Skip to content
← Back

src/ir/values/tuple_repack.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
4
// Converts a tuple to a tuple type whose elements each accept the
5
// source's. A value tuple is invariant in the CLR, so the source is
6
// spilled to a local and `built`, which constructs the target tuple
7
// from loads of that local's elements, is generated in its place.
8
class TUPLE_REPACK(source: Value, _temp_name: string, _source_type: Type, built: Value): Value is
9
type: Type? => built.type
10
is_lightweight_pure: bool => false
11
12
gen(context: IR.CONTEXT) is
13
let body = context.current_srm_body_emitter!
14
body.declare_local(_temp_name, _source_type)
15
16
gen(source, context)
17
18
body.stloc(_temp_name)
19
20
gen(built, context)
21
si
22
23
to_string() -> string =>
24
"tuple-repack:[{type}]({source})"
25
si
26
si