Appearance
| 1 | namespace IR.Values.Load is | |
| 2 | use IO.Std; | |
| 3 | ||
| 4 | use System.NotImplementedException; | |
| 5 | use System.Text.StringBuilder; | |
| 6 | ||
| 7 | use TypeTyped = Semantic.Types.Typed; | |
| 8 | use Semantic.Types.Type; | |
| 9 | use SymbolBase = Semantic.Symbols.Symbol; | |
| 10 | ||
| 11 | class DELEGATE: Value, TypeTyped is | |
| 12 | function: Value; | |
| 13 | frame: Value; | |
| 14 | type: Type; | |
| 15 | ||
| 16 | init(type: Type, function: Value, frame: Value) is | |
| 17 | self.type = type; | |
| 18 | ||
| 19 | self.function = function; | |
| 20 | self.frame = frame; | |
| 21 | si | |
| 22 | ||
| 23 | referenced_function: Semantic.Symbols.Function? => function.referenced_function; | |
| 24 | ||
| 25 | gen(context: IR.CONTEXT) is | |
| 26 | gen(frame, context); | |
| 27 | ||
| 28 | // ldvirtftn consumes the receiver it dispatches against, | |
| 29 | // so the target pushed above for the delegate's own | |
| 30 | // constructor argument needs a duplicate first. | |
| 31 | if function.is_virtual_dispatch then | |
| 32 | context.write_line("dup"); | |
| 33 | fi | |
| 34 | ||
| 35 | gen(function, context); | |
| 36 | context.write_line("newobj instance void {type.get_il_type()}::'.ctor'(object, native int)"); | |
| 37 | si | |
| 38 | ||
| 39 | to_string() -> string => | |
| 40 | "delegate:[{type}]({frame,function}\")"; | |
| 41 | si | |
| 42 | si |