nanoFORTH
v2.2
|
Functions | |
U8 | _find (U8 *tkn, IU *adr) |
search the keyword through colon word linked-list More... | |
void | _add_word () |
void | _add_branch (U8 op) |
void | _add_str () |
void | _list_voc (U16 n) |
void | save (U8 autorun=0) |
persist user dictionary to EEPROM More... | |
U16 | load (U8 autorun=0) |
restore user dictionary from EEPROM More... | |
IU | reset () |
reset internal pointers (for BYE) More... | |
IU | query () |
dictionary, string list scanners More... | |
N4OP | parse (U8 *tkn, IU *rst, U8 run) |
Instruction decoder. More... | |
void | compile (IU *rp0) |
Forth compiler. More... | |
void | create () |
meta compiler More... | |
void | comma (DU v) |
compile a 16-bit value onto dictionary More... | |
void | ccomma (DU v) |
More... | |
void | does (IU xt) |
More... | |
void | dot_str () |
void | variable () |
create a variable on dictionary More... | |
void | constant (DU v) |
void | words () |
display words in dictionary More... | |
void | forget () |
forgets word in the dictionary More... | |
void | see () |
decode colon word More... | |
IU | trace (IU adr, U8 ir, char delim=0) |
print execution tracing info More... | |
Variables | |
U8 * | last { NULL } |
pointer to last word, for debugging More... | |
U8 * | here { NULL } |
top of dictionary (exposed to _vm for HRE, ALO opcodes) More... | |
U8 | tab = 0 |
LFA NFA XT=PFA +----—+----—+-----------------—+ | lnk | name | parameters...I_RET | +----—+----—+-----------------—+ | | | v v v 16-bits 3-bytes variable length parameters
Assembler class
search the keyword through colon word linked-list
find colon word address of next input token
void N4Asm::_add_word | ( | ) |
create name field with link back to previous word
void N4Asm::_add_branch | ( | U8 | op | ) |
create branching for instructions
f IF...THN, f IF...ELS...THN BGN...f UTL, BGN...f WHL...RPT, BGN...f WHL...f UTL n1 n0 FOR...NXT
void N4Asm::_add_str | ( | ) |
display the opcode name
void N4Asm::_list_voc | ( | U16 | n | ) |
list words in built-in vocabularies
void N4Asm::save | ( | U8 | autorun | ) |
persist user dictionary to EEPROM
persist dictionary from RAM into EEPROM
verify EEPROM capacity to hold user dictionary
create EEPROM dictionary header
copy user dictionary into EEPROM byte-by-byte
restore user dictionary from EEPROM
restore dictionary from EEPROM into RAM
validate EEPROM contains user dictionary (from previous run)
retrieve metadata (sizes) of user dictionary
retrieve user dictionary byte-by-byte into memory
adjust user dictionary pointers
IU N4Asm::reset | ( | ) |
reset internal pointers (for BYE)
reset internal pointers (called by VM::reset)
IU N4Asm::query | ( | ) |
dictionary, string list scanners
get address of next input token
get xt of next input token, 0 if not found
< lfa of word
check if token is in dictionary
Instruction decoder.
parse given token into actionable item
tkn | token to be parsed |
rst | parsed result |
run | run mode flag (1: run mode, 0: compile mode) |
void N4Asm::compile | ( | IU * | rp0 | ) |
Forth compiler.
Forth assembler (creates word onto dictionary)
fetch token, create name field linked to previous word
loop til exhaust all tokens (tkn==NULL)
trace assembler progress if enabled
determine type of operation, and keep opcode in tmp
an immediate command?
debug memory dump, if enabled
a colon word? [addr + lnk(2) + name(3)]
a built-in primitives?
a literal (number)?
extended words, not implemented yet
then, token type not found
rp0 | memory address to be used as assembler return stack |
void N4Asm::create | ( | ) |
meta compiler
meta compiler
create a word name field
create a word header (link + name field)
fetch token, create name field linked to previous word
< address to variable storage
1-byte literal
or, 3-byte literal
void N4Asm::comma | ( | DU | v | ) |
compile a 16-bit value onto dictionary
void N4Asm::ccomma | ( | DU | v | ) |
compile a 16-bit value onto dictionary
compile a 8-it value onto dictionary
void N4Asm::does | ( | IU | xt | ) |
compile a 16-bit value onto dictionary
metaprogrammer (jump to definding word DO> section)
metaprogrammer (jump to definding word DO> section)
start walking back
shift down parameters by 2 bytes
adjust the PFA
replace NOP with a JMP,
and a NOP, (not necessary but nice to SEE)
extra 2 bytes due to shift
void N4Asm::dot_str | ( | ) |
< keep current HERE
void N4Asm::variable | ( | ) |
create a variable on dictionary
create a variable on dictionary
add actual literal storage area
void N4Asm::constant | ( | DU | v | ) |
create a constant on dictionary
create a constant on dictionary
fetch token, create name field linked to previous word
handle 1-byte constant
or, constant stored as 3-byte literal
void N4Asm::words | ( | ) |
display words in dictionary
display words in dictionary
wraping width
from last, loop through dictionary
optionally show address
show word name
void N4Asm::forget | ( | ) |
forgets word in the dictionary
drop words from the dictionary
< cfa of word
word found, rollback here
< pointer to word's link
void N4Asm::see | ( | ) |
decode colon word
decode colon word
< cfa of word
word found, walk parameter field
< pointer to word's name
print execution tracing info
execution tracer (debugger, can be modified into single-stepper)
is a jump instruction?
is a primitive?
and a number (i.e. 1-byte literal)
adr | address to word to be executed |
ir | instruction register value |
delim | token delimiter |
U8 * N4Asm::last { NULL } |
pointer to last word, for debugging
U8 * N4Asm::here { NULL } |
top of dictionary (exposed to _vm for HRE, ALO opcodes)
U8 N4Asm::tab = 0 |
tracing indentation counter