Appearance
| 1 | namespace IR.Values is | |
| 2 | use TypeTyped = Semantic.Types.Typed | |
| 3 | use Semantic.Types.Type | |
| 4 | ||
| 5 | // A completed handle for a result-less task-like, produced by | |
| 6 | // driving the task-like's builder directly: create, set_result, | |
| 7 | // read `task`. Emitted where a machine-less body completes at | |
| 8 | // fall-through or from a bare `return;` - the state-machine | |
| 9 | // lowering never produces this value, since its own trailer | |
| 10 | // completes through the builder field. Task itself completes | |
| 11 | // through `Tasks.TASK.completed_task` at compile time, so this is | |
| 12 | // the other task-likes only. | |
| 13 | class COMPLETED_TASK_LIKE: Value, TypeTyped is | |
| 14 | type: Type | |
| 15 | ||
| 16 | builder_type: Type | |
| 17 | ||
| 18 | is_state_changing_call: bool => true | |
| 19 | ||
| 20 | init(type: Type, builder_type: Type) is | |
| 21 | super.init() | |
| 22 | ||
| 23 | self.type = type | |
| 24 | self.builder_type = builder_type | |
| 25 | si | |
| 26 | ||
| 27 | gen(context: IR.CONTEXT) is | |
| 28 | let body = context.current_srm_body_emitter! | |
| 29 | let local = ".completed_builder" | |
| 30 | ||
| 31 | body.declare_local(local, builder_type) | |
| 32 | ||
| 33 | body.call(context.resolve_builder_member(builder_type, "create", 0)) | |
| 34 | body.stloc(local) | |
| 35 | ||
| 36 | _load_builder(body, builder_type, local) | |
| 37 | body.call(context.resolve_builder_member(builder_type, "set_result", 0)) | |
| 38 | ||
| 39 | _load_builder(body, builder_type, local) | |
| 40 | body.call(context.resolve_builder_property(builder_type, "task")) | |
| 41 | si | |
| 42 | ||
| 43 | // A struct builder is reached through its address, a class | |
| 44 | // builder through the object the local holds - the same | |
| 45 | // distinction the state-machine launch makes for the builder | |
| 46 | // field. | |
| 47 | _load_builder( | |
| 48 | body: IR.Emitter.SRM_METHOD_BODY_EMITTER, | |
| 49 | builder_type: Type, | |
| 50 | local: string | |
| 51 | ) static is | |
| 52 | if builder_type.is_value_type then | |
| 53 | body.ldloca(local) | |
| 54 | else | |
| 55 | body.ldloc(local) | |
| 56 | fi | |
| 57 | si | |
| 58 | ||
| 59 | to_string() -> string => "completed-task-like:[{type}]()" | |
| 60 | si | |
| 61 | si |