| | 63 | === How SBI works === |
| | 64 | |
| | 65 | SBI first takes all the code in the ''library'' and all the source files provided on the command-line and pre-processes them in several stages: |
| | 66 | |
| | 67 | || Parsing || Lex and parse source files to produce a syntax tree || |
| | 68 | || Ancestry resolution || Determine ancestry of classes and interfaces || |
| | 69 | || Typing || Annotate syntax tree with static types and make all type conversions explicit || |
| | 70 | |
| | 71 | The result is a syntax tree with symbol references resolved, annotated with static types and augmented |
| | 72 | so that type all conversions are explicit. This syntax tree is considered the ''program'', it is |
| | 73 | treated as read-only for the purpose of execution. |
| | 74 | |
| | 75 | SBI has a concept of a ''runner object'' (`run_t`) which is sort of similar to a process. It has a reference to the code |
| | 76 | that should be executed, to global/shared state (i.e. the heap) and to the thread(s). (There is only one thread |
| | 77 | currently, anyway.) A thread has its own private state consisting of a stack (of procedure |
| | 78 | activation records) and error/exception state. |
| | 79 | |
| | 80 | Data is managed using a system of interlinked structures -- `rdata` nodes. `rdata_var` nodes are used to implement |
| | 81 | both ''variables'' (addressable memory nodes that can be read and written) and ''values''. Values are immutable. |
| | 82 | so they can be copied just by copying the pointer to them. Values can be written to or read from variables. |
| | 83 | |
| | 84 | The equivalent of a data pointer in the `rdata` system is an ''address''. An address can refer both to a variable |
| | 85 | or a to property. Reading from or writing to a property (using its address) causes its getter or setter to be invoked. |
| | 86 | The equivalent of a code pointer is a delegate (this is not the same delegate as the language construct), which |
| | 87 | refers to a symbol and, optionally, to an object instance on which the symbol should be invoked. |
| | 88 | |
| | 89 | To implement L-values and R-values, an ''item'' is the result of evaluating an expression. An item can be either |
| | 90 | an ''address item'' (L-value) or a ''value item'' (R-value). |
| | 91 | |