Skip to content
← Back

src/ir/values/decrement.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
4
// Decrements an int local in place, leaving nothing on the stack.
5
// Used by a fused `take` stage: each element that reaches the stage
6
// spends one of its count, and the loop checks the count before it
7
// pulls the next element, so the stage itself has nothing to decide.
8
class DECREMENT: Value is
9
_counter_il_name: string
10
11
type: Type
12
13
init(counter_il_name: string, type: Type) is
14
super.init()
15
16
_counter_il_name = counter_il_name
17
self.type = type
18
si
19
20
gen(context: IR.CONTEXT) is
21
let body = context.current_srm_body_emitter!
22
body.ldloc(_counter_il_name)
23
body.ldc_i4(1)
24
body.op(System.Reflection.Metadata.ILOpCode.SUB)
25
body.stloc(_counter_il_name)
26
si
27
28
to_string() -> string => "decrement:({_counter_il_name})"
29
si
30
si