aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2021-06-06 21:08:31 +0300
committerVeikka Tuominen <git@vexu.eu>2021-06-07 22:15:56 +0300
commit7efd7bc3b8cc403814c0aa62be0a17ff25b33902 (patch)
tree7b92414b05bfc0e66bdc8aff4f3a68abc9a88ee7 /src/value.zig
parentca6951ff7959b88573bfec7c7bf0465209f3263f (diff)
downloadzig-7efd7bc3b8cc403814c0aa62be0a17ff25b33902.tar.gz
zig-7efd7bc3b8cc403814c0aa62be0a17ff25b33902.zip
stage2: implement comptime variables
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig26
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;