feat: part of the story api exposed via c bindings
This commit is contained in:
parent
a065e5bf46
commit
3afbbb6ec2
6 changed files with 748 additions and 16 deletions
|
|
@ -38,6 +38,7 @@ constants_pool: []const Value = &.{},
|
|||
/// Interned string bytes.
|
||||
string_bytes: []const u8 = &.{},
|
||||
dump_writer: ?*std.Io.Writer = null,
|
||||
internal_counter: usize = 0,
|
||||
|
||||
pub const default_knot_name: [:0]const u8 = "$__main__$";
|
||||
|
||||
|
|
@ -372,23 +373,23 @@ pub fn deinit(story: *Story) void {
|
|||
story.* = undefined;
|
||||
}
|
||||
|
||||
fn currentFrame(vm: *Story) *CallFrame {
|
||||
pub fn currentFrame(vm: *Story) *CallFrame {
|
||||
assert(vm.call_stack_top > 0);
|
||||
return &vm.call_stack[vm.call_stack_top - 1];
|
||||
}
|
||||
|
||||
fn peekStack(vm: *Story, offset: usize) ?Value {
|
||||
pub fn peekStack(vm: *Story, offset: usize) ?Value {
|
||||
if (vm.stack_top <= offset) return null;
|
||||
return vm.stack[vm.stack_top - offset - 1];
|
||||
}
|
||||
|
||||
fn pushStack(vm: *Story, value: Value) !void {
|
||||
pub fn pushStack(vm: *Story, value: Value) !void {
|
||||
if (vm.stack_top >= vm.stack.len) return error.StackOverflow;
|
||||
vm.stack[vm.stack_top] = value;
|
||||
vm.stack_top += 1;
|
||||
}
|
||||
|
||||
fn popStack(vm: *Story) ?Value {
|
||||
pub fn popStack(vm: *Story) ?Value {
|
||||
if (vm.stack_top == 0) return null;
|
||||
|
||||
const stack_top = vm.stack_top;
|
||||
|
|
@ -489,7 +490,7 @@ fn divertValue(vm: *Story, value: Value, args_count: u8) !void {
|
|||
}
|
||||
|
||||
// Diverts are essentially tail calls.
|
||||
fn divert(vm: *Story, knot: *Object.Knot, args_count: u8) !void {
|
||||
pub fn divert(vm: *Story, knot: *Object.Knot, args_count: u8) !void {
|
||||
assert(knot.code.args_count == args_count);
|
||||
if (vm.call_stack_top == 0)
|
||||
return vm.call(knot, args_count);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue