diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-06-08 14:16:57 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-08 14:16:57 -0400 |
| commit | ccfa16828445ebf3634c2a0f27ec359af1628efc (patch) | |
| tree | 0d73a532885fca9b9e6db9fdceb8f1e014cf495f /src/value.zig | |
| parent | c822a0b59fe123ff67bcb188f20290d818467be7 (diff) | |
| parent | d41a5105cd6222564dfe6bad9cff2c445847c6b3 (diff) | |
| download | zig-ccfa16828445ebf3634c2a0f27ec359af1628efc.tar.gz zig-ccfa16828445ebf3634c2a0f27ec359af1628efc.zip | |
Merge pull request #9030 from Vexu/stage2
Stage2: implement comptime variables
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/value.zig b/src/value.zig index 9c29bdf80c..c358975667 100644 --- a/src/value.zig +++ b/src/value.zig @@ -101,6 +101,8 @@ pub const Value = extern union { variable, /// Represents a pointer to another immutable value. ref_val, + /// Represents a comptime variables storage. + comptime_alloc, /// Represents a pointer to a decl, not the value of the decl. decl_ref, elem_ptr, @@ -223,6 +225,7 @@ pub const Value = extern union { .int_i64 => Payload.I64, .function => Payload.Function, .variable => Payload.Variable, + .comptime_alloc => Payload.ComptimeAlloc, .elem_ptr => Payload.ElemPtr, .field_ptr => Payload.FieldPtr, .float_16 => Payload.Float_16, @@ -403,6 +406,7 @@ pub const Value = extern union { }; return Value{ .ptr_otherwise = &new_payload.base }; }, + .comptime_alloc => return self.copyPayloadShallow(allocator, Payload.ComptimeAlloc), .decl_ref => return self.copyPayloadShallow(allocator, Payload.Decl), .elem_ptr => { const payload = self.castTag(.elem_ptr).?; @@ -577,6 +581,11 @@ pub const Value = extern union { try out_stream.writeAll("&const "); val = ref_val; }, + .comptime_alloc => { + const ref_val = val.castTag(.comptime_alloc).?.data.val; + try out_stream.writeAll("&"); + val = ref_val; + }, .decl_ref => return out_stream.writeAll("(decl ref)"), .elem_ptr => { const elem_ptr = val.castTag(.elem_ptr).?.data; @@ -713,6 +722,7 @@ pub const Value = extern union { .extern_fn, .variable, .ref_val, + .comptime_alloc, .decl_ref, .elem_ptr, .field_ptr, @@ -1186,6 +1196,10 @@ pub const Value = extern union { const payload = self.castTag(.ref_val).?; std.hash.autoHash(&hasher, payload.data.hash()); }, + .comptime_alloc => { + const payload = self.castTag(.comptime_alloc).?; + std.hash.autoHash(&hasher, payload.data.val.hash()); + }, .int_big_positive, .int_big_negative => { var space: BigIntSpace = undefined; const big = self.toBigInt(&space); @@ -1277,6 +1291,7 @@ pub const Value = extern union { /// Returns error.AnalysisFail if the pointer points to a Decl that failed semantic analysis. pub fn pointerDeref(self: Value, allocator: *Allocator) error{ AnalysisFail, OutOfMemory }!Value { return switch (self.tag()) { + .comptime_alloc => self.castTag(.comptime_alloc).?.data.val, .ref_val => self.castTag(.ref_val).?.data, .decl_ref => self.castTag(.decl_ref).?.data.value(), .elem_ptr => { @@ -1462,6 +1477,7 @@ pub const Value = extern union { .int_big_positive, .int_big_negative, .ref_val, + .comptime_alloc, .decl_ref, .elem_ptr, .field_ptr, @@ -1542,6 +1558,16 @@ pub const Value = extern union { data: Value, }; + pub const ComptimeAlloc = struct { + pub const base_tag = Tag.comptime_alloc; + + base: Payload = Payload{ .tag = base_tag }, + data: struct { + val: Value, + runtime_index: u32, + }, + }; + pub const ElemPtr = struct { pub const base_tag = Tag.elem_ptr; |
