Appearance
| 1 | namespace IR.Values is | |
| 2 | use Ghul.Pipes | |
| 3 | ||
| 4 | use Semantic.Types.Type | |
| 5 | ||
| 6 | class NEW: Value is | |
| 7 | is_state_changing_call: bool => !constructor.constructs_store_free | |
| 8 | type: Type | |
| 9 | constructor: Semantic.Symbols.Function | |
| 10 | arguments: Collections.List[Value] | |
| 11 | ||
| 12 | init( | |
| 13 | type: Type, | |
| 14 | constructor: Semantic.Symbols.Function, | |
| 15 | arguments: Collections.List[Value] | |
| 16 | ) is | |
| 17 | super.init() | |
| 18 | ||
| 19 | self.type = type | |
| 20 | self.constructor = constructor | |
| 21 | self.arguments = arguments | |
| 22 | si | |
| 23 | ||
| 24 | gen(context: IR.CONTEXT) is | |
| 25 | let owner = constructor.owner! | |
| 26 | ||
| 27 | if owner.is_unit_variant then | |
| 28 | let body = context.current_srm_body_emitter! | |
| 29 | ||
| 30 | // Which instance to load follows from the value's own | |
| 31 | // type rather than from wherever the constructor was | |
| 32 | // found: for a generic variant the type names the | |
| 33 | // instantiation, while the constructor's owner is the | |
| 34 | // open definition, whose parameters an imported | |
| 35 | // variant does not even declare. | |
| 36 | let variant = type.symbol | |
| 37 | ||
| 38 | body.ldsfld(context.resolve_unit_variant_instance(variant)) | |
| 39 | ||
| 40 | return | |
| 41 | fi | |
| 42 | ||
| 43 | for a in arguments do | |
| 44 | gen(a, context) | |
| 45 | od | |
| 46 | ||
| 47 | let body = context.current_srm_body_emitter! | |
| 48 | body.new_object(context.resolve_call_target(constructor)) | |
| 49 | si | |
| 50 | ||
| 51 | to_string() -> string => | |
| 52 | "new:[{type}](\"{constructor.name}\",{arguments |> join(",")})" | |
| 53 | si | |
| 54 | si |