-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forth3): return interpreter actions from builtins
This branch changes the `forth3` API to prepare for Forth-driven IO. In particular, builtin words and VM execution steps are changed from returning a `Ok(())` branch when the builtin/execution step succeeds to returning a new `InterpretAction` type in the `Ok` branch, which determines what action the host should perform next. `InterpretAction` is an enum which currently has three variants: - `InterpretAction::Done`, which has the same semantics that returning `Ok(())` currently has: if returned from a builtin, it indicates that the VM should pop the current callstack frame and keep executing, and if returned by the VM to the host, it indicates that the VM's callstack is empty. - `InterpretAction::Continue`, which replaces the `Error::PendingCallAgain` variant (it seemed more morally correct for this to be an `Ok` return rather than an `Err`), and indicates that the VM should continue executing what's currently on the stack when returned from a builtin - `InterpretAction::AcceptInput`, which indicates that the VM needs to wait for the host to fill its input buffer. In the future, `InterpretAction::AcceptInput` will be used to provide an improved abstraction for communicating to the host that the VM is requesting IO. We may also add a variant indicating that the VM needs the host to drain its output buffer. When we add implementations of Forth words such as `quit`, which fill the input buffer, they will return the `AcceptInput` variant, allowing us to request IO from builtins provided by `forth3` without requiring them to actually *do* the IO. This lets us avoid making the entire VM generic over some `Read` and `Write` traits (or `AsyncRead`/`AsyncWrite` traits), which don't exist in no-std, by temporarily breaking out of a VM's run loop and returning to the host when I/O is needed.
- Loading branch information
Showing
9 changed files
with
248 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.