Add function yielding and resuming
Sometimes, a builtin function may need to call out to another function (user-defined or otherwise). Previously, we were just calling the function and popping the stack frame, leaving no room for the new function to be called. This introduces a `FunctionResult` and `FunctionState` that get passed between these builtin functions. A builtin function will receive a FunctionState that tells it whether it is currently beginning or being resumed and can act accordingly. A builtin function will in turn return a FunctionResult, which can either be to return and push a value to the stack, return without pushing a value (value is already on top of the stack), or yield execution back to the VM (implying that a new stack frame has been pushed with a new function to execute). Having to call a new function and resume is a bit unwieldy and un-ergonomic, and making a macro to help write these would be nice, but it looks like a procedural macro may be required to really enable this. For now, we will write these yields by hand and once it becomes truly too much, we can start looking at writing a macro library to handle this case. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -99,6 +99,11 @@ fn disassemble_chunk(chunk: &Chunk, constants: &Vec<ObjP>, globals: &Vec<String>
|
||||
arg = format!("{depth}");
|
||||
info = format!("slot {slot} (name unknown)");
|
||||
}
|
||||
Op::Nop => {
|
||||
op_str = "NOP";
|
||||
arg = String::new();
|
||||
info = String::new();
|
||||
}
|
||||
Op::Halt => {
|
||||
op_str = "HALT";
|
||||
arg = String::new();
|
||||
|
||||
Reference in New Issue
Block a user