pub struct Forth<T: 'static> {
mode: Mode,
pub data_stack: Stack<Word>,
pub(crate) return_stack: Stack<Word>,
pub(crate) call_stack: Stack<CallContext<T>>,
pub(crate) dict: OwnedDict<T>,
pub input: WordStrBuf,
pub output: OutputBuf,
pub host_ctxt: T,
builtins: &'static [BuiltinEntry<T>],
async_builtins: &'static [AsyncBuiltinEntry<T>],
}
Expand description
Forth is the “context” of the VM/interpreter.
Fields§
§mode: Mode
§data_stack: Stack<Word>
§return_stack: Stack<Word>
§call_stack: Stack<CallContext<T>>
§dict: OwnedDict<T>
§input: WordStrBuf
§output: OutputBuf
§host_ctxt: T
§builtins: &'static [BuiltinEntry<T>]
§async_builtins: &'static [AsyncBuiltinEntry<T>]
async
only.Implementations§
source§impl<T: 'static> Forth<T>
impl<T: 'static> Forth<T>
pub fn float_div_mod(&mut self) -> Result<(), Error>
floats
only.pub fn float_div(&mut self) -> Result<(), Error>
floats
only.pub fn float_modu(&mut self) -> Result<(), Error>
floats
only.pub fn float_pop_print(&mut self) -> Result<(), Error>
floats
only.pub fn float_add(&mut self) -> Result<(), Error>
floats
only.pub fn float_mul(&mut self) -> Result<(), Error>
floats
only.pub fn float_abs(&mut self) -> Result<(), Error>
floats
and use-std
only.pub fn float_negate(&mut self) -> Result<(), Error>
floats
only.pub fn float_min(&mut self) -> Result<(), Error>
floats
only.pub fn float_max(&mut self) -> Result<(), Error>
floats
only.pub fn float_minus(&mut self) -> Result<(), Error>
floats
only.source§impl<T: 'static> Forth<T>
impl<T: 'static> Forth<T>
pub const FULL_BUILTINS: &'static [BuiltinEntry<T>] = _
sourcepub fn panic(&mut self) -> Result<(), Error>
pub fn panic(&mut self) -> Result<(), Error>
Dumps all stacks and ends the currently executing program
pub fn dict_free(&mut self) -> Result<(), Error>
pub fn list_stack(&mut self) -> Result<(), Error>
pub fn list_builtins(&mut self) -> Result<(), Error>
pub fn list_dict(&mut self) -> Result<(), Error>
pub fn word_add(&mut self) -> Result<(), Error>
pub fn byte_var_load(&mut self) -> Result<(), Error>
pub fn byte_var_store(&mut self) -> Result<(), Error>
pub fn var_load(&mut self) -> Result<(), Error>
pub fn var_store(&mut self) -> Result<(), Error>
pub fn zero_const(&mut self) -> Result<(), Error>
pub fn one_const(&mut self) -> Result<(), Error>
pub fn constant(&mut self) -> Result<(), Error>
pub fn variable(&mut self) -> Result<(), Error>
pub fn forget(&mut self) -> Result<(), Error>
pub fn over(&mut self) -> Result<(), Error>
pub fn over_2(&mut self) -> Result<(), Error>
pub fn rot(&mut self) -> Result<(), Error>
pub fn ds_drop(&mut self) -> Result<(), Error>
pub fn ds_drop_2(&mut self) -> Result<(), Error>
pub fn swap(&mut self) -> Result<(), Error>
pub fn swap_2(&mut self) -> Result<(), Error>
pub fn space(&mut self) -> Result<(), Error>
pub fn spaces(&mut self) -> Result<(), Error>
pub fn cr(&mut self) -> Result<(), Error>
fn skip_literal(&mut self) -> Result<(), Error>
pub fn invert(&mut self) -> Result<(), Error>
pub fn and(&mut self) -> Result<(), Error>
pub fn equal(&mut self) -> Result<(), Error>
pub fn greater(&mut self) -> Result<(), Error>
pub fn less(&mut self) -> Result<(), Error>
pub fn zero_equal(&mut self) -> Result<(), Error>
pub fn zero_greater(&mut self) -> Result<(), Error>
pub fn zero_less(&mut self) -> Result<(), Error>
pub fn div_mod(&mut self) -> Result<(), Error>
pub fn div(&mut self) -> Result<(), Error>
pub fn modu(&mut self) -> Result<(), Error>
pub fn loop_i(&mut self) -> Result<(), Error>
pub fn loop_itick(&mut self) -> Result<(), Error>
pub fn loop_j(&mut self) -> Result<(), Error>
pub fn loop_leave(&mut self) -> Result<(), Error>
pub fn jump_doloop(&mut self) -> Result<(), Error>
pub fn emit(&mut self) -> Result<(), Error>
pub fn jump_if_zero(&mut self) -> Result<(), Error>
pub fn jump(&mut self) -> Result<(), Error>
pub fn dup(&mut self) -> Result<(), Error>
pub fn dup_2(&mut self) -> Result<(), Error>
pub fn return_to_data_stack(&mut self) -> Result<(), Error>
pub fn data_to_return_stack(&mut self) -> Result<(), Error>
pub fn data2_to_return2_stack(&mut self) -> Result<(), Error>
pub fn pop_print(&mut self) -> Result<(), Error>
pub fn unsigned_pop_print(&mut self) -> Result<(), Error>
pub fn mul(&mut self) -> Result<(), Error>
pub fn abs(&mut self) -> Result<(), Error>
pub fn negate(&mut self) -> Result<(), Error>
pub fn min(&mut self) -> Result<(), Error>
pub fn max(&mut self) -> Result<(), Error>
pub fn minus(&mut self) -> Result<(), Error>
pub fn star_slash(&mut self) -> Result<(), Error>
pub fn star_slash_mod(&mut self) -> Result<(), Error>
pub fn colon(&mut self) -> Result<(), Error>
pub fn write_str_lit(&mut self) -> Result<(), Error>
sourcepub fn rliteral(&mut self) -> Result<(), Error>
pub fn rliteral(&mut self) -> Result<(), Error>
(rliteral)
is used mid-interpret to put the NEXT word of the parent’s
CFA into the return stack as a value
sourcepub fn literal(&mut self) -> Result<(), Error>
pub fn literal(&mut self) -> Result<(), Error>
(literal)
is used mid-interpret to put the NEXT word of the parent’s
CFA array into the stack as a value.
sourcepub fn addr_of(&mut self) -> Result<(), Error>
pub fn addr_of(&mut self) -> Result<(), Error>
Looks up a name in the dictionary and places its address on the stack.
pub fn execute(&mut self) -> Result<(), Error>
source§impl<T> Forth<T>
impl<T> Forth<T>
pub unsafe fn new( bufs: Buffers<T>, dict: OwnedDict<T>, host_ctxt: T, builtins: &'static [BuiltinEntry<T>], ) -> Result<Self, Error>
sourceunsafe fn new_async(
bufs: Buffers<T>,
dict: OwnedDict<T>,
host_ctxt: T,
builtins: &'static [BuiltinEntry<T>],
async_builtins: &'static [AsyncBuiltinEntry<T>],
) -> Result<Self, Error>
Available on crate feature async
only.
unsafe fn new_async( bufs: Buffers<T>, dict: OwnedDict<T>, host_ctxt: T, builtins: &'static [BuiltinEntry<T>], async_builtins: &'static [AsyncBuiltinEntry<T>], ) -> Result<Self, Error>
async
only.Pushes a task to the back of the local queue, skipping the LIFO slot, and overflowing onto the injection queue if the local queue is full.
sourcepub unsafe fn fork(
&mut self,
bufs: Buffers<T>,
new_dict: OwnedDict<T>,
my_dict: OwnedDict<T>,
host_ctxt: T,
) -> Result<Self, Error>
pub unsafe fn fork( &mut self, bufs: Buffers<T>, new_dict: OwnedDict<T>, my_dict: OwnedDict<T>, host_ctxt: T, ) -> Result<Self, Error>
Constructs a new VM whose dictionary is a fork of this VM’s dictionary.
The current dictionary owned by this VM is frozen (made immutable), and a reference to it is shared with this VM and the new child VM. When both this VM and the child are dropped, the frozen dictionary is deallocated.
This function takes two OwnedDict
s as arguments: new_dict
is the
dictionary allocation for the forked child VM, while my_dict
is a new
allocation for this VM’s mutable dictionary (which replaces the current
dictionary, as it will become frozen).
The child VM is created with empty stacks, and the provided input and output buffers.
§Safety
This method requires the same invariants be upheld as Forth::new
.
pub fn add_builtin_static_name( &mut self, name: &'static str, bi: fn(_: &mut Forth<T>) -> Result<(), Error>, ) -> Result<(), Error>
pub fn add_builtin( &mut self, name: &str, bi: fn(_: &mut Forth<T>) -> Result<(), Error>, ) -> Result<(), Error>
fn parse_num(word: &str) -> Option<i32>
fn find_word(&self, word: &str) -> Option<NonNull<EntryHeader<T>>>
fn find_in_async_bis( &self, fastr: &TmpFaStr<'_>, ) -> Option<NonNull<AsyncBuiltinEntry<T>>>
async
only.fn find_in_bis(&self, fastr: &TmpFaStr<'_>) -> Option<NonNull<BuiltinEntry<T>>>
fn find_in_dict(&self, fastr: &TmpFaStr<'_>) -> Option<DictLocation<T>>
pub fn lookup(&self, word: &str) -> Result<Lookup<T>, Error>
pub fn process_line(&mut self) -> Result<(), Error>
sourcefn start_processing_line(&mut self) -> Result<ProcessAction, Error>
fn start_processing_line(&mut self) -> Result<ProcessAction, Error>
Returns true
if we must call steppa_pig
until it returns Ready
,
false if not.
fn steppa_pig(&mut self) -> Result<Step, Error>
sourcepub fn interpret(&mut self) -> Result<(), Error>
pub fn interpret(&mut self) -> Result<(), Error>
Interpret is the run-time target of the :
(colon) word.
fn munch_do(&mut self, len: &mut u16) -> Result<u16, Error>
fn munch_if(&mut self, len: &mut u16) -> Result<u16, Error>
fn munch_one(&mut self, len: &mut u16) -> Result<u16, Error>
pub fn release(self) -> T
fn munch_comment(&mut self, _len: &mut u16) -> Result<u16, Error>
fn munch_str(&mut self, len: &mut u16) -> Result<u16, Error>
sourcefn munch_name(&mut self) -> Result<FaStr, Error>
fn munch_name(&mut self) -> Result<FaStr, Error>
Take the next token off of the input buffer as a name, and allocate the name in the dictionary.
fn munch_constant(&mut self, _len: &mut u16) -> Result<u16, Error>
fn munch_variable(&mut self, _len: &mut u16) -> Result<u16, Error>
fn munch_array(&mut self, _len: &mut u16) -> Result<u16, Error>
Trait Implementations§
impl<T: Send> Send for Forth<T>
§Safety
A Forth
VM contains raw pointers. However, these raw pointers point into
regions which are exclusively owned by the Forth
VM, and they are only
mutably dereferenced by methods which take ownership over the Forth VM. The
Constructing a new VM via Forth::new
is unsafe, as the caller is
responsible for ensuring that the pointed memory regions are exclusively
owned by the Forth
VM and that they live at least as long as the VM does,
but as long as those invariants are upheld, the VM may be shared across
thread boundaries.