Compare commits
No commits in common. "1d2f98348f014ecd7adea516da6edb88a3fe380b" and "0ddc42c00f35253c5a7aa8c878cf0602d1b5c521" have entirely different histories.
1d2f98348f
...
0ddc42c00f
4 changed files with 8 additions and 20 deletions
|
|
@ -19,7 +19,6 @@ fn renderRec(vm: *Vm, canvas: *Canvas, val: Value, depth: usize, max_depth: usiz
|
||||||
.{max_depth},
|
.{max_depth},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (val == .nil) return;
|
|
||||||
if (val != .ref) return notAScribble(vm, val);
|
if (val != .ref) return notAScribble(vm, val);
|
||||||
|
|
||||||
switch (val.ref.*) {
|
switch (val.ref.*) {
|
||||||
|
|
|
||||||
|
|
@ -146,12 +146,8 @@ pub const Closure = struct {
|
||||||
param_count: u8,
|
param_count: u8,
|
||||||
impl: Impl,
|
impl: Impl,
|
||||||
|
|
||||||
pub fn globalBytecodePtr(c: *const Closure, pc: usize) [*]const u8 {
|
pub fn bytecodePtr(c: *const Closure, pc: usize) [*]const u8 {
|
||||||
return c.impl.bytecode.chunk.bytecode[pc..].ptr;
|
return c.impl.bytecode.chunk.bytecode[c.impl.bytecode.start + pc ..].ptr;
|
||||||
}
|
|
||||||
|
|
||||||
pub fn relBytecodePtr(c: *const Closure, pc: usize) [*]const u8 {
|
|
||||||
return c.globalBytecodePtr(c.impl.bytecode.start + pc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn programCounter(c: *const Closure, ip: [*]const u8) u16 {
|
pub fn programCounter(c: *const Closure, ip: [*]const u8) u16 {
|
||||||
|
|
|
||||||
|
|
@ -266,10 +266,8 @@ pub fn run(
|
||||||
// system functions should be able to call themselves (like: map (range 1 10) sin)
|
// system functions should be able to call themselves (like: map (range 1 10) sin)
|
||||||
debug.assert(init_closure.impl == .bytecode);
|
debug.assert(init_closure.impl == .bytecode);
|
||||||
|
|
||||||
log.debug("BYTECODE {any}", .{init_closure.impl.bytecode.chunk.bytecode});
|
|
||||||
|
|
||||||
var closure = init_closure;
|
var closure = init_closure;
|
||||||
var ip: [*]const u8 = closure.relBytecodePtr(0);
|
var ip: [*]const u8 = closure.bytecodePtr(0);
|
||||||
var bottom = init_bottom;
|
var bottom = init_bottom;
|
||||||
var fuel = vm.fuel;
|
var fuel = vm.fuel;
|
||||||
|
|
||||||
|
|
@ -393,7 +391,7 @@ pub fn run(
|
||||||
const name = ip[0..name_len];
|
const name = ip[0..name_len];
|
||||||
ip += name_len;
|
ip += name_len;
|
||||||
const body = ip;
|
const body = ip;
|
||||||
ip = closure.globalBytecodePtr(then);
|
ip = closure.bytecodePtr(then);
|
||||||
|
|
||||||
const local_count = read(u8, &ip);
|
const local_count = read(u8, &ip);
|
||||||
const capture_count = read(u8, &ip);
|
const capture_count = read(u8, &ip);
|
||||||
|
|
@ -420,7 +418,7 @@ pub fn run(
|
||||||
.param_count = param_count,
|
.param_count = param_count,
|
||||||
.impl = .{ .bytecode = .{
|
.impl = .{ .bytecode = .{
|
||||||
.chunk = closure.impl.bytecode.chunk,
|
.chunk = closure.impl.bytecode.chunk,
|
||||||
.start = @truncate(body - closure.relBytecodePtr(0)),
|
.start = @truncate(body - closure.bytecodePtr(0)),
|
||||||
.local_count = local_count,
|
.local_count = local_count,
|
||||||
.captures = captures,
|
.captures = captures,
|
||||||
} },
|
} },
|
||||||
|
|
@ -435,8 +433,7 @@ pub fn run(
|
||||||
.jump => {
|
.jump => {
|
||||||
const offset = read(u16, &ip);
|
const offset = read(u16, &ip);
|
||||||
try vm.consumeFuel(&fuel, 1);
|
try vm.consumeFuel(&fuel, 1);
|
||||||
log.debug("JUMP {}", .{offset});
|
ip = closure.bytecodePtr(offset);
|
||||||
ip = closure.globalBytecodePtr(offset);
|
|
||||||
continue :next vm.readOpcode(&ip);
|
continue :next vm.readOpcode(&ip);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -445,10 +442,7 @@ pub fn run(
|
||||||
try vm.consumeFuel(&fuel, 1);
|
try vm.consumeFuel(&fuel, 1);
|
||||||
const condition = try vm.pop();
|
const condition = try vm.pop();
|
||||||
if (!condition.isTruthy()) {
|
if (!condition.isTruthy()) {
|
||||||
log.debug("CJUMP {} JUMPED", .{offset});
|
ip = closure.bytecodePtr(offset);
|
||||||
ip = closure.globalBytecodePtr(offset);
|
|
||||||
} else {
|
|
||||||
log.debug("CJUMP {} SKIPPED", .{offset});
|
|
||||||
}
|
}
|
||||||
continue :next vm.readOpcode(&ip);
|
continue :next vm.readOpcode(&ip);
|
||||||
},
|
},
|
||||||
|
|
@ -514,7 +508,7 @@ pub fn run(
|
||||||
try vm.validateBytecode(overflow == 0, "not enough values on the stack for arguments", .{});
|
try vm.validateBytecode(overflow == 0, "not enough values on the stack for arguments", .{});
|
||||||
|
|
||||||
closure = called_closure;
|
closure = called_closure;
|
||||||
ip = closure.relBytecodePtr(0);
|
ip = closure.bytecodePtr(0);
|
||||||
bottom = new_bottom;
|
bottom = new_bottom;
|
||||||
|
|
||||||
// pushCall before setting vm.closure and vm.ip, such that stack overflow errors are
|
// pushCall before setting vm.closure and vm.ip, such that stack overflow errors are
|
||||||
|
|
|
||||||
|
|
@ -546,7 +546,6 @@ rkgk-brush-editor {
|
||||||
|
|
||||||
& > .errors {
|
& > .errors {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 4px;
|
|
||||||
color: var(--color-error);
|
color: var(--color-error);
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue