Appearance
| 1 | namespace IR.Values is | |
| 2 | use Semantic.Types.Type; | |
| 3 | ||
| 4 | // Reads an int local and post-increments it: leaves the pre-increment | |
| 5 | // value on the stack and writes back value + 1. Used by fused `index()` | |
| 6 | // stages to produce each element's index while advancing the running | |
| 7 | // counter - the pre-increment value feeds straight into the | |
| 8 | // INDEXED_VALUE constructor. | |
| 9 | class POST_INCREMENT: Value is | |
| 10 | _counter_il_name: string; | |
| 11 | ||
| 12 | type: Type; | |
| 13 | ||
| 14 | init(counter_il_name: string, type: Type) is | |
| 15 | super.init(); | |
| 16 | ||
| 17 | _counter_il_name = counter_il_name; | |
| 18 | self.type = type; | |
| 19 | si | |
| 20 | ||
| 21 | gen(context: IR.CONTEXT) is | |
| 22 | context.write_line("ldloc {_counter_il_name}"); | |
| 23 | context.write_line("ldloc {_counter_il_name}"); | |
| 24 | context.write_line("ldc.i4.1"); | |
| 25 | context.write_line("add"); | |
| 26 | context.write_line("stloc {_counter_il_name}"); | |
| 27 | si | |
| 28 | ||
| 29 | to_string() -> string => "post_increment:({_counter_il_name})"; | |
| 30 | si | |
| 31 | si |