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 | let body = context.current_srm_body_emitter! | |
| 33 | body.op(System.Reflection.Metadata.ILOpCode.DUP) | |
| 34 | fi | |
| 35 | ||
| 36 | gen(function, context) | |
| 37 | let body = context.current_srm_body_emitter! | |
| 38 | body.new_object(context.resolve_delegate_constructor(type)) | |
| 39 | si | |
| 40 | ||
| 41 | to_string() -> string => | |
| 42 | "delegate:[{type}]({frame},{function})" | |
| 43 | si | |
| 44 | si |