Appearance
| 1 | namespace IR.Values.Load is | |
| 2 | use TypeTyped = Semantic.Types.Typed; | |
| 3 | use SymbolBase = Semantic.Symbols.Symbol; | |
| 4 | ||
| 5 | class INSTANCE_FIELD: SYMBOL, TypeTyped is | |
| 6 | is_consumable: bool => true; | |
| 7 | is_lightweight_pure: bool => from!.is_lightweight_pure; | |
| 8 | ||
| 9 | // A field is addressable in place when its containing instance | |
| 10 | // is: a reference receiver holds the object, so ldflda always | |
| 11 | // works; a struct receiver must itself be addressable or the | |
| 12 | // field lives in a temporary copy. | |
| 13 | has_address: bool => | |
| 14 | if from!.is_value_type then | |
| 15 | from!.has_address | |
| 16 | else | |
| 17 | true | |
| 18 | fi; | |
| 19 | ||
| 20 | init(from: Value, symbol: SymbolBase) is | |
| 21 | super.init(from, symbol); | |
| 22 | si | |
| 23 | ||
| 24 | gen(context: IR.CONTEXT) is | |
| 25 | gen(from, context); | |
| 26 | context.write_line("ldfld {symbol.get_il_reference()}"); | |
| 27 | si | |
| 28 | ||
| 29 | gen_address(context: IR.CONTEXT) is | |
| 30 | // `ldflda` takes the containing instance: the reference value | |
| 31 | // for a reference-type receiver, a managed pointer for a | |
| 32 | // value-type (struct) receiver. Taking the receiver's address | |
| 33 | // unconditionally would compute the field offset from the local | |
| 34 | // slot holding the reference, not from the object. | |
| 35 | if from!.is_value_type then | |
| 36 | from!.gen_address(context); | |
| 37 | else | |
| 38 | gen(from, context); | |
| 39 | fi | |
| 40 | context.write_line("ldflda {symbol.get_il_reference()}"); | |
| 41 | si | |
| 42 | ||
| 43 | to_string() -> string => | |
| 44 | "load:[{type}]({from},\"{symbol.name}\")"; | |
| 45 | si | |
| 46 | si |