Appearance
| 1 | namespace IR.Values is | |
| 2 | use TypeTyped = Semantic.Types.Typed | |
| 3 | use Semantic.Types.Type | |
| 4 | ||
| 5 | // Outer-method body of an async function. Newobjs the state | |
| 6 | // machine with the user's args (instance methods prefix | |
| 7 | // `ldarg.0` for $outer_self), creates+stashes the builder, | |
| 8 | // calls `builder.Start(ref this)`, and leaves the Task on the | |
| 9 | // stack. Caller emits `ret`. | |
| 10 | // | |
| 11 | // Stack effect: 0 → 1. | |
| 12 | class ASYNC_METHOD_LAUNCH: Value, TypeTyped is | |
| 13 | type: Type | |
| 14 | ||
| 15 | state_machine_type: Type | |
| 16 | constructor: Semantic.Symbols.Function | |
| 17 | ctor_arg_loads: Value | |
| 18 | state_field: Semantic.Symbols.Field | |
| 19 | builder_field: Semantic.Symbols.Field | |
| 20 | ||
| 21 | state_machine_local: IR.LOCAL | |
| 22 | ||
| 23 | init( | |
| 24 | type: Type, | |
| 25 | state_machine_type: Type, | |
| 26 | constructor: Semantic.Symbols.Function, | |
| 27 | ctor_arg_loads: Value, | |
| 28 | state_field: Semantic.Symbols.Field, | |
| 29 | builder_field: Semantic.Symbols.Field | |
| 30 | ) is | |
| 31 | super.init() | |
| 32 | ||
| 33 | self.type = type | |
| 34 | self.state_machine_type = state_machine_type | |
| 35 | self.constructor = constructor | |
| 36 | self.ctor_arg_loads = ctor_arg_loads | |
| 37 | self.state_field = state_field | |
| 38 | self.builder_field = builder_field | |
| 39 | self.state_machine_local = IR.LOCAL(".sm", state_machine_type) | |
| 40 | si | |
| 41 | ||
| 42 | accept(visitor: Visitor) is | |
| 43 | visitor.visit(self) | |
| 44 | si | |
| 45 | ||
| 46 | to_string() -> string => | |
| 47 | "async-method-launch:[{type}]({state_machine_type})" | |
| 48 | si | |
| 49 | si |