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§
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
Sourcefn hold_buffer(&mut self) -> &mut String
fn hold_buffer(&mut self) -> &mut String
Numeric output buffer
Sourcefn output_buffer(&mut self) -> &mut Option<String>
fn output_buffer(&mut self) -> &mut Option<String>
Get output_buffer
.
Sourcefn set_output_buffer(&mut self, buffer: String)
fn set_output_buffer(&mut self, buffer: String)
Set output_buffer
to Some(buffer)
.
Sourcefn source_id(&self) -> isize
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.
Sourcefn input_buffer(&mut self) -> &mut Option<String>
fn input_buffer(&mut self) -> &mut Option<String>
Get input_buffer
.
Sourcefn set_input_buffer(&mut self, buffer: String)
fn set_input_buffer(&mut self, buffer: String)
Set input_buffer
to Some(buffer)
.
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>
Sourcefn wordlist_mut(&mut self) -> &mut Wordlist<Self>
fn wordlist_mut(&mut self) -> &mut Wordlist<Self>
Last definition, 0 if last define fails.
fn wordlist(&self) -> &Wordlist<Self>
fn state(&mut self) -> &mut State
fn references(&mut self) -> &mut ForwardReferences
fn system_time_ns(&self) -> u64
Sourcefn current_task(&self) -> usize
fn current_task(&self) -> usize
Current task
Sourcefn set_current_task(&mut self, i: usize)
fn set_current_task(&mut self, i: usize)
Set curretn task.
No operation if there is no task i
.
Sourcefn forward_bitset(&self) -> &BitSet
fn forward_bitset(&self) -> &BitSet
Bitset to check forward declaration of labels.
Sourcefn forward_bitset_mut(&mut self) -> &mut BitSet
fn forward_bitset_mut(&mut self) -> &mut BitSet
Mutable bitset to check forward declaration of labels.
Sourcefn resolved_bitset(&self) -> &BitSet
fn resolved_bitset(&self) -> &BitSet
Bitset to check resolved labels.
Sourcefn resolved_bitset_mut(&mut self) -> &mut BitSet
fn resolved_bitset_mut(&mut self) -> &mut BitSet
Mutable bitset to check resolved labels.
Sourcefn labels_mut(&mut self) -> &mut Vec<usize>
fn labels_mut(&mut self) -> &mut Vec<usize>
Labels to support BASIC-like goto, label, call.
Provided Methods§
Sourcefn add_core(&mut self)
fn add_core(&mut self)
Add core primitives to self.
Examples found in repository?
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 }
Sourcefn add_primitive(&mut self, name: &str, action: fn(&mut Self))
fn add_primitive(&mut self, name: &str, action: fn(&mut Self))
Add a primitive word to word list.
Examples found in repository?
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}
Sourcefn add_immediate(&mut self, name: &str, action: fn(&mut Self))
fn add_immediate(&mut self, name: &str, action: fn(&mut Self))
Add an immediate word to word list.
Sourcefn compile_only(&mut self)
fn compile_only(&mut self)
Set the last definition compile-only.
Sourcefn add_compile_only(&mut self, name: &str, action: fn(&mut Self))
fn add_compile_only(&mut self, name: &str, action: fn(&mut Self))
Add a compile-only word to word list.
Sourcefn add_immediate_and_compile_only(&mut self, name: &str, action: fn(&mut Self))
fn add_immediate_and_compile_only(&mut self, name: &str, action: fn(&mut Self))
Add an immediate and compile-only word to word list.
Sourcefn execute_word(&mut self, i: usize)
fn execute_word(&mut self, i: usize)
Execute word at position i
.
Examples found in repository?
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}
Sourcefn find(&mut self, name: &str) -> Option<usize>
fn find(&mut self, name: &str) -> Option<usize>
Find the word with name name
.
If not found returns zero.
Examples found in repository?
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}
Sourcefn run(&mut self)
fn run(&mut self)
Evaluate a compiled program following self.state().instruction_pointer. Any exception causes termination of inner loop.
Examples found in repository?
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}
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)
Sourcefn compile_integer(&mut self, i: isize)
fn compile_integer(&mut self, i: isize)
Compile integer i
.
fn flit(&mut self)
Sourcefn compile_float(&mut self, f: f64)
fn compile_float(&mut self, f: f64)
Compile float ‘f’.
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
Sourcefn _do(&mut self)
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
Sourcefn _qdo(&mut self)
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
Sourcefn _loop(&mut self)
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.
Sourcefn _plus_loop(&mut self)
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.
Sourcefn unloop(&mut self)
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
EXIT
ed. An ambiguous condition exists if the loop-control parameters
are unavailable.
fn leave(&mut self)
fn compile_leave(&mut self, word_idx: usize)
fn p_j(&mut self)
fn leave_part(&mut self) -> Option<usize>
Sourcefn imm_if(&mut self)
fn imm_if(&mut self)
IF A THEN
+------+
| |
| v
+-----+---+---+--
| _if | x | A |
+-----+---+---+--
^
|
ip
Sourcefn imm_else(&mut self)
fn imm_else(&mut self)
IF A ELSE B THEN
+--------------------+
| |
| v
+---------+---+---+--------+---+---+--
| ?branch | x | A | branch | x | B |
+---------+---+---+--------+---+---+--
^ | ^
| | |
ip +-------+
fn imm_then(&mut self)
Sourcefn imm_case(&mut self)
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 |
+-----+----+------+---+---------+---+------+---+--------+---+---+------+---+
| ^
| |
+---------------------------+
fn imm_of(&mut self)
fn imm_endof(&mut self)
fn imm_endcase(&mut self)
Sourcefn imm_begin(&mut self)
fn imm_begin(&mut self)
Begin a structure that is terminated by repeat
, until
, or again
. begin ( -- )
.
Sourcefn imm_while(&mut self)
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 |
+---+---------+---+---+--------+---+---+
^ |
| |
+------------------------------+
Sourcefn imm_repeat(&mut self)
fn imm_repeat(&mut self)
Terminate a begin ... while ... repeat
structure. repeat ( -- )
.
Continue execution at the location following begin
.
Sourcefn imm_until(&mut self)
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 |
+---+---------+---+---+
^ |
| |
+-------------+
Sourcefn imm_again(&mut self)
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 |
+---+--------+---+---+
^ |
| |
+------------+
Sourcefn imm_clear_labels(&mut self)
fn imm_clear_labels(&mut self)
Clear labels, 0labels ( -- )
Sourcefn imm_goto(&mut self)
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
Sourcefn imm_call(&mut self)
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 ...
Sourcefn imm_do(&mut self)
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)
fn imm_recurse(&mut self)
Sourcefn imm_qdo(&mut self)
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)
Sourcefn imm_loop(&mut self)
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, _)
Sourcefn imm_plus_loop(&mut self)
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
.
fn activate(&mut self)
fn p_i(&mut self)
fn left_bracket(&mut self)
fn right_bracket(&mut self)
Sourcefn set_source(&mut self, s: &str)
fn set_source(&mut self, s: &str)
Copy content of s
to input_buffer
and set source_index
to 0.
Examples found in repository?
More examples
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}
Sourcefn push_source(&mut self, s: &str)
fn push_source(&mut self, s: &str)
Push content of s
to input_buffer
.
Sourcefn parse_word(&mut self)
fn parse_word(&mut self)
Run-time: ( “ccc” – )
Parse word delimited by white space, skipping leading white spaces.
Sourcefn char(&mut self)
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.
Sourcefn bracket_char(&mut self)
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.
Sourcefn parse(&mut self)
fn parse(&mut self)
Run-time: ( char “ccc<char>” – )
Parse ccc delimited by the delimiter char.
fn imm_paren(&mut self)
Sourcefn imm_backslash(&mut self)
fn imm_backslash(&mut self)
Begin a comment that includes the entire remainder of the current line.
Sourcefn postpone(&mut self)
fn postpone(&mut self)
postpone ( “
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 |
+--------------------+-----------+------+------------+-----------+
Sourcefn _postpone(&mut self)
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.
fn compile_token(&mut self)
fn interpret_token(&mut self)
fn p_compiling(&mut self)
Sourcefn token_empty(&mut self)
fn token_empty(&mut self)
Is token empty? `token-empty? ( – f )
Sourcefn store_token(&mut self)
fn store_token(&mut self)
Store token. `!token ( c-addr – )
Store token in counted string at c-addr
.`
Sourcefn evaluate_input(&mut self)
fn evaluate_input(&mut self)
Examples found in repository?
More examples
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}
fn base(&mut self)
fn evaluate_integer(&mut self, token: &str)
Sourcefn evaluate_float(&mut self, token: &str)
fn evaluate_float(&mut self, token: &str)
Evaluate float.
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)
Sourcefn marker(&mut self)
fn marker(&mut self)
Example:
marker -work
DFA of -work
+------+--------+
| last | b0-b63 |
+------+--------+
Sourcefn does(&mut self)
fn does(&mut self)
Run time behavior of words created by create
… does>
.
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 |
+---+----+
fn xdoes(&mut self)
Sourcefn p_true(&mut self)
fn p_true(&mut self)
Run-time: ( – true )
Return a true flag, a single-cell value with all bits set.
Sourcefn char_plus(&mut self)
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
.
Sourcefn cell_plus(&mut self)
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
.
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)
Sourcefn pick(&mut self)
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
.
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)
Sourcefn within(&mut self)
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.
fn invert(&mut self)
fn and(&mut self)
fn or(&mut self)
fn xor(&mut self)
Sourcefn lshift(&mut self)
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.
Sourcefn rshift(&mut self)
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.
Sourcefn exit(&mut self)
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
.
Sourcefn bye(&mut self)
fn bye(&mut self)
Execution: ( – )
Set the instruction pointer to zero in order to terminate inner interpreter.
Sourcefn c_fetch(&mut self)
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.
Sourcefn c_store(&mut self)
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.
Sourcefn p_move(&mut self)
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.
Sourcefn tick(&mut self)
fn tick(&mut self)
Run-time: ( “
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.
Sourcefn to_body(&mut self)
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.
Sourcefn execute(&mut self)
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 EXECUTE
d.
Sourcefn bracket_tick(&mut self)
fn bracket_tick(&mut self)
Compilation: ( “
Forth 2012 6.1.2510
Sourcefn compile_comma(&mut self)
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.
Sourcefn allot(&mut self)
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.
Sourcefn aligned(&mut self)
fn aligned(&mut self)
Run-time: ( addr – a-addr )
Return a-addr
, the first aligned address greater than or equal to addr
.
Sourcefn align(&mut self)
fn align(&mut self)
Run-time: ( – )
If the data-space pointer is not aligned, reserve enough space to align it.
Sourcefn comma(&mut self)
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 ,
.
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)
Sourcefn clear_error(&mut self)
fn clear_error(&mut self)
Clear error. 0error ( -- )
Sourcefn clear_stacks(&mut self)
fn clear_stacks(&mut self)
Clear data, floating point, and control stacks. Called by VM’s client upon ABORT.
Sourcefn p_source_id(&mut self)
fn p_source_id(&mut self)
( – source-id )
Current source id.
Sourcefn p_set_source_id(&mut self)
fn p_set_source_id(&mut self)
( source-id – )
Set source id.
Sourcefn set_source_id(&mut self, id: isize)
fn set_source_id(&mut self, id: isize)
Set source id.
Sourcefn p_source_idx(&mut self)
fn p_source_idx(&mut self)
( – source-idx )
Current source index.
Sourcefn p_set_source_idx(&mut self)
fn p_set_source_idx(&mut self)
( source-idx – )
Set source index.
Sourcefn reset(&mut self)
fn reset(&mut self)
Reset VM, do not clear data stack, floating point and control stack. Called by VM’s client upon Quit.
Sourcefn abort_with(&mut self, e: Exception)
fn abort_with(&mut self, e: Exception)
Abort the inner loop with an exception, reset VM and clears stacks.
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.