Appearance
| 1 | namespace IR.Values.Call is | |
| 2 | use TypeTyped = Semantic.Types.Typed; | |
| 3 | use Semantic.Types.Type; | |
| 4 | ||
| 5 | class CLOSURE: Value, TypeTyped is | |
| 6 | // Invoking a function value can run anything — except through | |
| 7 | // a pure function type, whose slots only admit store-free | |
| 8 | // values. | |
| 9 | is_state_changing_call: bool => !(func_type? /\ func_type.is_pure_function); | |
| 10 | from: Value; | |
| 11 | type: Type; | |
| 12 | ||
| 13 | is_action: bool; | |
| 14 | func_type: Type?; | |
| 15 | arguments: Collections.List[Value]; | |
| 16 | ||
| 17 | init( | |
| 18 | from: Value, | |
| 19 | type: Type, | |
| 20 | is_action: bool, | |
| 21 | func_type: Type, | |
| 22 | arguments: Collections.List[Value] | |
| 23 | ) is | |
| 24 | super.init(); | |
| 25 | ||
| 26 | self.from = from; | |
| 27 | self.type = type; | |
| 28 | self.is_action = is_action; | |
| 29 | self.func_type = func_type; | |
| 30 | self.arguments = arguments; | |
| 31 | si | |
| 32 | ||
| 33 | gen(context: IR.CONTEXT) is | |
| 34 | gen(from, context); | |
| 35 | ||
| 36 | let count mut = 0; | |
| 37 | for a in arguments do | |
| 38 | gen(a, context); | |
| 39 | ||
| 40 | count = count + 1; | |
| 41 | od | |
| 42 | ||
| 43 | let call = System.Text.StringBuilder(); | |
| 44 | ||
| 45 | call | |
| 46 | .append("callvirt instance "); | |
| 47 | ||
| 48 | if is_action then | |
| 49 | call | |
| 50 | .append("void"); | |
| 51 | else | |
| 52 | call | |
| 53 | .append("!") | |
| 54 | .append(count); | |
| 55 | fi | |
| 56 | ||
| 57 | call | |
| 58 | .append(" "); | |
| 59 | ||
| 60 | func_type!.gen_type(call); | |
| 61 | ||
| 62 | call | |
| 63 | .append("::Invoke("); | |
| 64 | ||
| 65 | for i in 0..count do | |
| 66 | if i > 0 then | |
| 67 | call.append(","); | |
| 68 | fi | |
| 69 | ||
| 70 | call | |
| 71 | .append("!") | |
| 72 | .append(i); | |
| 73 | od | |
| 74 | ||
| 75 | call.append(")"); | |
| 76 | ||
| 77 | context.write_line(call.to_string()); | |
| 78 | si | |
| 79 | ||
| 80 | to_string() -> string => | |
| 81 | "closure-call:[{type}]({from}{arguments})"; | |
| 82 | si | |
| 83 | si |