From 1919595adcec7e8fc98b133dbf458ea647051d7d Mon Sep 17 00:00:00 2001 From: iddev5 Date: Fri, 8 Jul 2022 00:09:51 +0530 Subject: [PATCH] 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``. --- js-runtime/src/js-runtime.js | 1 - js-runtime/src/main.zig | 29 +++++------------------------ 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/js-runtime/src/js-runtime.js b/js-runtime/src/js-runtime.js index 8bca277a..4572a137 100644 --- a/js-runtime/src/js-runtime.js +++ b/js-runtime/src/js-runtime.js @@ -173,7 +173,6 @@ const zig = { switch (block.getU8(0)) { case 0: case 6: - case 7: return values[block.getU64(8)]; break; case 1: diff --git a/js-runtime/src/main.zig b/js-runtime/src/main.zig index 1d8f7045..07b35922 100644 --- a/js-runtime/src/main.zig +++ b/js-runtime/src/main.zig @@ -24,25 +24,14 @@ const js = struct { }; pub const Value = extern struct { - tag: ValueTag, + tag: Tag, val: extern union { ref: u64, num: f64, bool: bool, }, - const ValueTag = enum(u8) { - ref, - num, - bool, - str, - nulled, - undef, - func_js, - func_zig, - }; - - pub const Tag = enum { + pub const Tag = enum(u8) { object, num, bool, @@ -53,15 +42,7 @@ pub const Value = extern struct { }; pub fn is(val: *const Value, comptime tag: Tag) bool { - return switch (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, - }; + return val.tag == 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 { - return .{ .tag = .ref, .val = .{ .ref = obj.ref } }; + return .{ .tag = .object, .val = .{ .ref = obj.ref } }; } 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 { - 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 {