sysjs: use null and undefined in enums

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
This commit is contained in:
Eric Joldasov 2022-12-13 18:42:58 +06:00 committed by Stephen Gutekanst
parent 3397497cc9
commit 37b7d32485

View file

@ -39,8 +39,8 @@ pub const Value = extern struct {
num, num,
bool, bool,
str, str,
nulled, null,
undef, undefined,
func, func,
}; };
@ -54,7 +54,7 @@ pub const Value = extern struct {
.bool => bool, .bool => bool,
.str => String, .str => String,
.func => Function, .func => Function,
.nulled, .undef => @compileError("Cannot get null or undefined as a value"), .null, .undefined => @compileError("Cannot get null or undefined as a value"),
} { } {
return switch (tag) { return switch (tag) {
.object => Object{ .ref = val.val.ref }, .object => Object{ .ref = val.val.ref },
@ -92,8 +92,8 @@ pub const Value = extern struct {
.bool => try writer.writeAll(if (val.view(.bool)) "true" else "false"), .bool => try writer.writeAll(if (val.view(.bool)) "true" else "false"),
.str => try writer.print("String@{}({})", .{ val.val.ref, val.view(.str).getLength() }), .str => try writer.print("String@{}({})", .{ val.val.ref, val.view(.str).getLength() }),
.func => try writer.print("Function@{}({})", .{ val.val.ref, val.view(.func).paramCount() }), .func => try writer.print("Function@{}({})", .{ val.val.ref, val.view(.func).paramCount() }),
.nulled => try writer.writeAll("null"), .null => try writer.writeAll("null"),
.undef => try writer.writeAll("undefined"), .undefined => try writer.writeAll("undefined"),
} }
} }
}; };
@ -237,11 +237,11 @@ pub fn createBool(val: bool) Value {
} }
pub fn createNull() Value { pub fn createNull() Value {
return .{ .tag = .nulled, .val = undefined }; return .{ .tag = .null, .val = undefined };
} }
pub fn createUndefined() Value { pub fn createUndefined() Value {
return .{ .tag = .undef, .val = undefined }; return .{ .tag = .undefined, .val = undefined };
} }
const FunType = *const fn (args: Object, args_len: u32, captures: []Value) Value; const FunType = *const fn (args: Object, args_len: u32, captures: []Value) Value;