Implement Bytecode Executor for Kym #19

Merged
kayomn merged 9 commits from kym-bytecode-executor into main 2023-07-12 02:58:03 +02:00
2 changed files with 12 additions and 0 deletions
Showing only changes of commit bf0ff03b49 - Show all commits

View File

@ -210,6 +210,13 @@ pub fn error_details(self: Self) []const u8 {
return self.message_data.values;
}
pub fn execute(self: *Self) types.RuntimeError!types.Val {
_ = self;
// TODO: Implement.
return .nil;
}
pub fn init(env: *Environment, chunk_name: []const u8) coral.io.AllocationError!Self {
var message_data = Buffer{};

View File

@ -198,6 +198,10 @@ pub fn execute_data(self: *Self, source: DataSource) types.RuntimeError!types.Va
const typeid = "<chunk>";
const Behaviors = struct {
fn call(context: ObjectInfo.CallContext) types.RuntimeError!types.Val {
return (context.env.native_cast(context.callable, typeid, Chunk) catch unreachable).execute();
}
fn deinitialize(context: ObjectInfo.DeinitializeContext) void {
(context.env.native_cast(context.obj, typeid, Chunk) catch unreachable).deinit();
}
@ -220,6 +224,7 @@ pub fn execute_data(self: *Self, source: DataSource) types.RuntimeError!types.Va
const script = try self.new_object(coral.io.bytes_of(&compiled_chunk), .{
.identity = typeid,
.deinitializer = Behaviors.deinitialize,
.caller = Behaviors.call,
});
defer self.discard(script);