Appearance
| 1 | namespace IR.Values is | |
| 2 | use Semantic.Types.Type; | |
| 3 | ||
| 4 | // Reads an int local, decrements it, and leaves the decremented value | |
| 5 | // on the stack. Used by fused `take`/`skip` stages: each pulled element | |
| 6 | // decrements the running counter, and the new value is compared against | |
| 7 | // zero to decide whether the loop stops (`take`) or the element is | |
| 8 | // dropped (`skip`) - mirroring FilterPipeBase.have_moved followed by | |
| 9 | // should_continue / should_include. | |
| 10 | class PRE_DECREMENT: Value is | |
| 11 | _counter_il_name: string; | |
| 12 | ||
| 13 | type: Type; | |
| 14 | ||
| 15 | init(counter_il_name: string, type: Type) is | |
| 16 | super.init(); | |
| 17 | ||
| 18 | _counter_il_name = counter_il_name; | |
| 19 | self.type = type; | |
| 20 | si | |
| 21 | ||
| 22 | gen(context: IR.CONTEXT) is | |
| 23 | context.write_line("ldloc {_counter_il_name}"); | |
| 24 | context.write_line("ldc.i4.1"); | |
| 25 | context.write_line("sub"); | |
| 26 | context.write_line("dup"); | |
| 27 | context.write_line("stloc {_counter_il_name}"); | |
| 28 | si | |
| 29 | ||
| 30 | to_string() -> string => "pre_decrement:({_counter_il_name})"; | |
| 31 | si | |
| 32 | si |