Skip to content
← Back

src/ir/values/post_increment.ghul

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
let body = context.current_srm_body_emitter!
23
body.ldloc(_counter_il_name)
24
body.ldloc(_counter_il_name)
25
body.ldc_i4(1)
26
body.op(System.Reflection.Metadata.ILOpCode.ADD)
27
body.stloc(_counter_il_name)
28
si
29
30
to_string() -> string => "post_increment:({_counter_il_name})"
31
si
32
si