Trait Core

Source
pub trait Core: Sized {
Show 222 methods // Required methods fn last_error(&self) -> Option<Exception>; fn set_error(&mut self, e: Option<Exception>); fn handler(&self) -> usize; fn set_handler(&mut self, h: usize); fn data_space(&mut self) -> &mut DataSpace; fn data_space_const(&self) -> &DataSpace; fn hold_buffer(&mut self) -> &mut String; fn output_buffer(&mut self) -> &mut Option<String>; fn set_output_buffer(&mut self, buffer: String); fn source_id(&self) -> isize; fn input_buffer(&mut self) -> &mut Option<String>; fn set_input_buffer(&mut self, buffer: String); fn files(&self) -> &Vec<Option<File>>; fn files_mut(&mut self) -> &mut Vec<Option<File>>; fn sources(&self) -> &Vec<Option<Source>>; fn sources_mut(&mut self) -> &mut Vec<Option<Source>>; fn lines(&self) -> &Vec<Option<String>>; fn lines_mut(&mut self) -> &mut Vec<Option<String>>; fn last_token(&mut self) -> &mut Option<String>; fn set_last_token(&mut self, buffer: String); fn s_stack(&mut self) -> &mut Stack<isize>; fn r_stack(&mut self) -> &mut Stack<isize>; fn c_stack(&mut self) -> &mut Stack<Control>; fn f_stack(&mut self) -> &mut Stack<f64>; fn wordlist_mut(&mut self) -> &mut Wordlist<Self>; fn wordlist(&self) -> &Wordlist<Self>; fn state(&mut self) -> &mut State; fn references(&mut self) -> &mut ForwardReferences; fn system_time_ns(&self) -> u64; fn current_task(&self) -> usize; fn set_current_task(&mut self, i: usize); fn awake(&self, i: usize) -> bool; fn set_awake(&mut self, i: usize, v: bool); fn forward_bitset(&self) -> &BitSet; fn forward_bitset_mut(&mut self) -> &mut BitSet; fn resolved_bitset(&self) -> &BitSet; fn resolved_bitset_mut(&mut self) -> &mut BitSet; fn labels(&self) -> &Vec<usize>; fn labels_mut(&mut self) -> &mut Vec<usize>; // Provided methods fn add_core(&mut self) { ... } fn add_primitive(&mut self, name: &str, action: fn(&mut Self)) { ... } fn immediate(&mut self) { ... } fn add_immediate(&mut self, name: &str, action: fn(&mut Self)) { ... } fn compile_only(&mut self) { ... } fn add_compile_only(&mut self, name: &str, action: fn(&mut Self)) { ... } fn add_immediate_and_compile_only( &mut self, name: &str, action: fn(&mut Self), ) { ... } fn execute_word(&mut self, i: usize) { ... } fn find(&mut self, name: &str) -> Option<usize> { ... } fn run(&mut self) { ... } fn forth(&mut self) -> bool { ... } fn compile_word(&mut self, word_index: usize) { ... } fn compile_nest(&mut self, word_index: usize) { ... } fn compile_nest_code(&mut self, _: usize) { ... } fn compile_var(&mut self, word_index: usize) { ... } fn compile_const(&mut self, word_index: usize) { ... } fn compile_unmark(&mut self, word_index: usize) { ... } fn compile_fconst(&mut self, word_index: usize) { ... } fn lit(&mut self) { ... } fn compile_integer(&mut self, i: isize) { ... } fn flit(&mut self) { ... } fn compile_float(&mut self, f: f64) { ... } fn p_s_quote(&mut self) { ... } fn patch_compilation_semanticses(&mut self) { ... } fn branch(&mut self) { ... } fn compile_branch(&mut self, destination: usize) -> usize { ... } fn zero_branch(&mut self) { ... } fn compile_zero_branch(&mut self, destination: usize) -> usize { ... } fn _do(&mut self) { ... } fn _qdo(&mut self) { ... } fn _loop(&mut self) { ... } fn _plus_loop(&mut self) { ... } fn unloop(&mut self) { ... } fn leave(&mut self) { ... } fn compile_leave(&mut self, word_idx: usize) { ... } fn p_j(&mut self) { ... } fn leave_part(&mut self) -> Option<usize> { ... } fn imm_if(&mut self) { ... } fn imm_else(&mut self) { ... } fn imm_then(&mut self) { ... } fn imm_case(&mut self) { ... } fn imm_of(&mut self) { ... } fn imm_endof(&mut self) { ... } fn imm_endcase(&mut self) { ... } fn imm_begin(&mut self) { ... } fn imm_while(&mut self) { ... } fn imm_repeat(&mut self) { ... } fn imm_until(&mut self) { ... } fn imm_again(&mut self) { ... } fn imm_clear_labels(&mut self) { ... } fn imm_label(&mut self) { ... } fn imm_goto(&mut self) { ... } fn imm_call(&mut self) { ... } fn imm_do(&mut self) { ... } fn imm_recurse(&mut self) { ... } fn imm_qdo(&mut self) { ... } fn imm_loop(&mut self) { ... } fn imm_plus_loop(&mut self) { ... } fn activate(&mut self) { ... } fn p_i(&mut self) { ... } fn left_bracket(&mut self) { ... } fn right_bracket(&mut self) { ... } fn set_source(&mut self, s: &str) { ... } fn push_source(&mut self, s: &str) { ... } fn parse_word(&mut self) { ... } fn char(&mut self) { ... } fn bracket_char(&mut self) { ... } fn parse(&mut self) { ... } fn _skip(&mut self) { ... } fn imm_paren(&mut self) { ... } fn imm_backslash(&mut self) { ... } fn postpone(&mut self) { ... } fn _postpone(&mut self) { ... } fn compile_token(&mut self) { ... } fn interpret_token(&mut self) { ... } fn p_compiling(&mut self) { ... } fn token_empty(&mut self) { ... } fn dot_token(&mut self) { ... } fn store_token(&mut self) { ... } fn evaluate_input(&mut self) { ... } fn base(&mut self) { ... } fn evaluate_integer(&mut self, token: &str) { ... } fn evaluate_float(&mut self, token: &str) { ... } fn nest(&mut self) { ... } fn p_var(&mut self) { ... } fn p_const(&mut self) { ... } fn define( &mut self, action: fn(&mut Self), compilation_semantics: fn(&mut Self, usize), ) { ... } fn colon(&mut self) { ... } fn semicolon(&mut self) { ... } fn create(&mut self) { ... } fn constant(&mut self) { ... } fn unmark(&mut self) { ... } fn marker(&mut self) { ... } fn does(&mut self) { ... } fn xdoes(&mut self) { ... } fn _does(&mut self) { ... } fn noop(&mut self) { ... } fn p_true(&mut self) { ... } fn p_false(&mut self) { ... } fn char_plus(&mut self) { ... } fn cell_plus(&mut self) { ... } fn cells(&mut self) { ... } fn swap(&mut self) { ... } fn dup(&mut self) { ... } fn p_drop(&mut self) { ... } fn pop_s_stack(&mut self) -> isize { ... } fn nip(&mut self) { ... } fn over(&mut self) { ... } fn rot(&mut self) { ... } fn minus_rot(&mut self) { ... } fn pick(&mut self) { ... } fn two_drop(&mut self) { ... } fn two_dup(&mut self) { ... } fn two_swap(&mut self) { ... } fn two_over(&mut self) { ... } fn depth(&mut self) { ... } fn one_plus(&mut self) { ... } fn one_minus(&mut self) { ... } fn plus(&mut self) { ... } fn minus(&mut self) { ... } fn star(&mut self) { ... } fn slash(&mut self) { ... } fn p_mod(&mut self) { ... } fn slash_mod(&mut self) { ... } fn abs(&mut self) { ... } fn negate(&mut self) { ... } fn zero_less(&mut self) { ... } fn zero_equals(&mut self) { ... } fn zero_greater(&mut self) { ... } fn zero_not_equals(&mut self) { ... } fn equals(&mut self) { ... } fn less_than(&mut self) { ... } fn greater_than(&mut self) { ... } fn not_equals(&mut self) { ... } fn within(&mut self) { ... } fn invert(&mut self) { ... } fn and(&mut self) { ... } fn or(&mut self) { ... } fn xor(&mut self) { ... } fn lshift(&mut self) { ... } fn rshift(&mut self) { ... } fn exit(&mut self) { ... } fn bye(&mut self) { ... } fn fetch(&mut self) { ... } fn store(&mut self) { ... } fn c_fetch(&mut self) { ... } fn c_store(&mut self) { ... } fn p_move(&mut self) { ... } fn tick(&mut self) { ... } fn to_body(&mut self) { ... } fn to_name(&mut self) { ... } fn execute(&mut self) { ... } fn bracket_tick(&mut self) { ... } fn compile_comma(&mut self) { ... } fn here(&mut self) { ... } fn allot(&mut self) { ... } fn aligned(&mut self) { ... } fn align(&mut self) { ... } fn comma(&mut self) { ... } fn p_to_r(&mut self) { ... } fn r_from(&mut self) { ... } fn r_fetch(&mut self) { ... } fn two_to_r(&mut self) { ... } fn two_r_from(&mut self) { ... } fn two_r_fetch(&mut self) { ... } fn check_stacks(&mut self) { ... } fn handler_store(&mut self) { ... } fn error(&mut self) { ... } fn clear_error(&mut self) { ... } fn dot_error(&mut self) { ... } fn clear_stacks(&mut self) { ... } fn p_source_id(&mut self) { ... } fn p_set_source_id(&mut self) { ... } fn set_source_id(&mut self, id: isize) { ... } fn p_source_idx(&mut self) { ... } fn p_set_source_idx(&mut self) { ... } fn reset(&mut self) { ... } fn abort_with(&mut self, e: Exception) { ... } fn abort(&mut self) { ... } fn pause(&mut self) { ... } fn me(&mut self) { ... } fn suspend(&mut self) { ... } fn resume(&mut self) { ... }
}

Required Methods§

Source

fn last_error(&self) -> Option<Exception>

Source

fn set_error(&mut self, e: Option<Exception>)

Source

fn handler(&self) -> usize

Source

fn set_handler(&mut self, h: usize)

Source

fn data_space(&mut self) -> &mut DataSpace

Source

fn data_space_const(&self) -> &DataSpace

Source

fn hold_buffer(&mut self) -> &mut String

Numeric output buffer

Source

fn output_buffer(&mut self) -> &mut Option<String>

Get output_buffer.

Source

fn set_output_buffer(&mut self, buffer: String)

Set output_buffer to Some(buffer).

Source

fn source_id(&self) -> isize

Input source identifier

0: input from source at self.sources[source_id] and input buffer self.lines[source_id]`. = 0: input from the default user input buffer.

Source

fn input_buffer(&mut self) -> &mut Option<String>

Get input_buffer.

Source

fn set_input_buffer(&mut self, buffer: String)

Set input_buffer to Some(buffer).

Source

fn files(&self) -> &Vec<Option<File>>

Source

fn files_mut(&mut self) -> &mut Vec<Option<File>>

Source

fn sources(&self) -> &Vec<Option<Source>>

Source

fn sources_mut(&mut self) -> &mut Vec<Option<Source>>

Source

fn lines(&self) -> &Vec<Option<String>>

Source

fn lines_mut(&mut self) -> &mut Vec<Option<String>>

Source

fn last_token(&mut self) -> &mut Option<String>

Source

fn set_last_token(&mut self, buffer: String)

Source

fn s_stack(&mut self) -> &mut Stack<isize>

Source

fn r_stack(&mut self) -> &mut Stack<isize>

Source

fn c_stack(&mut self) -> &mut Stack<Control>

Source

fn f_stack(&mut self) -> &mut Stack<f64>

Source

fn wordlist_mut(&mut self) -> &mut Wordlist<Self>

Last definition, 0 if last define fails.

Source

fn wordlist(&self) -> &Wordlist<Self>

Source

fn state(&mut self) -> &mut State

Source

fn references(&mut self) -> &mut ForwardReferences

Source

fn system_time_ns(&self) -> u64

Source

fn current_task(&self) -> usize

Current task

Source

fn set_current_task(&mut self, i: usize)

Set curretn task.

No operation if there is no task i.

Source

fn awake(&self, i: usize) -> bool

Is task i awake?

False if there is no task i.

Source

fn set_awake(&mut self, i: usize, v: bool)

Set awake to v.

No operation if there is no task i.

Source

fn forward_bitset(&self) -> &BitSet

Bitset to check forward declaration of labels.

Source

fn forward_bitset_mut(&mut self) -> &mut BitSet

Mutable bitset to check forward declaration of labels.

Source

fn resolved_bitset(&self) -> &BitSet

Bitset to check resolved labels.

Source

fn resolved_bitset_mut(&mut self) -> &mut BitSet

Mutable bitset to check resolved labels.

Source

fn labels(&self) -> &Vec<usize>

Labels to support BASIC-like goto, label, call.

Source

fn labels_mut(&mut self) -> &mut Vec<usize>

Labels to support BASIC-like goto, label, call.

Provided Methods§

Source

fn add_core(&mut self)

Add core primitives to self.

Examples found in repository?
examples/vm.rs (line 111)
85    pub fn new(data_pages: usize) -> VM {
86        let mut labels = Vec::with_capacity(LABEL_COUNT as _);
87        labels.resize(LABEL_COUNT as _, 0);
88        let mut vm = VM {
89            current_task: 0,
90            tasks: [
91                // Only operator task has its own input buffer.
92                Task::new_terminal(),
93                Task::new_background(),
94                Task::new_background(),
95                Task::new_background(),
96                Task::new_background(),
97            ],
98            last_error: None,
99            handler: 0,
100            wordlist: Wordlist::with_capacity(1000),
101            data_space: DataSpace::new(data_pages),
102            tkn: Some(String::with_capacity(64)),
103            outbuf: Some(String::with_capacity(128)),
104            hldbuf: String::with_capacity(128),
105            references: ForwardReferences::new(),
106            now: Instant::now(),
107            forward_bitset: BitSet::with_capacity(LABEL_COUNT),
108            resolved_bitset: BitSet::with_capacity(LABEL_COUNT),
109            labels,
110        };
111        vm.add_core();
112        vm.add_output();
113        vm.add_tools();
114        vm.add_environment();
115        vm.add_facility();
116        vm.add_float();
117        vm.add_units();
118        vm.add_file_access();
119        vm.add_loader();
120
121        vm.load_core_fth();
122
123        vm
124    }
Source

fn add_primitive(&mut self, name: &str, action: fn(&mut Self))

Add a primitive word to word list.

Examples found in repository?
examples/multitask.rs (line 11)
9fn main() {
10    let mut vm = VM::new(0x100);
11    vm.add_primitive("bye", bye);
12
13    vm.set_source(
14        "
15        : stars   2 activate  5 0 do pause 42 emit flush-output loop  nod ;
16        : pluses   3 activate  5 0 do pause 43 emit flush-output loop  nod ;
17        : main   stars  pluses  1000 ms  bye ;
18    ",
19    );
20    vm.evaluate_input();
21    if vm.last_error().is_some() {
22        panic!("Error {:?} {:?}", vm.last_error().unwrap(), vm.last_token());
23    }
24    vm.flush_output();
25
26    let main = vm.find("main").unwrap();
27    vm.execute_word(main);
28    vm.run();
29}
Source

fn immediate(&mut self)

Set the last definition immediate.

Source

fn add_immediate(&mut self, name: &str, action: fn(&mut Self))

Add an immediate word to word list.

Source

fn compile_only(&mut self)

Set the last definition compile-only.

Source

fn add_compile_only(&mut self, name: &str, action: fn(&mut Self))

Add a compile-only word to word list.

Source

fn add_immediate_and_compile_only(&mut self, name: &str, action: fn(&mut Self))

Add an immediate and compile-only word to word list.

Source

fn execute_word(&mut self, i: usize)

Execute word at position i.

Examples found in repository?
examples/multitask.rs (line 27)
9fn main() {
10    let mut vm = VM::new(0x100);
11    vm.add_primitive("bye", bye);
12
13    vm.set_source(
14        "
15        : stars   2 activate  5 0 do pause 42 emit flush-output loop  nod ;
16        : pluses   3 activate  5 0 do pause 43 emit flush-output loop  nod ;
17        : main   stars  pluses  1000 ms  bye ;
18    ",
19    );
20    vm.evaluate_input();
21    if vm.last_error().is_some() {
22        panic!("Error {:?} {:?}", vm.last_error().unwrap(), vm.last_token());
23    }
24    vm.flush_output();
25
26    let main = vm.find("main").unwrap();
27    vm.execute_word(main);
28    vm.run();
29}
Source

fn find(&mut self, name: &str) -> Option<usize>

Find the word with name name. If not found returns zero.

Examples found in repository?
examples/multitask.rs (line 26)
9fn main() {
10    let mut vm = VM::new(0x100);
11    vm.add_primitive("bye", bye);
12
13    vm.set_source(
14        "
15        : stars   2 activate  5 0 do pause 42 emit flush-output loop  nod ;
16        : pluses   3 activate  5 0 do pause 43 emit flush-output loop  nod ;
17        : main   stars  pluses  1000 ms  bye ;
18    ",
19    );
20    vm.evaluate_input();
21    if vm.last_error().is_some() {
22        panic!("Error {:?} {:?}", vm.last_error().unwrap(), vm.last_token());
23    }
24    vm.flush_output();
25
26    let main = vm.find("main").unwrap();
27    vm.execute_word(main);
28    vm.run();
29}
Source

fn run(&mut self)

Evaluate a compiled program following self.state().instruction_pointer. Any exception causes termination of inner loop.

Examples found in repository?
examples/multitask.rs (line 28)
9fn main() {
10    let mut vm = VM::new(0x100);
11    vm.add_primitive("bye", bye);
12
13    vm.set_source(
14        "
15        : stars   2 activate  5 0 do pause 42 emit flush-output loop  nod ;
16        : pluses   3 activate  5 0 do pause 43 emit flush-output loop  nod ;
17        : main   stars  pluses  1000 ms  bye ;
18    ",
19    );
20    vm.evaluate_input();
21    if vm.last_error().is_some() {
22        panic!("Error {:?} {:?}", vm.last_error().unwrap(), vm.last_token());
23    }
24    vm.flush_output();
25
26    let main = vm.find("main").unwrap();
27    vm.execute_word(main);
28    vm.run();
29}
Source

fn forth(&mut self) -> bool

Source

fn compile_word(&mut self, word_index: usize)

Source

fn compile_nest(&mut self, word_index: usize)

Source

fn compile_nest_code(&mut self, _: usize)

Source

fn compile_var(&mut self, word_index: usize)

Source

fn compile_const(&mut self, word_index: usize)

Source

fn compile_unmark(&mut self, word_index: usize)

Source

fn compile_fconst(&mut self, word_index: usize)

Source

fn lit(&mut self)

Source

fn compile_integer(&mut self, i: isize)

Compile integer i.

Source

fn flit(&mut self)

Source

fn compile_float(&mut self, f: f64)

Compile float ‘f’.

Source

fn p_s_quote(&mut self)

Runtime of S“

Source

fn patch_compilation_semanticses(&mut self)

Source

fn branch(&mut self)

Source

fn compile_branch(&mut self, destination: usize) -> usize

Source

fn zero_branch(&mut self)

Source

fn compile_zero_branch(&mut self, destination: usize) -> usize

Source

fn _do(&mut self)

( n1|u1 n2|u2 – ) ( R: – loop-sys )

Set up loop control parameters with index n2|u2 and limit n1|u1. An ambiguous condition exists if n1|u1 and n2|u2 are not both the same type. Anything already on the return stack becomes unavailable until the loop-control parameters are discarded.

        +--------------------------+
        |                          |
        |                          v
+-----+-+-+-----------+-------+---+--
| _do | x | loop body | _loop | x |
+-----+---+-----------+-------+-+-+--
        ^
        |
        ip
Source

fn _qdo(&mut self)

( n1|u1 n2|u2 – ) ( R: – loop-sys )

If n1|u1 is equal to n2|u2, continue execution at the location given by the consumer of do-sys. Otherwise set up loop control parameters with index n2|u2 and limit n1|u1 and continue executing immediately following ?DO. Anything already on the return stack becomes unavailable until the loop control parameters are discarded. An ambiguous condition exists if n1|u1 and n2|u2 are not both of the same type.

         +--------------------------+
         |                          |
         |                          v
+------+-+-+-----------+-------+---+--
| _qdo | x | loop body | _loop | x |
+------+---+-----------+-------+-+-+--
         ^
         |
         ip
Source

fn _loop(&mut self)

Run-time: ( – ) ( R: loop-sys1 – | loop-sys2 )

An ambiguous condition exists if the loop control parameters are unavailable. Add one to the loop index. If the loop index is then equal to the loop limit, discard the loop parameters and continue execution immediately following the loop. Otherwise continue execution at the beginning of the loop.

Source

fn _plus_loop(&mut self)

Run-time: ( n – ) ( R: loop-sys1 – | loop-sys2 )

An ambiguous condition exists if the loop control parameters are unavailable. Add n to the loop index. If the loop index did not cross the boundary between the loop limit minus one and the loop limit, continue execution at the beginning of the loop. Otherwise, discard the current loop control parameters and continue execution immediately following the loop.

Source

fn unloop(&mut self)

Run-time: ( – ) ( R: loop-sys – )

Discard the loop-control parameters for the current nesting level. An UNLOOP is required for each nesting level before the definition may be EXITed. An ambiguous condition exists if the loop-control parameters are unavailable.

Source

fn leave(&mut self)

Source

fn compile_leave(&mut self, word_idx: usize)

Source

fn p_j(&mut self)

Source

fn leave_part(&mut self) -> Option<usize>

Source

fn imm_if(&mut self)

IF A THEN

        +------+
        |      |
        |      v
+-----+---+---+--
| _if | x | A |
+-----+---+---+--
        ^
        |
        ip
Source

fn imm_else(&mut self)

IF A ELSE B THEN

            +--------------------+
            |                    |
            |                    v
+---------+---+---+--------+---+---+--
| ?branch | x | A | branch | x | B |
+---------+---+---+--------+---+---+--
            ^                |       ^
            |                |       |
            ip               +-------+
Source

fn imm_then(&mut self)

Source

fn imm_case(&mut self)

n1 CASE
  n2 OF A ENDOF
  n3 OF B ENDOF
  C
ENDCASE
D

+-----+----+------+---+---------+---+------+---+--------+---+
| lit | n2 | over | = | 0branch | x | drop | A | branch | x |
+-----+----+------+---+---------+---+------+---+--------+---+
                                  |                       |
  +-------------------------------+                       +--------------+
  |                                                       |              |
  v                                                       |              v
+-----+----+------+---+---------+---+------+---+--------+---+---+------+---+
| lit | n3 | over | = | 0branch | x | drop | B | branch | x | C | drop | D |
+-----+----+------+---+---------+---+------+---+--------+---+---+------+---+
                                  |                           ^
                                  |                           |
                                  +---------------------------+
Source

fn imm_of(&mut self)

Source

fn imm_endof(&mut self)

Source

fn imm_endcase(&mut self)

Source

fn imm_begin(&mut self)

Begin a structure that is terminated by repeat, until, or again. begin ( -- ).

Source

fn imm_while(&mut self)

Begin the conditional part of a begin ... while ... repeat structure. while ( flag -- ).

If all bits of flag are zero, continue execution at the location following repeat.

begin A while B repeat C

               +--------------------+
               |                    |
               |                    v
+---+---------+---+---+--------+---+---+
| A | 0branch | x | B | branch | x | C |
+---+---------+---+---+--------+---+---+
  ^                              |
  |                              |
  +------------------------------+
Source

fn imm_repeat(&mut self)

Terminate a begin ... while ... repeat structure. repeat ( -- ).

Continue execution at the location following begin.

Source

fn imm_until(&mut self)

Terminate a begin ... until structure. until ( flag -- ).

If all bits of flag are zero, continue execution at the location following begin.

begin A until C

+---+---------+---+---+
| A | 0branch | x | C |
+---+---------+---+---+
  ^             |
  |             |
  +-------------+
Source

fn imm_again(&mut self)

Terminate a begin ... again structure. again ( -- ).

Continue execution at the location following begin.

begin A again C

+---+--------+---+---+
| A | branch | x | C |
+---+--------+---+---+
  ^            |
  |            |
  +------------+
Source

fn imm_clear_labels(&mut self)

Clear labels, 0labels ( -- )

Source

fn imm_label(&mut self)

Create a label n, label ( n -- )

Valid n: 0 < n < labels.capacity().

Source

fn imm_goto(&mut self)

goto ( n – )

Go to label n.

+--------+---------------------+-----+-------
| BRANCH | data ptr of label n | ... |  addr at label n
+--------+---------------------+-----+-------
            |                             ^
            +-----------------------------+

[ n ] goto ... [ n ] label ...
[ n ] label ... [ n ]  goto
Source

fn imm_call(&mut self)

call ( n – )

Call subroutine at label n.

+----+-----------------+----+------------+-------------------------+--+------+
| LIT | return_addr | >R |  BRANCH | data ptr of label n | ... | EXIT |
+----+-----------------+----+------------+-------------------------+--+------+
                      |                                                                                       ^
                      +-------------------------------------------------------+

Usage:

[ n ] call ... [ n ] label ... exit ...
[ n ] label .. exit ... [ n ] call ...
Source

fn imm_do(&mut self)

Execution: ( – a-ddr )

Append the run-time semantics of _do to the current definition. The semantics are incomplete until resolved by LOOP or +LOOP.

+-----+---+--
| _do | 0 |
+-----+---+--
           ^
           |
           ++-----+
            |     |
Control::Do(here, here)
Source

fn imm_recurse(&mut self)

Source

fn imm_qdo(&mut self)

Execution: ( – a-ddr )

Append the run-time semantics of _qdo to the current definition. The semantics are incomplete until resolved by LOOP or +LOOP.

+------+---+--
| _qdo | 0 |
+------+---+--
            ^
            |
            ++-----+
             |     |
Control::Do(here, here)
Source

fn imm_loop(&mut self)

Run-time: ( a-addr – )

Append the run-time semantics of _LOOP to the current definition. Resolve the destination of all unresolved occurrences of LEAVE between the location given by do-sys and the next location for a transfer of control, to execute the words following the LOOP.

For DO ... LOOP,

        +--------------------------+
        |                          |
        |                          v
+-----+-+-+-----------+-------+---+--
| _do | x | loop body | _loop | x |
+-----+---+-----------+-------+-+-+--
           ^                    |
           |                    |
           ++-------------------+
            |
Control::Do(do_part, _)

For ?DO ... LOOP,

         +--------------------------+
         |                          |
         |                          v
+------+-+-+-----------+-------+---+--
| _qdo | x | loop body | _loop | x |
+------+---+-----------+-------+-+-+--
            ^                    |
            |                    |
            +--------------------+
            |
Control::Do(do_part, _)
Source

fn imm_plus_loop(&mut self)

Run-time: ( a-addr – )

Append the run-time semantics of _+LOOP to the current definition. Resolve the destination of all unresolved occurrences of LEAVE between the location given by do-sys and the next location for a transfer of control, to execute the words following +LOOP.

Source

fn activate(&mut self)

Source

fn p_i(&mut self)

Source

fn left_bracket(&mut self)

Source

fn right_bracket(&mut self)

Source

fn set_source(&mut self, s: &str)

Copy content of s to input_buffer and set source_index to 0.

Examples found in repository?
examples/simple.rs (line 10)
8fn main() {
9    let vm = &mut VM::new(100);
10    vm.set_source("1 . flush-output");
11    vm.evaluate_input();
12    match vm.last_error() {
13        Some(e) => println!("{:?}", e),
14        None => {}
15    }
16}
More examples
Hide additional examples
examples/multitask.rs (lines 13-19)
9fn main() {
10    let mut vm = VM::new(0x100);
11    vm.add_primitive("bye", bye);
12
13    vm.set_source(
14        "
15        : stars   2 activate  5 0 do pause 42 emit flush-output loop  nod ;
16        : pluses   3 activate  5 0 do pause 43 emit flush-output loop  nod ;
17        : main   stars  pluses  1000 ms  bye ;
18    ",
19    );
20    vm.evaluate_input();
21    if vm.last_error().is_some() {
22        panic!("Error {:?} {:?}", vm.last_error().unwrap(), vm.last_token());
23    }
24    vm.flush_output();
25
26    let main = vm.find("main").unwrap();
27    vm.execute_word(main);
28    vm.run();
29}
Source

fn push_source(&mut self, s: &str)

Push content of s to input_buffer.

Source

fn parse_word(&mut self)

Run-time: ( “ccc” – )

Parse word delimited by white space, skipping leading white spaces.

Source

fn char(&mut self)

Run-time: ( “<spaces>name” – char)

Skip leading space delimiters. Parse name delimited by a space. Put the value of its first character onto the stack.

Source

fn bracket_char(&mut self)

Compilation: ( “<spaces>name” – )

Skip leading space delimiters. Parse name delimited by a space. Append the run-time semantics given below to the current definition.

Run-time: ( – char )

Place char, the value of the first character of name, on the stack.

Source

fn parse(&mut self)

Run-time: ( char “ccc<char>” – )

Parse ccc delimited by the delimiter char.

Source

fn _skip(&mut self)

Run-time: ( char “ccc” – )

Skip all of the delimiter char.

Source

fn imm_paren(&mut self)

Source

fn imm_backslash(&mut self)

Begin a comment that includes the entire remainder of the current line.

Source

fn postpone(&mut self)

postpone ( “name” – )

Skip leading space delimiters. Parse name delimited by a space. Find name. Append the compilation semantics of name to the current definition.

For example:

: does>   postpone _does  postpone exit ;

+------+-------------+-----------+------+------------+-----------+
| _lit | xt of _does | _postpone | _lit | xt of exit | _postpone |
+--------------------+-----------+------+------------+-----------+
Source

fn _postpone(&mut self)

_POSTPONE ( xt – )

Execute the compilation semantics of an xt on stack.

_POSTPONE is a hidden word which is only compiled by POSTPONE.

Source

fn compile_token(&mut self)

Source

fn interpret_token(&mut self)

Source

fn p_compiling(&mut self)

Source

fn token_empty(&mut self)

Is token empty? `token-empty? ( – f )

Source

fn dot_token(&mut self)

Print token. .token ( -- )

Source

fn store_token(&mut self)

Store token. `!token ( c-addr – )

Store token in counted string at c-addr.`

Source

fn evaluate_input(&mut self)

Examples found in repository?
examples/simple.rs (line 11)
8fn main() {
9    let vm = &mut VM::new(100);
10    vm.set_source("1 . flush-output");
11    vm.evaluate_input();
12    match vm.last_error() {
13        Some(e) => println!("{:?}", e),
14        None => {}
15    }
16}
More examples
Hide additional examples
examples/multitask.rs (line 20)
9fn main() {
10    let mut vm = VM::new(0x100);
11    vm.add_primitive("bye", bye);
12
13    vm.set_source(
14        "
15        : stars   2 activate  5 0 do pause 42 emit flush-output loop  nod ;
16        : pluses   3 activate  5 0 do pause 43 emit flush-output loop  nod ;
17        : main   stars  pluses  1000 ms  bye ;
18    ",
19    );
20    vm.evaluate_input();
21    if vm.last_error().is_some() {
22        panic!("Error {:?} {:?}", vm.last_error().unwrap(), vm.last_token());
23    }
24    vm.flush_output();
25
26    let main = vm.find("main").unwrap();
27    vm.execute_word(main);
28    vm.run();
29}
Source

fn base(&mut self)

Source

fn evaluate_integer(&mut self, token: &str)

Source

fn evaluate_float(&mut self, token: &str)

Evaluate float.

Source

fn nest(&mut self)

Source

fn p_var(&mut self)

Source

fn p_const(&mut self)

Source

fn define( &mut self, action: fn(&mut Self), compilation_semantics: fn(&mut Self, usize), )

Source

fn colon(&mut self)

Source

fn semicolon(&mut self)

Source

fn create(&mut self)

Source

fn constant(&mut self)

Source

fn unmark(&mut self)

Source

fn marker(&mut self)

Example:

marker -work

DFA of -work
+------+--------+
| last | b0-b63 |
+------+--------+
Source

fn does(&mut self)

Run time behavior of words created by createdoes>.

Token threaded version.

Example of does>

: 2constant   create , , does> 2@ ;
4 40 2constant range

2constant
+--------+---+---+-------+------+----+------+
| create | , | , | _does | exit | 2@ | exit |
+--------+---+---+-------+------+----+------+
                                  ^
range                             |
                                  |
  action                          |
  +-------+                       |
  | xdoes |                       |
  +-------+                       |
                                  |
  doer                            |
  +------+                        |
  | x    |------------------------+
  +------+

  dfa
  +---+----+
  | 4 | 40 |
  +---+----+
Source

fn xdoes(&mut self)

Source

fn _does(&mut self)

Run time behavior of does>.

Source

fn noop(&mut self)

Run-time: ( – )

No operation

Source

fn p_true(&mut self)

Run-time: ( – true )

Return a true flag, a single-cell value with all bits set.

Source

fn p_false(&mut self)

Run-time: ( – false )

Return a false flag.

Source

fn char_plus(&mut self)

Run-time: ( c-addr1 – c-addr2 )

Add the size in address units of a character to c-addr1, giving c-addr2.

Source

fn cell_plus(&mut self)

Run-time: ( a-addr1 – a-addr2 )

Add the size in address units of a cell to a-addr1, giving a-addr2.

Source

fn cells(&mut self)

Run-time: ( n1 – n2 )

n2 is the size in address units of n1 cells.

Source

fn swap(&mut self)

Source

fn dup(&mut self)

Source

fn p_drop(&mut self)

Source

fn pop_s_stack(&mut self) -> isize

Source

fn nip(&mut self)

Source

fn over(&mut self)

Source

fn rot(&mut self)

Source

fn minus_rot(&mut self)

Source

fn pick(&mut self)

Place a copy of the nth stack entry on top of the stack. pick ( ... n -- x )

0 pick is equivalent to dup.

Source

fn two_drop(&mut self)

Source

fn two_dup(&mut self)

Source

fn two_swap(&mut self)

Source

fn two_over(&mut self)

Source

fn depth(&mut self)

Source

fn one_plus(&mut self)

Source

fn one_minus(&mut self)

Source

fn plus(&mut self)

Source

fn minus(&mut self)

Source

fn star(&mut self)

Source

fn slash(&mut self)

Source

fn p_mod(&mut self)

Source

fn slash_mod(&mut self)

Source

fn abs(&mut self)

Source

fn negate(&mut self)

Source

fn zero_less(&mut self)

Source

fn zero_equals(&mut self)

Source

fn zero_greater(&mut self)

Source

fn zero_not_equals(&mut self)

Source

fn equals(&mut self)

Source

fn less_than(&mut self)

Source

fn greater_than(&mut self)

Source

fn not_equals(&mut self)

Source

fn within(&mut self)

within ( n1 n2 n3 – flag ) true if n2 <= n1 and n1 < n3.

Note: implmenetation incompatible with Forth 2012 standards when n2 > n3.

Source

fn invert(&mut self)

Source

fn and(&mut self)

Source

fn or(&mut self)

Source

fn xor(&mut self)

Source

fn lshift(&mut self)

Run-time: ( x1 u – x2 )

Perform a logical left shift of u bit-places on x1, giving x2. Put zeroes into the least significant bits vacated by the shift. An ambiguous condition exists if u is greater than or equal to the number of bits in a cell.

Source

fn rshift(&mut self)

Run-time: ( x1 u – x2 )

Perform a logical right shift of u bit-places on x1, giving x2. Put zeroes into the most significant bits vacated by the shift. An ambiguous condition exists if u is greater than or equal to the number of bits in a cell.

Source

fn exit(&mut self)

Interpretation: Interpretation semantics for this word are undefined.

Execution: ( – ) ( R: nest-sys – ) Return control to the calling definition specified by nest-sys. Before executing EXIT within a do-loop, a program shall discard the loop-control parameters by executing UNLOOP.

Source

fn bye(&mut self)

Execution: ( – )

Set the instruction pointer to zero in order to terminate inner interpreter.

Source

fn fetch(&mut self)

Run-time: ( a-addr – x )

x is the value stored at a-addr.

Source

fn store(&mut self)

Run-time: ( x a-addr – )

Store x at a-addr.

Source

fn c_fetch(&mut self)

Run-time: ( c-addr – char )

Fetch the character stored at c-addr. When the cell size is greater than character size, the unused high-order bits are all zeroes.

Source

fn c_store(&mut self)

Run-time: ( char c-addr – )

Store char at c-addr. When character size is smaller than cell size, only the number of low-order bits corresponding to character size are transferred.

Source

fn p_move(&mut self)

Run-time: ( addr1 addr2 u – )

If u is greater than zero, copy the contents of u consecutive address units at addr1 to the u consecutive address units at addr2. After MOVE completes, the u consecutive address units at addr2 contain exactly what the u consecutive address units at addr1 contained before the move.

Source

fn tick(&mut self)

Run-time: ( “name” – xt )

Skip leading space delimiters. Parse name delimited by a space. Find name and return xt, the execution token for name. An ambiguous condition exists if name is not found.

Source

fn to_body(&mut self)

( xt – a-addr ) a-addr is the data-field address corresponding to xt. An ambiguous condition exists if xt is not for a word defined via CREATE.

Source

fn to_name(&mut self)

( xt – a-addr ) a-addr is the name-field address corresponding to xt.

Source

fn execute(&mut self)

Run-time: ( ix xt – jx )

Remove xt from the stack and perform the semantics identified by it. Other stack effects are due to the word EXECUTEd.

Source

fn bracket_tick(&mut self)

Compilation: ( “name” – ) Run-time: ( – xt )

Forth 2012 6.1.2510

Source

fn compile_comma(&mut self)

Execution: ( xt – )

Forth 2012 6.2.0945 Append the execution semantics of the definition represented by xt to the execution semantics of the current definition.

Source

fn here(&mut self)

Run-time: ( – addr )

addr is the data-space pointer.

Source

fn allot(&mut self)

Run-time: ( n – )

If n is greater than zero, reserve n address units of data space. If n is less than zero, release |n| address units of data space. If n is zero, leave the data-space pointer unchanged.

Source

fn aligned(&mut self)

Run-time: ( addr – a-addr )

Return a-addr, the first aligned address greater than or equal to addr.

Source

fn align(&mut self)

Run-time: ( – )

If the data-space pointer is not aligned, reserve enough space to align it.

Source

fn comma(&mut self)

Run-time: ( x – )

Reserve one cell of data space and store x in the cell. If the data-space pointer is aligned when , begins execution, it will remain aligned when , finishes execution. An ambiguous condition exists if the data-space pointer is not aligned prior to execution of ,.

Source

fn p_to_r(&mut self)

Source

fn r_from(&mut self)

Source

fn r_fetch(&mut self)

Source

fn two_to_r(&mut self)

Source

fn two_r_from(&mut self)

Source

fn two_r_fetch(&mut self)

Source

fn check_stacks(&mut self)

Source

fn handler_store(&mut self)

Source

fn error(&mut self)

Error code error ( -- n )

Source

fn clear_error(&mut self)

Clear error. 0error ( -- )

Source

fn dot_error(&mut self)

Print error description. .error ( -- )

Source

fn clear_stacks(&mut self)

Clear data, floating point, and control stacks. Called by VM’s client upon ABORT.

Source

fn p_source_id(&mut self)

( – source-id )

Current source id.

Source

fn p_set_source_id(&mut self)

( source-id – )

Set source id.

Source

fn set_source_id(&mut self, id: isize)

Set source id.

Source

fn p_source_idx(&mut self)

( – source-idx )

Current source index.

Source

fn p_set_source_idx(&mut self)

( source-idx – )

Set source index.

Source

fn reset(&mut self)

Reset VM, do not clear data stack, floating point and control stack. Called by VM’s client upon Quit.

Source

fn abort_with(&mut self, e: Exception)

Abort the inner loop with an exception, reset VM and clears stacks.

Source

fn abort(&mut self)

Abort the inner loop with an exception, reset VM and clears stacks.

Source

fn pause(&mut self)

Pause the current task and resume the next task which is awake.

Source

fn me(&mut self)

Current task ID

Source

fn suspend(&mut self)

Suspend task i. suspend ( i -- )

Source

fn resume(&mut self)

Resume task i. resume ( i -- )

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§