Appearance
| 1 | namespace IR.Values is | |
| 2 | use Semantic.Types.Type; | |
| 3 | ||
| 4 | class ADDRESS: Value is | |
| 5 | _next_id: int static; | |
| 6 | ||
| 7 | is_lightweight_pure: bool => value.is_lightweight_pure; | |
| 8 | has_address: bool => value.has_address; | |
| 9 | type: Type; | |
| 10 | value: Value; | |
| 11 | ||
| 12 | name: string?; | |
| 13 | ||
| 14 | next_name: string static is | |
| 15 | let result = "'.address.{_next_id}'"; | |
| 16 | ||
| 17 | _next_id = _next_id + 1; | |
| 18 | ||
| 19 | return result; | |
| 20 | si | |
| 21 | ||
| 22 | init( | |
| 23 | value: Value, | |
| 24 | type: Type | |
| 25 | ) is | |
| 26 | super.init(); | |
| 27 | ||
| 28 | self.value = value; | |
| 29 | self.type = type; | |
| 30 | si | |
| 31 | ||
| 32 | init( | |
| 33 | value: Value | |
| 34 | ) is | |
| 35 | init(value, value.type!); | |
| 36 | si | |
| 37 | ||
| 38 | reset_id() static is | |
| 39 | _next_id = 0; | |
| 40 | si | |
| 41 | ||
| 42 | gen_address(context: IR.CONTEXT) is | |
| 43 | gen(context); | |
| 44 | si | |
| 45 | ||
| 46 | gen(context: IR.CONTEXT) is | |
| 47 | if value.has_address then | |
| 48 | value.gen_address(context); | |
| 49 | else | |
| 50 | if !name? then | |
| 51 | name = next_name; | |
| 52 | fi | |
| 53 | ||
| 54 | let buffer = System.Text.StringBuilder(); | |
| 55 | ||
| 56 | buffer | |
| 57 | .append(".locals init ("); | |
| 58 | ||
| 59 | type.gen_type(buffer); | |
| 60 | ||
| 61 | buffer | |
| 62 | .append(' ') | |
| 63 | .append(name) | |
| 64 | .append(')'); | |
| 65 | ||
| 66 | context.write_line(buffer); | |
| 67 | ||
| 68 | value.gen(context); | |
| 69 | context.write_line("stloc {name}"); | |
| 70 | context.write_line("ldloca {name}"); | |
| 71 | fi | |
| 72 | si | |
| 73 | ||
| 74 | to_string() -> string => | |
| 75 | "address:[{type}]({value})"; | |
| 76 | si | |
| 77 | si |