Compare commits
No commits in common. "70746b4680f37b15e1756dd7a792941e5c44763f" and "e5c18e4a14730f7de228a68d3a080ee9d4bcaded" have entirely different histories.
70746b4680
...
e5c18e4a14
|
@ -1,2 +0,0 @@
|
|||
|
||||
pub const lina = @import("./gfx/lina.zig");
|
|
@ -1,181 +0,0 @@
|
|||
|
||||
pub const Vector2 = struct {
|
||||
x: f32,
|
||||
y: f32,
|
||||
|
||||
pub const Scalars = [2]f32;
|
||||
|
||||
pub fn equals(self: Vector2, vector: Vector2) bool {
|
||||
return self.x == vector.x and self.y == vector.y;
|
||||
}
|
||||
|
||||
pub fn from_scalar(scalar: f32) Vector2 {
|
||||
return .{
|
||||
.x = scalar,
|
||||
.y = scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn from_scalars(scalars: Scalars) Vector2 {
|
||||
return .{
|
||||
.x = scalars[0],
|
||||
.y = scalars[1],
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scalar_added(self: Vector2, scalar: f32) Vector2 {
|
||||
return .{
|
||||
.x = self.x + scalar,
|
||||
.y = self.y + scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scalar_divided(self: Vector2, scalar: f32) Vector2 {
|
||||
return .{
|
||||
.x = self.x / scalar,
|
||||
.y = self.y / scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scalar_multiplied(self: Vector2, scalar: f32) Vector2 {
|
||||
return .{
|
||||
.x = self.x * scalar,
|
||||
.y = self.y * scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn to_scalars(self: Vector2) Scalars {
|
||||
return .{self.x, self.y};
|
||||
}
|
||||
|
||||
pub fn scalar_subtracted(self: Vector2, scalar: f32) Vector2 {
|
||||
return .{
|
||||
.x = self.x - scalar,
|
||||
.y = self.y - scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector_added(self: Vector2, vector: Vector2) Vector2 {
|
||||
return .{
|
||||
.x = self.x + vector.x,
|
||||
.y = self.y + vector.y,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector_divided(self: Vector2, vector: Vector2) Vector2 {
|
||||
return .{
|
||||
.x = self.x / vector.x,
|
||||
.y = self.y / vector.y,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector_multiplied(self: Vector2, vector: Vector2) Vector2 {
|
||||
return .{
|
||||
.x = self.x * vector.x,
|
||||
.y = self.y * vector.y,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector_subtracted(self: Vector2, vector: Vector2) Vector2 {
|
||||
return .{
|
||||
.x = self.x - vector.x,
|
||||
.y = self.y - vector.y,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const Vector3 = struct {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
|
||||
pub const Scalars = [3]f32;
|
||||
|
||||
pub fn equals(self: Vector3, vector: Vector3) bool {
|
||||
return self.x == vector.x and self.y == vector.y and self.z == vector.z;
|
||||
}
|
||||
|
||||
pub fn from_scalar(scalar: f32) Vector3 {
|
||||
return .{
|
||||
.x = scalar,
|
||||
.y = scalar,
|
||||
.z = scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn from_scalars(scalars: Scalars) Vector3 {
|
||||
return .{
|
||||
.x = scalars[0],
|
||||
.y = scalars[1],
|
||||
.z = scalars[2],
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scalar_added(self: Vector3, scalar: f32) Vector3 {
|
||||
return .{
|
||||
.x = self.x + scalar,
|
||||
.y = self.y + scalar,
|
||||
.z = self.z + scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scalar_divided(self: Vector3, scalar: f32) Vector3 {
|
||||
return .{
|
||||
.x = self.x / scalar,
|
||||
.y = self.y / scalar,
|
||||
.z = self.z / scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scalar_multiplied(self: Vector3, scalar: f32) Vector3 {
|
||||
return .{
|
||||
.x = self.x * scalar,
|
||||
.y = self.y * scalar,
|
||||
.z = self.z * scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scalar_subtracted(self: Vector3, scalar: f32) Vector3 {
|
||||
return .{
|
||||
.x = self.x - scalar,
|
||||
.y = self.y - scalar,
|
||||
.z = self.z - scalar,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn to_scalars(self: Vector3) Scalars {
|
||||
return .{self.x, self.y, self.z};
|
||||
}
|
||||
|
||||
pub fn vector_added(self: Vector3, other: Vector3) Vector3 {
|
||||
return .{
|
||||
.x = self.x + other.x,
|
||||
.y = self.y + other.y,
|
||||
.z = self.z + other.z,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector_divided(self: Vector3, other: Vector3) Vector3 {
|
||||
return .{
|
||||
.x = self.x / other.x,
|
||||
.y = self.y / other.y,
|
||||
.z = self.z / other.z,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector_multiplied(self: Vector3, other: Vector3) Vector3 {
|
||||
return .{
|
||||
.x = self.x * other.x,
|
||||
.y = self.y * other.y,
|
||||
.z = self.z * other.z,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn vector_subtracted(self: Vector3, other: Vector3) Vector3 {
|
||||
return .{
|
||||
.x = self.x - other.x,
|
||||
.y = self.y - other.y,
|
||||
.z = self.z - other.z,
|
||||
};
|
||||
}
|
||||
};
|
1468
source/ona/kym.zig
1468
source/ona/kym.zig
File diff suppressed because it is too large
Load Diff
|
@ -632,7 +632,7 @@ pub fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.Runtime
|
|||
.push_false => _ = try env.new_boolean(false),
|
||||
.push_const => |push_const| _ = try env.push(try self.get_constant(env, push_const)),
|
||||
.push_local => |push_local| _ = try env.local_get(push_local),
|
||||
.push_top => _ = try env.local_top(),
|
||||
.push_top => _ = try env.local_get(env.local_count() - 1),
|
||||
|
||||
.push_table => |push_table| {
|
||||
const table = (try env.new_table()).pop().?;
|
||||
|
@ -708,7 +708,7 @@ pub fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.Runtime
|
|||
.vec3 => syscall_vec3,
|
||||
}),
|
||||
|
||||
.set_local => |local_set| _ = try env.local_set(local_set, env.pop()),
|
||||
.set_local => |local_set| _ = env.local_set(local_set, env.pop()),
|
||||
.get_box => _ = try env.boxed_get(),
|
||||
|
||||
.set_box => {
|
||||
|
@ -765,10 +765,10 @@ pub fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.Runtime
|
|||
defer env.release(addable);
|
||||
|
||||
_ = switch (try env.expect_numeric(addable)) {
|
||||
.fixed => |fixed| try env.fixed_add(fixed),
|
||||
.float => |float| try env.float_add(float),
|
||||
.vector2 => |vector2| try env.vector2_add(vector2),
|
||||
.vector3 => |vector3| try env.vector3_add(vector3),
|
||||
.fixed => |fixed| try env.add_fixed(fixed),
|
||||
.float => |float| try env.add_float(float),
|
||||
.vector2 => |vector2| try env.add_vector2(vector2),
|
||||
.vector3 => |vector3| try env.add_vector3(vector3),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -778,10 +778,10 @@ pub fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.Runtime
|
|||
defer env.release(subtractable);
|
||||
|
||||
_ = switch (try env.expect_numeric(subtractable)) {
|
||||
.fixed => |fixed| try env.fixed_subtract(fixed),
|
||||
.float => |float| try env.float_subtract(float),
|
||||
.vector2 => |vector2| try env.vector2_subtract(vector2),
|
||||
.vector3 => |vector3| try env.vector3_subtract(vector3),
|
||||
.fixed => |fixed| try env.sub_fixed(fixed),
|
||||
.float => |float| try env.sub_float(float),
|
||||
.vector2 => |vector2| try env.sub_vector2(vector2),
|
||||
.vector3 => |vector3| try env.sub_vector3(vector3),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -791,10 +791,10 @@ pub fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.Runtime
|
|||
defer env.release(multiplicable);
|
||||
|
||||
_ = switch (try env.expect_numeric(multiplicable)) {
|
||||
.fixed => |fixed| try env.fixed_multiply(fixed),
|
||||
.float => |float| try env.float_multiply(float),
|
||||
.vector2 => |vector2| try env.vector2_multiply(vector2),
|
||||
.vector3 => |vector3| try env.vector3_multiply(vector3),
|
||||
.fixed => |fixed| try env.mul_fixed(fixed),
|
||||
.float => |float| try env.mul_float(float),
|
||||
.vector2 => |vector2| try env.mul_vector2(vector2),
|
||||
.vector3 => |vector3| try env.mul_vector3(vector3),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -804,10 +804,10 @@ pub fn execute(self: *Self, env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.Runtime
|
|||
defer env.release(divisible);
|
||||
|
||||
_ = switch (try env.expect_numeric(divisible)) {
|
||||
.fixed => |fixed| try env.fixed_divide(fixed),
|
||||
.float => |float| try env.float_divide(float),
|
||||
.vector2 => |vector2| try env.vector2_divide(vector2),
|
||||
.vector3 => |vector3| try env.vector3_divide(vector3),
|
||||
.fixed => |fixed| try env.div_fixed(fixed),
|
||||
.float => |float| try env.div_float(float),
|
||||
.vector2 => |vector2| try env.div_vector2(vector2),
|
||||
.vector3 => |vector3| try env.div_vector3(vector3),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -914,6 +914,9 @@ pub fn init(env: *kym.RuntimeEnv, name: []const coral.io.Byte, environment: *con
|
|||
|
||||
try compiler.compile_environment(environment);
|
||||
|
||||
@import("../app.zig").log_info("");
|
||||
@import("../app.zig").log_info((try (try env.push(try chunk.dump(env))).to_string()).pop().?.is_string().?);
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
@ -951,13 +954,10 @@ fn syscall_vec2(env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.RuntimeObj {
|
|||
if ((try env.arg_get(1)).pop()) |y| {
|
||||
defer env.release(y);
|
||||
|
||||
return (try env.new_vector2(.{
|
||||
.y = @floatCast(try env.expect_float(y)),
|
||||
.x = x,
|
||||
})).pop();
|
||||
return (try env.new_vector2(x, @floatCast(try env.expect_float(y)))).pop();
|
||||
}
|
||||
|
||||
return (try env.new_vector2(kym.Vector2.from_scalar(x))).pop();
|
||||
return (try env.new_vector2(x, x)).pop();
|
||||
}
|
||||
|
||||
fn syscall_vec3(env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.RuntimeObj {
|
||||
|
@ -974,8 +974,7 @@ fn syscall_vec3(env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.RuntimeObj {
|
|||
if ((try env.arg_get(1)).pop()) |y| {
|
||||
defer env.release(y);
|
||||
|
||||
return (try env.new_vector3(.{
|
||||
.z = @as(f32, get_z: {
|
||||
const z = @as(f32, get_z: {
|
||||
const z = (try env.arg_get(0)).pop() orelse {
|
||||
return env.raise(error.BadOperation,
|
||||
"a third argument is required to create a vector if a first and second exist", .{});
|
||||
|
@ -984,14 +983,12 @@ fn syscall_vec3(env: *kym.RuntimeEnv) kym.RuntimeError!?*kym.RuntimeObj {
|
|||
defer env.release(z);
|
||||
|
||||
break: get_z @floatCast(try env.expect_float(z));
|
||||
}),
|
||||
});
|
||||
|
||||
.y = @floatCast(try env.expect_float(y)),
|
||||
.x = x,
|
||||
})).pop();
|
||||
return (try env.new_vector3(x, @floatCast(try env.expect_float(y)), z)).pop();
|
||||
}
|
||||
|
||||
return (try env.new_vector3(kym.Vector3.from_scalar(x))).pop();
|
||||
return (try env.new_vector3(x, x, x)).pop();
|
||||
}
|
||||
|
||||
pub const typeinfo = &kym.Typeinfo{
|
||||
|
@ -1002,16 +999,16 @@ pub const typeinfo = &kym.Typeinfo{
|
|||
.to_string = typeinfo_to_string,
|
||||
};
|
||||
|
||||
fn typeinfo_call(context: kym.Typeinfo.CallContext) kym.RuntimeError!?*kym.RuntimeObj {
|
||||
return @as(*Self, @ptrCast(@alignCast(context.userdata))).execute(context.env);
|
||||
fn typeinfo_call(env: *kym.RuntimeEnv, userdata: []coral.io.Byte) kym.RuntimeError!?*kym.RuntimeObj {
|
||||
return @as(*Self, @ptrCast(@alignCast(userdata))).execute(env);
|
||||
}
|
||||
|
||||
fn typeinfo_destruct(context: kym.Typeinfo.DestructContext) void {
|
||||
@as(*Self, @ptrCast(@alignCast(context.userdata))).deinit(context.env);
|
||||
fn typeinfo_destruct(env: *kym.RuntimeEnv, userdata: []coral.io.Byte) void {
|
||||
@as(*Self, @ptrCast(@alignCast(userdata))).deinit(env);
|
||||
}
|
||||
|
||||
fn typeinfo_to_string(context: kym.Typeinfo.ToStringContext) kym.RuntimeError!*kym.RuntimeObj {
|
||||
return (try (try context.env.push(@as(*Self, @ptrCast(@alignCast(context.userdata))).name)).to_string()).pop().?;
|
||||
fn typeinfo_to_string(env: *kym.RuntimeEnv, userdata: []coral.io.Byte) kym.RuntimeError!*kym.RuntimeObj {
|
||||
return (try (try env.push(@as(*Self, @ptrCast(@alignCast(userdata))).name)).to_string()).pop().?;
|
||||
}
|
||||
|
||||
pub fn write(self: *Self, line: tokens.Line, opcode: Opcode) coral.io.AllocationError!void {
|
||||
|
|
|
@ -8,7 +8,7 @@ contiguous: RefList,
|
|||
const RefList = coral.list.Stack(?*kym.RuntimeObj);
|
||||
|
||||
const RefTable = coral.map.Table(*kym.RuntimeObj, *kym.RuntimeObj, struct {
|
||||
pub const hash = kym.RuntimeObj.hash;
|
||||
pub const hash = kym.RuntimeObj.get_hash;
|
||||
|
||||
pub const equals = kym.RuntimeObj.equals;
|
||||
});
|
||||
|
@ -51,41 +51,41 @@ pub const typeinfo = &kym.Typeinfo{
|
|||
.set = typeinfo_set,
|
||||
};
|
||||
|
||||
fn typeinfo_destruct(context: kym.Typeinfo.DestructContext) void {
|
||||
@as(*Self, @ptrCast(@alignCast(context.userdata))).deinit(context.env);
|
||||
fn typeinfo_destruct(env: *kym.RuntimeEnv, userdata: []coral.io.Byte) void {
|
||||
@as(*Self, @ptrCast(@alignCast(userdata))).deinit(env);
|
||||
}
|
||||
|
||||
fn typeinfo_get(context: kym.Typeinfo.GetContext) kym.RuntimeError!?*kym.RuntimeObj {
|
||||
const table = @as(*Self, @ptrCast(@alignCast(context.userdata)));
|
||||
const index = (try context.push_index()).pop().?;
|
||||
fn typeinfo_get(env: *kym.RuntimeEnv, userdata: []coral.io.Byte, index: *const kym.RuntimeObj) kym.RuntimeError!?*kym.RuntimeObj {
|
||||
const table = @as(*Self, @ptrCast(@alignCast(userdata)));
|
||||
const acquired_index = index.acquire();
|
||||
|
||||
defer context.env.release(index);
|
||||
defer env.release(acquired_index);
|
||||
|
||||
if (index.is_fixed()) |fixed| {
|
||||
if (acquired_index.is_fixed()) |fixed| {
|
||||
if (fixed < 0) {
|
||||
// TODO: Negative indexing.
|
||||
unreachable;
|
||||
}
|
||||
|
||||
if (fixed < table.contiguous.values.len) {
|
||||
return table.contiguous.values[@intCast(fixed)];
|
||||
return (table.contiguous.values[@intCast(fixed)] orelse return null).acquire();
|
||||
}
|
||||
}
|
||||
|
||||
if (table.associative.lookup(index)) |value| {
|
||||
return value;
|
||||
if (table.associative.lookup(acquired_index)) |value| {
|
||||
return value.acquire();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
fn typeinfo_set(context: kym.Typeinfo.SetContext) kym.RuntimeError!void {
|
||||
const table = @as(*Self, @ptrCast(@alignCast(context.userdata)));
|
||||
const index = (try context.push_index()).pop().?;
|
||||
fn typeinfo_set(env: *kym.RuntimeEnv, userdata: []coral.io.Byte, index: *const kym.RuntimeObj, value: ?*const kym.RuntimeObj) kym.RuntimeError!void {
|
||||
const table = @as(*Self, @ptrCast(@alignCast(userdata)));
|
||||
const acquired_index = index.acquire();
|
||||
|
||||
errdefer context.env.release(index);
|
||||
errdefer env.release(acquired_index);
|
||||
|
||||
if (index.is_fixed()) |fixed| {
|
||||
if (acquired_index.is_fixed()) |fixed| {
|
||||
if (fixed < 0) {
|
||||
// TODO: Negative indexing.
|
||||
unreachable;
|
||||
|
@ -95,34 +95,28 @@ fn typeinfo_set(context: kym.Typeinfo.SetContext) kym.RuntimeError!void {
|
|||
const maybe_replacing = &table.contiguous.values[@intCast(fixed)];
|
||||
|
||||
if (maybe_replacing.*) |replacing| {
|
||||
context.env.release(replacing);
|
||||
env.release(replacing);
|
||||
}
|
||||
|
||||
if ((try context.push_value()).pop()) |value| {
|
||||
errdefer context.env.release(value);
|
||||
|
||||
maybe_replacing.* = value;
|
||||
} else {
|
||||
maybe_replacing.* = null;
|
||||
}
|
||||
maybe_replacing.* = if (value) |ref| ref.acquire() else null;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const value = (try context.push_value()).pop() orelse {
|
||||
if (table.associative.remove(index)) |removed| {
|
||||
context.env.release(removed.key);
|
||||
context.env.release(removed.value);
|
||||
const acquired_value = (value orelse {
|
||||
if (table.associative.remove(acquired_index)) |removed| {
|
||||
env.release(removed.key);
|
||||
env.release(removed.value);
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
}).acquire();
|
||||
|
||||
errdefer context.env.release(value);
|
||||
errdefer env.release(acquired_value);
|
||||
|
||||
if (try table.associative.replace(index, value)) |replaced| {
|
||||
context.env.release(replaced.key);
|
||||
context.env.release(replaced.value);
|
||||
if (try table.associative.replace(acquired_index, acquired_value)) |replaced| {
|
||||
env.release(replaced.key);
|
||||
env.release(replaced.value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue