Struct forth3::vm::Forth

source ·
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>]
Available on crate feature async only.

Implementations§

source§

impl<T: 'static> Forth<T>

source

pub fn float_div_mod(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_div(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_modu(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_pop_print(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_add(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_mul(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_abs(&mut self) -> Result<(), Error>

Available on crate features floats and use-std only.
source

pub fn float_negate(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_min(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_max(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source

pub fn float_minus(&mut self) -> Result<(), Error>

Available on crate feature floats only.
source§

impl<T: 'static> Forth<T>

source

pub const FULL_BUILTINS: &'static [BuiltinEntry<T>] = _

source

pub fn panic(&mut self) -> Result<(), Error>

Dumps all stacks and ends the currently executing program

source

pub fn dict_free(&mut self) -> Result<(), Error>

source

pub fn list_stack(&mut self) -> Result<(), Error>

source

pub fn list_builtins(&mut self) -> Result<(), Error>

source

pub fn list_dict(&mut self) -> Result<(), Error>

source

pub fn word_add(&mut self) -> Result<(), Error>

source

pub fn byte_var_load(&mut self) -> Result<(), Error>

source

pub fn byte_var_store(&mut self) -> Result<(), Error>

source

pub fn var_load(&mut self) -> Result<(), Error>

source

pub fn var_store(&mut self) -> Result<(), Error>

source

pub fn zero_const(&mut self) -> Result<(), Error>

source

pub fn one_const(&mut self) -> Result<(), Error>

source

pub fn constant(&mut self) -> Result<(), Error>

source

pub fn variable(&mut self) -> Result<(), Error>

source

pub fn forget(&mut self) -> Result<(), Error>

source

pub fn over(&mut self) -> Result<(), Error>

source

pub fn over_2(&mut self) -> Result<(), Error>

source

pub fn rot(&mut self) -> Result<(), Error>

source

pub fn ds_drop(&mut self) -> Result<(), Error>

source

pub fn ds_drop_2(&mut self) -> Result<(), Error>

source

pub fn swap(&mut self) -> Result<(), Error>

source

pub fn swap_2(&mut self) -> Result<(), Error>

source

pub fn space(&mut self) -> Result<(), Error>

source

pub fn spaces(&mut self) -> Result<(), Error>

source

pub fn cr(&mut self) -> Result<(), Error>

source

fn skip_literal(&mut self) -> Result<(), Error>

source

pub fn invert(&mut self) -> Result<(), Error>

source

pub fn and(&mut self) -> Result<(), Error>

source

pub fn equal(&mut self) -> Result<(), Error>

source

pub fn greater(&mut self) -> Result<(), Error>

source

pub fn less(&mut self) -> Result<(), Error>

source

pub fn zero_equal(&mut self) -> Result<(), Error>

source

pub fn zero_greater(&mut self) -> Result<(), Error>

source

pub fn zero_less(&mut self) -> Result<(), Error>

source

pub fn div_mod(&mut self) -> Result<(), Error>

source

pub fn div(&mut self) -> Result<(), Error>

source

pub fn modu(&mut self) -> Result<(), Error>

source

pub fn loop_i(&mut self) -> Result<(), Error>

source

pub fn loop_itick(&mut self) -> Result<(), Error>

source

pub fn loop_j(&mut self) -> Result<(), Error>

source

pub fn loop_leave(&mut self) -> Result<(), Error>

source

pub fn jump_doloop(&mut self) -> Result<(), Error>

source

pub fn emit(&mut self) -> Result<(), Error>

source

pub fn jump_if_zero(&mut self) -> Result<(), Error>

source

pub fn jump(&mut self) -> Result<(), Error>

source

pub fn dup(&mut self) -> Result<(), Error>

source

pub fn dup_2(&mut self) -> Result<(), Error>

source

pub fn return_to_data_stack(&mut self) -> Result<(), Error>

source

pub fn data_to_return_stack(&mut self) -> Result<(), Error>

source

pub fn data2_to_return2_stack(&mut self) -> Result<(), Error>

source

pub fn pop_print(&mut self) -> Result<(), Error>

source

pub fn unsigned_pop_print(&mut self) -> Result<(), Error>

source

pub fn add(&mut self) -> Result<(), Error>

§Add (+)
> 1 2 +
> .
< 3 ok.
source

pub fn mul(&mut self) -> Result<(), Error>

source

pub fn abs(&mut self) -> Result<(), Error>

source

pub fn negate(&mut self) -> Result<(), Error>

source

pub fn min(&mut self) -> Result<(), Error>

source

pub fn max(&mut self) -> Result<(), Error>

source

pub fn minus(&mut self) -> Result<(), Error>

source

pub fn star_slash(&mut self) -> Result<(), Error>

source

pub fn star_slash_mod(&mut self) -> Result<(), Error>

source

pub fn colon(&mut self) -> Result<(), Error>

source

pub fn write_str_lit(&mut self) -> Result<(), Error>

source

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

source

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.

source

pub fn addr_of(&mut self) -> Result<(), Error>

Looks up a name in the dictionary and places its address on the stack.

source

pub fn execute(&mut self) -> Result<(), Error>

source§

impl<T> Forth<T>

source

pub unsafe fn new( bufs: Buffers<T>, dict: OwnedDict<T>, host_ctxt: T, builtins: &'static [BuiltinEntry<T>], ) -> Result<Self, Error>

source

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>

Available on crate feature 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.

source

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 OwnedDicts 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.

source

pub fn add_builtin_static_name( &mut self, name: &'static str, bi: fn(_: &mut Forth<T>) -> Result<(), Error>, ) -> Result<(), Error>

source

pub fn add_builtin( &mut self, name: &str, bi: fn(_: &mut Forth<T>) -> Result<(), Error>, ) -> Result<(), Error>

source

fn parse_num(word: &str) -> Option<i32>

source

fn find_word(&self, word: &str) -> Option<NonNull<EntryHeader<T>>>

source

fn find_in_async_bis( &self, fastr: &TmpFaStr<'_>, ) -> Option<NonNull<AsyncBuiltinEntry<T>>>

Available on crate feature async only.
source

fn find_in_bis(&self, fastr: &TmpFaStr<'_>) -> Option<NonNull<BuiltinEntry<T>>>

source

fn find_in_dict(&self, fastr: &TmpFaStr<'_>) -> Option<DictLocation<T>>

source

pub fn lookup(&self, word: &str) -> Result<Lookup<T>, Error>

source

pub fn process_line(&mut self) -> Result<(), Error>

source

fn start_processing_line(&mut self) -> Result<ProcessAction, Error>

Returns true if we must call steppa_pig until it returns Ready, false if not.

source

fn steppa_pig(&mut self) -> Result<Step, Error>

source

pub fn interpret(&mut self) -> Result<(), Error>

Interpret is the run-time target of the : (colon) word.

source

fn munch_do(&mut self, len: &mut u16) -> Result<u16, Error>

source

fn munch_if(&mut self, len: &mut u16) -> Result<u16, Error>

source

fn munch_one(&mut self, len: &mut u16) -> Result<u16, Error>

source

pub fn release(self) -> T

source

fn munch_comment(&mut self, _len: &mut u16) -> Result<u16, Error>

source

fn munch_str(&mut self, len: &mut u16) -> Result<u16, Error>

source

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.

source

fn munch_constant(&mut self, _len: &mut u16) -> Result<u16, Error>

source

fn munch_variable(&mut self, _len: &mut u16) -> Result<u16, Error>

source

fn munch_array(&mut self, _len: &mut u16) -> Result<u16, Error>

Trait Implementations§

source§

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.

source§

impl<T: Sync> Sync for Forth<T>

Auto Trait Implementations§

§

impl<T> Freeze for Forth<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Forth<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Forth<T>
where T: Unpin,

§

impl<T> UnwindSafe for Forth<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.