js-runtime: Use the same tag for both func_js and func_zig
There is no technical different between the ways they are used. So its better to merge them. This commit further removes the internal ValueTag which worked under Tag. On doing that tag type ``.ref`` has been renamed to ``.object``.
This commit is contained in:
parent
3b00b478ce
commit
1919595adc
2 changed files with 5 additions and 25 deletions
|
|
@ -173,7 +173,6 @@ const zig = {
|
||||||
switch (block.getU8(0)) {
|
switch (block.getU8(0)) {
|
||||||
case 0:
|
case 0:
|
||||||
case 6:
|
case 6:
|
||||||
case 7:
|
|
||||||
return values[block.getU64(8)];
|
return values[block.getU64(8)];
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
||||||
|
|
@ -24,25 +24,14 @@ const js = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Value = extern struct {
|
pub const Value = extern struct {
|
||||||
tag: ValueTag,
|
tag: Tag,
|
||||||
val: extern union {
|
val: extern union {
|
||||||
ref: u64,
|
ref: u64,
|
||||||
num: f64,
|
num: f64,
|
||||||
bool: bool,
|
bool: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
const ValueTag = enum(u8) {
|
pub const Tag = enum(u8) {
|
||||||
ref,
|
|
||||||
num,
|
|
||||||
bool,
|
|
||||||
str,
|
|
||||||
nulled,
|
|
||||||
undef,
|
|
||||||
func_js,
|
|
||||||
func_zig,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Tag = enum {
|
|
||||||
object,
|
object,
|
||||||
num,
|
num,
|
||||||
bool,
|
bool,
|
||||||
|
|
@ -53,15 +42,7 @@ pub const Value = extern struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn is(val: *const Value, comptime tag: Tag) bool {
|
pub fn is(val: *const Value, comptime tag: Tag) bool {
|
||||||
return switch (tag) {
|
return val.tag == tag;
|
||||||
.object => val.tag == .object,
|
|
||||||
.num => val.tag == .num,
|
|
||||||
.bool => val.tag == .bool,
|
|
||||||
.str => val.tag == .str,
|
|
||||||
.nulled => val.tag == .nulled,
|
|
||||||
.undef => val.tag == .undef,
|
|
||||||
.func => val.tag == .func_js or val.tag == .func_zig,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(val: *const Value, comptime tag: Tag) switch (tag) {
|
pub fn view(val: *const Value, comptime tag: Tag) switch (tag) {
|
||||||
|
|
@ -107,7 +88,7 @@ pub const Object = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toValue(obj: *const Object) Value {
|
pub fn toValue(obj: *const Object) Value {
|
||||||
return .{ .tag = .ref, .val = .{ .ref = obj.ref } };
|
return .{ .tag = .object, .val = .{ .ref = obj.ref } };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(obj: *const Object, prop: []const u8) Value {
|
pub fn get(obj: *const Object, prop: []const u8) Value {
|
||||||
|
|
@ -153,7 +134,7 @@ pub const Function = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toValue(func: *const Function) Value {
|
pub fn toValue(func: *const Function) Value {
|
||||||
return .{ .tag = .func_zig, .val = .{ .ref = func.ref } };
|
return .{ .tag = .func, .val = .{ .ref = func.ref } };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn construct(func: *const Function, args: []const Value) Value {
|
pub fn construct(func: *const Function, args: []const Value) Value {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue