From 919d32e714290a98073bb8253b26203bda1927ef Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 13 Aug 2023 02:03:43 +0100 Subject: [PATCH 1/4] Add vector primitive object to Kym --- debug/app.ona | 2 ++ source/coral/coral.zig | 2 ++ source/coral/io.zig | 26 +++++++++++++++++++------- source/coral/lina.zig | 12 ++++++++++++ source/ona/kym.zig | 17 ++++++++++++++++- 5 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 source/coral/lina.zig diff --git a/debug/app.ona b/debug/app.ona index 8a50cd9..4950301 100644 --- a/debug/app.ona +++ b/debug/app.ona @@ -1,6 +1,8 @@ # Test comment. +pos = [10, 20, 0.3] + options = { .title = "Afterglow", .width = 1280, diff --git a/source/coral/coral.zig b/source/coral/coral.zig index e1c021b..1cd5221 100644 --- a/source/coral/coral.zig +++ b/source/coral/coral.zig @@ -5,6 +5,8 @@ pub const debug = @import("./debug.zig"); pub const io = @import("./io.zig"); +pub const lina = @import("./lina.zig"); + pub const list = @import("./list.zig"); pub const map = @import("./map.zig"); diff --git a/source/coral/io.zig b/source/coral/io.zig index 39025ee..1e6a897 100644 --- a/source/coral/io.zig +++ b/source/coral/io.zig @@ -350,15 +350,23 @@ pub fn find_first(haystack: []const Byte, needle: Byte) ?usize { return null; } -var null_context = @as(usize, 0); +pub fn jenkins_hash(comptime int: std.builtin.Type.Int, bytes: []const Byte) math.Int(int) { + var hash = @as(math.Int(int), 0); -pub const null_writer = Writer.bind(usize, &null_context, struct { - fn write(context: *usize, buffer: []const u8) ?usize { - debug.assert(context.* == 0); + for (bytes) |byte| { + hash +%= byte; + hash +%= (hash << 10); + hash ^= (hash >> 6); + } - return buffer.len; - } -}.write); + hash +%= (hash << 3); + hash ^= (hash >> 11); + hash +%= (hash << 15); + + return hash; +} + +pub const null_writer = Writer.from(write_null); pub fn slice_sentineled(comptime sen: anytype, ptr: [*:sen]const @TypeOf(sen)) [:sen]const @TypeOf(sen) { var len = @as(usize, 0); @@ -374,6 +382,10 @@ pub fn tag_of(comptime value: anytype) Tag(@TypeOf(value)) { return @as(Tag(@TypeOf(value)), value); } +pub fn write_null(buffer: []const u8) ?usize { + return buffer.len; +} + pub fn zero(target: []Byte) void { for (target) |*t| t.* = 0; } diff --git a/source/coral/lina.zig b/source/coral/lina.zig new file mode 100644 index 0000000..4ca347e --- /dev/null +++ b/source/coral/lina.zig @@ -0,0 +1,12 @@ + +pub const Vector3 = struct { + x: f32, + y: f32, + z: f32, + + pub fn equals(self: Vector3, other: Vector3) bool { + return self.x == other.x and self.y == other.y and self.z == other.z; + } + + pub const zero = Vector3{.x = 0, .y = 0, .z = 0}; +}; diff --git a/source/ona/kym.zig b/source/ona/kym.zig index 920ca6f..46e45f8 100644 --- a/source/ona/kym.zig +++ b/source/ona/kym.zig @@ -991,7 +991,7 @@ pub const RuntimeEnv = struct { if (object.ref_count == 0) { switch (object.payload) { - .false, .true, .float, .fixed, .symbol, .syscall => {}, + .false, .true, .float, .fixed, .symbol, .vector, .syscall => {}, .string => |string| { coral.debug.assert(string.len >= 0); @@ -1190,6 +1190,13 @@ pub const RuntimeEnv = struct { }); } + pub fn new_vector(self: *RuntimeEnv, x: f32, y: f32, z: f32) RuntimeError!*RuntimeRef { + return RuntimeRef.allocate(self.allocator, .{ + .ref_count = 1, + .payload = .{.vector = .{x, y, z}}, + }); + } + pub fn print(self: *RuntimeEnv, buffer: []const coral.io.Byte) void { if (self.options.print) |bound_print| { bound_print(buffer); @@ -1287,6 +1294,7 @@ pub const RuntimeRef = opaque { float: Float, fixed: Fixed, symbol: [*:0]const coral.io.Byte, + vector: coral.lina.Vector3, syscall: *const Syscall, string: struct { @@ -1357,6 +1365,11 @@ pub const RuntimeRef = opaque { else => false, }, + .vector => |self_vector| switch (other.object().payload) { + .vector => |other_vector| self_vector.equals(other_vector), + else => false, + }, + .syscall => |self_syscall| switch (other.object().payload) { .syscall => |other_syscall| self_syscall == other_syscall, else => false, @@ -1384,6 +1397,7 @@ pub const RuntimeRef = opaque { .float => |float| @bitCast(float), .fixed => |fixed| @intCast(@as(u32, @bitCast(fixed))), .symbol => |symbol| @intFromPtr(symbol), + .vector => |vector| coral.io.jenkins_hash(@typeInfo(usize).Int, coral.io.bytes_of(&vector)), .syscall => |syscall| @intFromPtr(syscall), .string => |string| coral.io.djb2_hash(@typeInfo(usize).Int, string.unpack()), .dynamic => |dynamic| @intFromPtr(dynamic.typeinfo()) ^ @intFromPtr(dynamic.userdata().ptr), @@ -1404,6 +1418,7 @@ pub const RuntimeRef = opaque { .float => |float| float != 0, .fixed => |fixed| fixed != 0, .symbol => true, + .vector => |vector| !vector.equals(coral.lina.Vector3.zero), .syscall => true, .string => |string| string.len != 0, .dynamic => true, From 0fbdc001d4d44da27519bc01a7906e415b20b5b1 Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 13 Aug 2023 13:54:31 +0100 Subject: [PATCH 2/4] Add parser support for vector literals --- source/coral/coral.zig | 2 - source/coral/io.zig | 38 +++++++++++------- source/coral/lina.zig | 12 ------ source/coral/map.zig | 2 +- source/coral/utf8.zig | 2 +- source/ona/kym.zig | 91 +++++++++++++++++++++++++++++++++++++----- source/ona/kym/Ast.zig | 62 ++++++++++++++++++++++++++++ 7 files changed, 169 insertions(+), 40 deletions(-) delete mode 100644 source/coral/lina.zig diff --git a/source/coral/coral.zig b/source/coral/coral.zig index 1cd5221..e1c021b 100644 --- a/source/coral/coral.zig +++ b/source/coral/coral.zig @@ -5,8 +5,6 @@ pub const debug = @import("./debug.zig"); pub const io = @import("./io.zig"); -pub const lina = @import("./lina.zig"); - pub const list = @import("./list.zig"); pub const map = @import("./map.zig"); diff --git a/source/coral/io.zig b/source/coral/io.zig index 1e6a897..ed90db8 100644 --- a/source/coral/io.zig +++ b/source/coral/io.zig @@ -207,6 +207,16 @@ pub fn Tag(comptime Element: type) type { pub const Writer = Generator(?usize, []const Byte); +pub fn all_equals(target: []const Byte, match: Byte) bool { + for (0 .. target.len) |index| { + if (target[index] != match) { + return false; + } + } + + return true; +} + pub fn allocate_copy(allocator: Allocator, source: []const Byte) AllocationError![]Byte { const allocation = try allocator.actions.reallocate(allocator.context, @returnAddress(), null, source.len); @@ -265,6 +275,20 @@ pub fn allocate_string(allocator: Allocator, source: []const Byte) AllocationErr return @ptrCast(allocation); } +pub fn are_equal(target: []const Byte, match: []const Byte) bool { + if (target.len != match.len) { + return false; + } + + for (0 .. target.len) |index| { + if (target[index] != match[index]) { + return false; + } + } + + return true; +} + pub fn bytes_of(value: anytype) []const Byte { const pointer_info = @typeInfo(@TypeOf(value)).Pointer; @@ -326,20 +350,6 @@ pub fn ends_with(target: []const Byte, match: []const Byte) bool { return true; } -pub fn equals(target: []const Byte, match: []const Byte) bool { - if (target.len != match.len) { - return false; - } - - for (0 .. target.len) |index| { - if (target[index] != match[index]) { - return false; - } - } - - return true; -} - pub fn find_first(haystack: []const Byte, needle: Byte) ?usize { for (0 .. haystack.len) |i| { if (haystack[i] == needle) { diff --git a/source/coral/lina.zig b/source/coral/lina.zig deleted file mode 100644 index 4ca347e..0000000 --- a/source/coral/lina.zig +++ /dev/null @@ -1,12 +0,0 @@ - -pub const Vector3 = struct { - x: f32, - y: f32, - z: f32, - - pub fn equals(self: Vector3, other: Vector3) bool { - return self.x == other.x and self.y == other.y and self.z == other.z; - } - - pub const zero = Vector3{.x = 0, .y = 0, .z = 0}; -}; diff --git a/source/coral/map.zig b/source/coral/map.zig index 30a8bdb..f19cd27 100644 --- a/source/coral/map.zig +++ b/source/coral/map.zig @@ -11,7 +11,7 @@ pub fn StringTable(comptime Value: type) type { const Self = @This(); fn equals(key_a: []const io.Byte, key_b: []const io.Byte) bool { - return io.equals(key_a, key_b); + return io.are_equal(key_a, key_b); } fn hash(key: []const io.Byte) usize { diff --git a/source/coral/utf8.zig b/source/coral/utf8.zig index 97fb597..c1e7843 100644 --- a/source/coral/utf8.zig +++ b/source/coral/utf8.zig @@ -40,7 +40,7 @@ pub const DecimalFormat = struct { }, else => { - if (self.delimiter.len == 0 or !io.equals(self.delimiter, utf8[index ..])) { + if (self.delimiter.len == 0 or !io.are_equal(self.delimiter, utf8[index ..])) { return null; } }, diff --git a/source/ona/kym.zig b/source/ona/kym.zig index 46e45f8..c4f293e 100644 --- a/source/ona/kym.zig +++ b/source/ona/kym.zig @@ -39,6 +39,8 @@ pub const RuntimeEnv = struct { push_false, push_const: u16, push_local: u8, + push_vector2, + push_vector3, push_table: u32, push_builtin: Builtin, local_set: u8, @@ -108,6 +110,19 @@ pub const RuntimeEnv = struct { }); }, + .vector2_literal => |literal| { + try self.compile_expression(chunk, literal.y_expression.*); + try self.compile_expression(chunk, literal.x_expression.*); + try chunk.opcodes.push_one(.push_vector2); + }, + + .vector3_literal => |literal| { + try self.compile_expression(chunk, literal.z_expression.*); + try self.compile_expression(chunk, literal.y_expression.*); + try self.compile_expression(chunk, literal.x_expression.*); + try chunk.opcodes.push_one(.push_vector3); + }, + .table_literal => |fields| { if (fields.values.len > coral.math.max_int(@typeInfo(u32).Int)) { return error.OutOfMemory; @@ -257,7 +272,7 @@ pub const RuntimeEnv = struct { var index = @as(u8, self.local_identifiers_count - 1); while (true) : (index -= 1) { - if (coral.io.equals(local_identifier, self.local_identifiers_buffer[index])) { + if (coral.io.are_equal(local_identifier, self.local_identifiers_buffer[index])) { return index; } @@ -324,6 +339,47 @@ pub const RuntimeEnv = struct { } }, + .push_vector2 => { + const x = try self.env.expect(try self.pop_local()); + + defer self.env.discard(x); + + const y = try self.env.expect(try self.pop_local()); + + defer self.env.discard(y); + + const vector = try self.env.new_vector2( + @floatCast(try self.env.unbox_float(x)), + @floatCast(try self.env.unbox_float(y))); + + errdefer self.env.discard(vector); + + try self.env.locals.push_one(vector); + }, + + .push_vector3 => { + const x = try self.env.expect(try self.pop_local()); + + defer self.env.discard(x); + + const y = try self.env.expect(try self.pop_local()); + + defer self.env.discard(y); + + const z = try self.env.expect(try self.pop_local()); + + defer self.env.discard(z); + + const vector = try self.env.new_vector3( + @floatCast(try self.env.unbox_float(x)), + @floatCast(try self.env.unbox_float(y)), + @floatCast(try self.env.unbox_float(z))); + + errdefer self.env.discard(vector); + + try self.env.locals.push_one(vector); + }, + .push_table => |push_table| { const table = try self.env.new_table(); @@ -991,7 +1047,7 @@ pub const RuntimeEnv = struct { if (object.ref_count == 0) { switch (object.payload) { - .false, .true, .float, .fixed, .symbol, .vector, .syscall => {}, + .false, .true, .float, .fixed, .symbol, .vector2, .vector3, .syscall => {}, .string => |string| { coral.debug.assert(string.len >= 0); @@ -1190,10 +1246,17 @@ pub const RuntimeEnv = struct { }); } - pub fn new_vector(self: *RuntimeEnv, x: f32, y: f32, z: f32) RuntimeError!*RuntimeRef { + pub fn new_vector2(self: *RuntimeEnv, x: f32, y: f32) RuntimeError!*RuntimeRef { return RuntimeRef.allocate(self.allocator, .{ .ref_count = 1, - .payload = .{.vector = .{x, y, z}}, + .payload = .{.vector2 = .{x, y}}, + }); + } + + pub fn new_vector3(self: *RuntimeEnv, x: f32, y: f32, z: f32) RuntimeError!*RuntimeRef { + return RuntimeRef.allocate(self.allocator, .{ + .ref_count = 1, + .payload = .{.vector3 = .{x, y, z}}, }); } @@ -1294,7 +1357,8 @@ pub const RuntimeRef = opaque { float: Float, fixed: Fixed, symbol: [*:0]const coral.io.Byte, - vector: coral.lina.Vector3, + vector2: [2]f32, + vector3: [3]f32, syscall: *const Syscall, string: struct { @@ -1365,8 +1429,13 @@ pub const RuntimeRef = opaque { else => false, }, - .vector => |self_vector| switch (other.object().payload) { - .vector => |other_vector| self_vector.equals(other_vector), + .vector2 => |self_vector| switch (other.object().payload) { + .vector2 => |other_vector| coral.io.are_equal(coral.io.bytes_of(&self_vector), coral.io.bytes_of(&other_vector)), + else => false, + }, + + .vector3 => |self_vector| switch (other.object().payload) { + .vector3 => |other_vector| coral.io.are_equal(coral.io.bytes_of(&self_vector), coral.io.bytes_of(&other_vector)), else => false, }, @@ -1376,7 +1445,7 @@ pub const RuntimeRef = opaque { }, .string => |self_string| switch (other.object().payload) { - .string => |other_string| coral.io.equals(self_string.unpack(), other_string.unpack()), + .string => |other_string| coral.io.are_equal(self_string.unpack(), other_string.unpack()), else => false, }, @@ -1397,7 +1466,8 @@ pub const RuntimeRef = opaque { .float => |float| @bitCast(float), .fixed => |fixed| @intCast(@as(u32, @bitCast(fixed))), .symbol => |symbol| @intFromPtr(symbol), - .vector => |vector| coral.io.jenkins_hash(@typeInfo(usize).Int, coral.io.bytes_of(&vector)), + .vector2 => |vector| @bitCast(vector), + .vector3 => |vector| coral.io.jenkins_hash(@typeInfo(usize).Int, coral.io.bytes_of(&vector)), .syscall => |syscall| @intFromPtr(syscall), .string => |string| coral.io.djb2_hash(@typeInfo(usize).Int, string.unpack()), .dynamic => |dynamic| @intFromPtr(dynamic.typeinfo()) ^ @intFromPtr(dynamic.userdata().ptr), @@ -1418,7 +1488,8 @@ pub const RuntimeRef = opaque { .float => |float| float != 0, .fixed => |fixed| fixed != 0, .symbol => true, - .vector => |vector| !vector.equals(coral.lina.Vector3.zero), + .vector2 => |vector| coral.io.all_equals(coral.io.bytes_of(&vector), 0), + .vector3 => |vector| coral.io.all_equals(coral.io.bytes_of(&vector), 0), .syscall => true, .string => |string| string.len != 0, .dynamic => true, diff --git a/source/ona/kym/Ast.zig b/source/ona/kym/Ast.zig index 346f432..12cdeff 100755 --- a/source/ona/kym/Ast.zig +++ b/source/ona/kym/Ast.zig @@ -60,6 +60,17 @@ pub const Expression = union (enum) { argument_expressions: List, }, + vector2_literal: struct { + x_expression: *Expression, + y_expression: *Expression, + }, + + vector3_literal: struct { + x_expression: *Expression, + y_expression: *Expression, + z_expression: *Expression, + }, + pub const BinaryOperator = enum { addition, subtraction, @@ -357,6 +368,57 @@ fn parse_factor(self: *Self) ParseError!Expression { break: parse .{.builtin = builtin}; }, + .symbol_bracket_left => { + self.tokenizer.skip_newlines(); + + var expressions = [3]?*Expression{null, null, null}; + var size = @as(u2, 0); + + while (true) { + if (size == expressions.len) { + return self.report("vector literals cannot contain more than 3 elements"); + } + + expressions[size] = try coral.io.allocate_one(allocator, try self.parse_expression()); + size += 1; + + switch (self.tokenizer.token) { + .symbol_comma => { + self.tokenizer.skip_newlines(); + + continue; + }, + + .symbol_bracket_right => { + self.tokenizer.skip_newlines(); + + break; + }, + + else => return self.report("expected `,` or `]` after vector literal element expression"), + } + } + + break: parse switch (size) { + 0, 1 => return self.report("vector literals must contain at least 2 elements"), + + 2 => .{ + .vector2_literal = .{ + .x_expression = expressions[0] orelse unreachable, + .y_expression = expressions[1] orelse unreachable, + }, + }, + + 3 => .{ + .vector3_literal = .{ + .x_expression = expressions[0] orelse unreachable, + .y_expression = expressions[1] orelse unreachable, + .z_expression = expressions[2] orelse unreachable, + }, + }, + }; + }, + .symbol_brace_left => { var table_literal = Expression.TableLiteral.make(allocator); From 016165b6a6c544db1d5cbfa71554c7def5d3ec28 Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 13 Aug 2023 14:27:03 +0100 Subject: [PATCH 3/4] Replace dedicated vector literal syntax builtins --- debug/app.ona | 2 +- source/ona/kym.zig | 93 ++++++++++++++++++++++++++++++++---------- source/ona/kym/Ast.zig | 62 ---------------------------- 3 files changed, 72 insertions(+), 85 deletions(-) diff --git a/debug/app.ona b/debug/app.ona index 4950301..7ac7bb0 100644 --- a/debug/app.ona +++ b/debug/app.ona @@ -1,7 +1,7 @@ # Test comment. -pos = [10, 20, 0.3] +pos = @vec3(10, 20, 0.3) options = { .title = "Afterglow", diff --git a/source/ona/kym.zig b/source/ona/kym.zig index c4f293e..5ff65cd 100644 --- a/source/ona/kym.zig +++ b/source/ona/kym.zig @@ -24,6 +24,8 @@ pub const RuntimeEnv = struct { const Builtin = enum { import, print, + vec2, + vec3, }; const Constant = union (enum) { @@ -110,19 +112,6 @@ pub const RuntimeEnv = struct { }); }, - .vector2_literal => |literal| { - try self.compile_expression(chunk, literal.y_expression.*); - try self.compile_expression(chunk, literal.x_expression.*); - try chunk.opcodes.push_one(.push_vector2); - }, - - .vector3_literal => |literal| { - try self.compile_expression(chunk, literal.z_expression.*); - try self.compile_expression(chunk, literal.y_expression.*); - try self.compile_expression(chunk, literal.x_expression.*); - try chunk.opcodes.push_one(.push_vector3); - }, - .table_literal => |fields| { if (fields.values.len > coral.math.max_int(@typeInfo(u32).Int)) { return error.OutOfMemory; @@ -182,15 +171,33 @@ pub const RuntimeEnv = struct { .builtin => |builtin| { coral.debug.assert(builtin.len != 0); - const decoded_builtin = @as(?Builtin, switch (builtin[0]) { - 'i' => if (coral.io.ends_with(builtin, "mport")) .import else null, - 'p' => if (coral.io.ends_with(builtin, "rint")) .print else null, - else => null, - }); + switch (builtin[0]) { + 'i' => { + if (coral.io.ends_with(builtin, "mport")) { + return chunk.opcodes.push_one(.{.push_builtin = .import}); + } + }, - try chunk.opcodes.push_one(.{.push_builtin = decoded_builtin orelse { - return chunk.env.raise(error.BadSyntax, "unknown builtin"); - }}); + 'p' => { + if (coral.io.ends_with(builtin, "rint")) { + return chunk.opcodes.push_one(.{.push_builtin = .print}); + } + }, + + 'v' => { + if (coral.io.ends_with(builtin, "ec2")) { + return chunk.opcodes.push_one(.{.push_builtin = .vec2}); + } + + if (coral.io.ends_with(builtin, "ec3")) { + return chunk.opcodes.push_one(.{.push_builtin = .vec3}); + } + }, + + else => {}, + } + + return chunk.env.raise(error.BadSyntax, "unknown builtin"); }, .local_get => |local_get| { @@ -417,6 +424,8 @@ pub const RuntimeEnv = struct { const builtin_syscall = try self.env.new_syscall(switch (push_builtin) { .import => syscall_import, .print => syscall_print, + .vec2 => syscall_vec2, + .vec3 => syscall_vec3, }); errdefer self.env.discard(builtin_syscall); @@ -990,7 +999,7 @@ pub const RuntimeEnv = struct { const frame = self.frames.peek() orelse return self.raise(error.IllegalState, "stack underflow"); if (index < frame.arg_count) { - if (self.locals.values[frame.locals_top - (1 + index)]) |local| { + if (self.locals.values[(frame.locals_top - frame.arg_count) + index]) |local| { return self.acquire(local); } } @@ -1566,3 +1575,43 @@ fn syscall_print(env: *RuntimeEnv) RuntimeError!?*RuntimeRef { return null; } + +fn syscall_vec2(env: *RuntimeEnv) RuntimeError!?*RuntimeRef { + const x = decode: { + const value = try env.expect(try env.acquire_arg(0)); + + defer env.discard(value); + + break: decode @as(f32, @floatCast(try env.unbox_float(value))); + }; + + if (try env.acquire_arg(1)) |y| { + defer env.discard(y); + + return env.new_vector2(x, @floatCast(try env.unbox_float(y))); + } + + return env.new_vector2(x, x); +} + +fn syscall_vec3(env: *RuntimeEnv) RuntimeError!?*RuntimeRef { + const x = decode: { + const value = try env.expect(try env.acquire_arg(0)); + + defer env.discard(value); + + break: decode @as(f32, @floatCast(try env.unbox_float(value))); + }; + + if (try env.acquire_arg(1)) |y| { + defer env.discard(y); + + const z = try env.expect(try env.acquire_arg(2)); + + defer env.discard(z); + + return env.new_vector3(x, @floatCast(try env.unbox_float(y)), @floatCast(try env.unbox_float(z))); + } + + return env.new_vector3(x, x, x); +} diff --git a/source/ona/kym/Ast.zig b/source/ona/kym/Ast.zig index 12cdeff..346f432 100755 --- a/source/ona/kym/Ast.zig +++ b/source/ona/kym/Ast.zig @@ -60,17 +60,6 @@ pub const Expression = union (enum) { argument_expressions: List, }, - vector2_literal: struct { - x_expression: *Expression, - y_expression: *Expression, - }, - - vector3_literal: struct { - x_expression: *Expression, - y_expression: *Expression, - z_expression: *Expression, - }, - pub const BinaryOperator = enum { addition, subtraction, @@ -368,57 +357,6 @@ fn parse_factor(self: *Self) ParseError!Expression { break: parse .{.builtin = builtin}; }, - .symbol_bracket_left => { - self.tokenizer.skip_newlines(); - - var expressions = [3]?*Expression{null, null, null}; - var size = @as(u2, 0); - - while (true) { - if (size == expressions.len) { - return self.report("vector literals cannot contain more than 3 elements"); - } - - expressions[size] = try coral.io.allocate_one(allocator, try self.parse_expression()); - size += 1; - - switch (self.tokenizer.token) { - .symbol_comma => { - self.tokenizer.skip_newlines(); - - continue; - }, - - .symbol_bracket_right => { - self.tokenizer.skip_newlines(); - - break; - }, - - else => return self.report("expected `,` or `]` after vector literal element expression"), - } - } - - break: parse switch (size) { - 0, 1 => return self.report("vector literals must contain at least 2 elements"), - - 2 => .{ - .vector2_literal = .{ - .x_expression = expressions[0] orelse unreachable, - .y_expression = expressions[1] orelse unreachable, - }, - }, - - 3 => .{ - .vector3_literal = .{ - .x_expression = expressions[0] orelse unreachable, - .y_expression = expressions[1] orelse unreachable, - .z_expression = expressions[2] orelse unreachable, - }, - }, - }; - }, - .symbol_brace_left => { var table_literal = Expression.TableLiteral.make(allocator); From af7483db13d5dc90a32b8ae051c03df5fc032561 Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 13 Aug 2023 14:38:21 +0100 Subject: [PATCH 4/4] Remove dead code changes --- source/ona/kym.zig | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/source/ona/kym.zig b/source/ona/kym.zig index 5ff65cd..9489d4a 100644 --- a/source/ona/kym.zig +++ b/source/ona/kym.zig @@ -41,8 +41,6 @@ pub const RuntimeEnv = struct { push_false, push_const: u16, push_local: u8, - push_vector2, - push_vector3, push_table: u32, push_builtin: Builtin, local_set: u8, @@ -346,47 +344,6 @@ pub const RuntimeEnv = struct { } }, - .push_vector2 => { - const x = try self.env.expect(try self.pop_local()); - - defer self.env.discard(x); - - const y = try self.env.expect(try self.pop_local()); - - defer self.env.discard(y); - - const vector = try self.env.new_vector2( - @floatCast(try self.env.unbox_float(x)), - @floatCast(try self.env.unbox_float(y))); - - errdefer self.env.discard(vector); - - try self.env.locals.push_one(vector); - }, - - .push_vector3 => { - const x = try self.env.expect(try self.pop_local()); - - defer self.env.discard(x); - - const y = try self.env.expect(try self.pop_local()); - - defer self.env.discard(y); - - const z = try self.env.expect(try self.pop_local()); - - defer self.env.discard(z); - - const vector = try self.env.new_vector3( - @floatCast(try self.env.unbox_float(x)), - @floatCast(try self.env.unbox_float(y)), - @floatCast(try self.env.unbox_float(z))); - - errdefer self.env.discard(vector); - - try self.env.locals.push_one(vector); - }, - .push_table => |push_table| { const table = try self.env.new_table();