diff --git a/debug/app.ona b/debug/app.ona index f05118d..9407ffe 100644 --- a/debug/app.ona +++ b/debug/app.ona @@ -1,12 +1,14 @@ -let printer = lambda (): +let printer = lambda (pfx): + let prefix = pfx + return lambda (msg): - @print("This is a func call") + @print(prefix) @print(msg) end end -let pr = printer() +let pr = printer("This is a func call") var i = 0 pr("test") @@ -25,6 +27,10 @@ else: pr("i'unno") end +let pr2 = printer("this is a final closure") + +pr2("goodbye") + return { .title = "Game", .width = 1280, diff --git a/source/ona/file.zig b/source/ona/file.zig index b05ae92..73a5b98 100644 --- a/source/ona/file.zig +++ b/source/ona/file.zig @@ -11,9 +11,9 @@ pub const Access = union (enum) { .null => return null, .sandboxed_path => |sandboxed_path| { - const readable_path_string = sandboxed_path.joined(readable_path).to_string() orelse return null; + const path_string = sandboxed_path.joined(readable_path).get_string(); - return @ptrCast(ext.SDL_RWFromFile(readable_path_string.ptr, "rb")); + return @ptrCast(ext.SDL_RWFromFile(path_string.ptr, "rb")); }, } } @@ -23,7 +23,7 @@ pub const Access = union (enum) { .null => return null, .sandboxed_path => |sandboxed_path| { - const path_string = sandboxed_path.joined(path).to_string() orelse return null; + const path_string = sandboxed_path.joined(path).get_string(); const rw_ops = ext.SDL_RWFromFile(path_string, "rb") orelse return null; const file_size = ext.SDL_RWseek(rw_ops, 0, ext.RW_SEEK_END); @@ -96,12 +96,8 @@ pub const Path = extern struct { return path; } - pub fn to_string(self: Path) ?[:0]const coral.io.Byte { - const last_index = self.data.len - 1; - - if (self.data[last_index] != 0) { - return null; - } + pub fn get_string(self: Path) [:0]const coral.io.Byte { + coral.debug.assert(self.data[self.data.len - 1] == 0); return coral.io.slice_sentineled(@as(coral.io.Byte, 0), @as([*:0]const coral.io.Byte, @ptrCast(&self.data))); } diff --git a/source/ona/kym.zig b/source/ona/kym.zig index d56c80f..12fbf32 100644 --- a/source/ona/kym.zig +++ b/source/ona/kym.zig @@ -2,10 +2,6 @@ const Chunk = @import("./kym/Chunk.zig"); const Table = @import("./kym/Table.zig"); -const app = @import("./app.zig"); - -const builtin = @import("builtin"); - const coral = @import("coral"); const file = @import("./file.zig"); @@ -15,7 +11,7 @@ const tokens = @import("./kym/tokens.zig"); const tree = @import("./kym/tree.zig"); pub const Frame = struct { - name: []const coral.io.Byte = "", + name_stringable: *RuntimeRef, arg_count: u8, locals_top: usize, @@ -88,11 +84,11 @@ pub const RuntimeEnv = struct { try self.locals.push_one(try self.acquire(arg)); } - const frame = try self.push_frame(args.len); + const frame = try self.push_frame(callable, args.len); defer self.pop_frame(); - return self.call_frame(callable, frame); + return self.call_frame(frame); } pub fn call_frame(self: *RuntimeEnv, callable: *const RuntimeRef, frame: Frame) RuntimeError!?*RuntimeRef { @@ -132,6 +128,12 @@ pub const RuntimeEnv = struct { switch (object.payload) { .false, .true, .float, .fixed, .symbol, .vector2, .vector3, .syscall => {}, + .boxed => |*boxed| { + if (boxed.*) |boxed_value| { + self.discard(boxed_value); + } + }, + .string => |string| { coral.debug.assert(string.len >= 0); self.allocator.deallocate(string.ptr[0 .. @intCast(string.len)]); @@ -201,6 +203,7 @@ pub const RuntimeEnv = struct { .string => self.raise(error.TypeMismatch, "string is not get-indexable"), .symbol => self.raise(error.TypeMismatch, "symbol is not get-indexable"), .syscall => self.raise(error.TypeMismatch, "syscall is not get-indexable"), + .boxed => self.raise(error.TypeMismatch, "boxed is not get-indexable"), .vector2 => |vector2| swizzle: { const swizzle_symbol = try self.unbox_symbol(index); @@ -258,6 +261,8 @@ pub const RuntimeEnv = struct { } pub fn import(self: *RuntimeEnv, file_path: file.Path) RuntimeError!?*RuntimeRef { + const file_name = file_path.get_string(); + var chunk = make_chunk: { const file_data = (try file.allocate_and_load(self.allocator, self.options.import_access, file_path)) orelse { @@ -282,24 +287,17 @@ pub const RuntimeEnv = struct { }; } - break: make_chunk try Chunk.make(self, file_path.to_string() orelse "