Appearance
| 1 | namespace Syntax.Process is | |
| 2 | use Collections | |
| 3 | ||
| 4 | // Per-build compile-expressions state for the node kinds that | |
| 5 | // carry more than the common EXPRESSION_STATE / STATEMENT_STATE. | |
| 6 | // Each struct is hosted as a field on its node class, which keeps | |
| 7 | // forwarders for the members and no knowledge of the storage, so | |
| 8 | // that what a walk writes is reset by Node.clear() and | |
| 9 | // Node.clear_outputs() through the struct rather than field by | |
| 10 | // field. | |
| 11 | ||
| 12 | // Whether a `ref` argument is a write, decided from the resolved | |
| 13 | // callee. | |
| 14 | struct REFERENCE_STATE is | |
| 15 | writes_target: bool public | |
| 16 | ||
| 17 | init() is | |
| 18 | si | |
| 19 | ||
| 20 | clear() is | |
| 21 | writes_target = false | |
| 22 | si | |
| 23 | si | |
| 24 | ||
| 25 | // The operators a synthesized memberwise comparison calls, one per | |
| 26 | // member, recorded as each resolves. | |
| 27 | struct MEMBERWISE_STATE is | |
| 28 | called_functions: LIST[Semantic.Symbols.Function]? public | |
| 29 | ||
| 30 | init() is | |
| 31 | si | |
| 32 | ||
| 33 | functions() -> LIST[Semantic.Symbols.Function] is | |
| 34 | let list = called_functions ?? LIST[Semantic.Symbols.Function]() | |
| 35 | called_functions = list | |
| 36 | ||
| 37 | return list | |
| 38 | si | |
| 39 | ||
| 40 | clear() is | |
| 41 | called_functions = null | |
| 42 | si | |
| 43 | si | |
| 44 | ||
| 45 | // What an `if` in value position yields when no branch runs. | |
| 46 | struct IF_STATE is | |
| 47 | yields_absence_on_fall_through: bool public | |
| 48 | ||
| 49 | init() is | |
| 50 | si | |
| 51 | ||
| 52 | clear() is | |
| 53 | yields_absence_on_fall_through = false | |
| 54 | si | |
| 55 | si | |
| 56 | ||
| 57 | // The iterator surface a `for` or `yield in` drives, resolved once | |
| 58 | // by compile-expressions and read by generate-il. The frame field a | |
| 59 | // state machine keeps the iterator in is allocated once and retyped | |
| 60 | // by later walks, so clear_outputs() keeps it. | |
| 61 | struct ITERATOR_STATE is | |
| 62 | read_iterator: Semantic.Symbols.Function? public | |
| 63 | read_current: Semantic.Symbols.Function? public | |
| 64 | move_next: Semantic.Symbols.Function? public | |
| 65 | iterator_field: Semantic.Symbols.Field? public | |
| 66 | fusion: PIPE_FUSION? public | |
| 67 | ||
| 68 | init() is | |
| 69 | si | |
| 70 | ||
| 71 | clear() is | |
| 72 | read_iterator = null | |
| 73 | read_current = null | |
| 74 | move_next = null | |
| 75 | iterator_field = null | |
| 76 | fusion = null | |
| 77 | si | |
| 78 | ||
| 79 | clear_outputs() is | |
| 80 | read_iterator = null | |
| 81 | read_current = null | |
| 82 | move_next = null | |
| 83 | fusion = null | |
| 84 | si | |
| 85 | si | |
| 86 | ||
| 87 | // The awaiter pattern an `await` resolved on its operand's type, and | |
| 88 | // the frame fields a state machine carries its awaiter and result | |
| 89 | // in. The fields are allocated once and retyped by later walks, so | |
| 90 | // clear_outputs() keeps them. | |
| 91 | struct AWAIT_STATE is | |
| 92 | awaitable: Semantic.AWAITABLE? public | |
| 93 | result_field: Semantic.Symbols.Field? public | |
| 94 | awaiter_field: Semantic.Symbols.Field? public | |
| 95 | ||
| 96 | init() is | |
| 97 | si | |
| 98 | ||
| 99 | clear() is | |
| 100 | awaitable = null | |
| 101 | result_field = null | |
| 102 | awaiter_field = null | |
| 103 | si | |
| 104 | ||
| 105 | clear_outputs() is | |
| 106 | awaitable = null | |
| 107 | si | |
| 108 | si | |
| 109 | ||
| 110 | // The frame field a spilled operand is held in across a suspend, | |
| 111 | // allocated once and retyped by later walks. | |
| 112 | struct SPILL_STATE is | |
| 113 | spill_field: Semantic.Symbols.Field? public | |
| 114 | ||
| 115 | init() is | |
| 116 | si | |
| 117 | ||
| 118 | clear() is | |
| 119 | spill_field = null | |
| 120 | si | |
| 121 | ||
| 122 | clear_outputs() is | |
| 123 | si | |
| 124 | si | |
| 125 | ||
| 126 | // What the wrapping context asked of a statement in expression | |
| 127 | // position, and the temp the walk routed its value through. | |
| 128 | struct STATEMENT_EXPRESSION_STATE is | |
| 129 | temp: IR.TEMP? public | |
| 130 | want_value: bool public | |
| 131 | void_tolerated: bool public | |
| 132 | ||
| 133 | init() is | |
| 134 | si | |
| 135 | ||
| 136 | clear() is | |
| 137 | temp = null | |
| 138 | want_value = true | |
| 139 | void_tolerated = false | |
| 140 | si | |
| 141 | ||
| 142 | clear_outputs() is | |
| 143 | temp = null | |
| 144 | si | |
| 145 | si | |
| 146 | ||
| 147 | // A parenthesised block's inputs from its context and the outputs | |
| 148 | // its walk collects from the returns that target it. | |
| 149 | struct VAL_BLOCK_STATE is | |
| 150 | want_value: bool public | |
| 151 | void_tolerated: bool public | |
| 152 | expected_type: Semantic.Types.Type? public | |
| 153 | expected_type_error_message: string? public | |
| 154 | return_types: LIST[Semantic.Types.Type]? public | |
| 155 | has_targeted_return: bool public | |
| 156 | end_label: IR.LABEL? public | |
| 157 | ||
| 158 | init() is | |
| 159 | si | |
| 160 | ||
| 161 | returns() -> LIST[Semantic.Types.Type] is | |
| 162 | let list = return_types ?? LIST[Semantic.Types.Type]() | |
| 163 | return_types = list | |
| 164 | ||
| 165 | return list | |
| 166 | si | |
| 167 | ||
| 168 | clear() is | |
| 169 | want_value = true | |
| 170 | void_tolerated = false | |
| 171 | expected_type = null | |
| 172 | expected_type_error_message = null | |
| 173 | clear_outputs() | |
| 174 | si | |
| 175 | ||
| 176 | clear_outputs() is | |
| 177 | return_types = null | |
| 178 | has_targeted_return = false | |
| 179 | end_label = null | |
| 180 | si | |
| 181 | si | |
| 182 | ||
| 183 | // The block a `return` exits, when it exits a block rather than | |
| 184 | // the function. | |
| 185 | struct RETURN_STATE is | |
| 186 | val_block_target: Syntax.Trees.Expressions.VAL_BLOCK? public | |
| 187 | ||
| 188 | init() is | |
| 189 | si | |
| 190 | ||
| 191 | clear() is | |
| 192 | val_block_target = null | |
| 193 | si | |
| 194 | si | |
| 195 | ||
| 196 | // The loop a `break` or `continue` resolved to. | |
| 197 | struct JUMP_STATE is | |
| 198 | resolved_target: Syntax.Trees.Statements.Statement? public | |
| 199 | ||
| 200 | init() is | |
| 201 | si | |
| 202 | ||
| 203 | clear() is | |
| 204 | resolved_target = null | |
| 205 | si | |
| 206 | si | |
| 207 | si | |
| 208 | ||
| 209 | namespace Syntax.Process is | |
| 210 | use Collections | |
| 211 | ||
| 212 | // Whether a statement list is the tail of a function body, pushed by | |
| 213 | // the literal or definition that owns it. | |
| 214 | struct LIST_STATE is | |
| 215 | function_tail: bool public | |
| 216 | ||
| 217 | init() is | |
| 218 | si | |
| 219 | ||
| 220 | clear() is | |
| 221 | function_tail = false | |
| 222 | si | |
| 223 | si | |
| 224 | si |