nanoFORTH v2.2
Loading...
Searching...
No Matches
N4VM Namespace Reference

Functions

void _nest (IU xt)
 
void _init ()
 
void _dump (IU p0, U16 sz0)
 
void _immediate (U16 op)
 
void _clock ()
 
void _dplus ()
 
void _dminus ()
 
void _dneg ()
 
IU _invoke (U8 op, IU xt=0)
 
void setup (const char *code, Stream &io, U8 ucase)
 
void push (int v)
 
int pop ()
 
void serv_isr ()
 interrupt service routine
 
void outer ()
 outer-interpreter
 

Detailed Description

nanoForth Virtual Machine class

Function Documentation

◆ _nest()

void N4VM::_nest ( IU  xt)

‍reset virtual machine

‍opcode execution unit i.e. inner interpreter

‍walk through instruction sequences

< fetch instruction

< masked opcode

‍branching opcodes?

‍primitive word?

‍handle number (1-byte literal)

‍walk through instruction sequences

< fetch instruction

< masked opcode

‍branching opcodes?

‍primitive word?

‍handle number (1-byte literal)

◆ _init()

void N4VM::_init ( )
  • forward declaration
  • reset return stack pointer
  • reset data stack pointer
  • init interrupt handler
  • reload EEPROM and reset assembler
  • check autorun addr has been setup? (see SEX)
  • execute last saved colon word in EEPROM

◆ _dump()

void N4VM::_dump ( IU  p0,
U16  sz0 
)

◆ _immediate()

void N4VM::_immediate ( U16  op)

‍immediate word handler

‍compiler

  • : (COLON), switch into compile mode (for new word)
  • VAL, create new constant
  • VAR, create new variable

‍interrupt handlers

  • PCI, create a pin change interrupt handler
  • TMI, create a timer interrupt handler

< tmp = ISR slot#

  • period in multiply of 10ms

‍system

  • SEX - save/execute (autorun)
  • SAV
  • LD

‍dicionary debugging

  • FGT, rollback word created
  • DMP, memory dump
  • SEE
  • WRD

‍numeric radix

  • DEC
  • HEX
  • BYE, restart

◆ _clock()

void N4VM::_clock ( )

◆ _dplus()

void N4VM::_dplus ( )

◆ _dminus()

void N4VM::_dminus ( )

◆ _dneg()

void N4VM::_dneg ( )

◆ _invoke()

IU N4VM::_invoke ( U8  op,
IU  xt = 0 
)

‍invoke a built-in opcode Note: computed goto takes extra 128-bytes for ~5% faster

‍stack ops

‍Bit-wise ops

‍ALU ops

‍Logical ops

‍IO ops

‍Compiler ops

‍Double ops

‍Arduino Specific ops

‍meta programming (for advance users)

◆ setup()

void N4VM::setup ( const char *  code,
Stream &  io,
U8  ucase 
)

‍constructor and initializer

  • install embedded Forth code
  • set IO stream pointer (static member, shared with N4ASM)
  • set case sensitiveness
  • set radix = 10
  • init VM
Parameters
codepreload Forth code
ioIO stream
ucasecase sensitiveness

◆ push()

void N4VM::push ( int  v)

‍VM proxy functions

◆ pop()

int N4VM::pop ( )

◆ serv_isr()

void N4VM::serv_isr ( )

interrupt service routine

‍virtual machine interrupt service routine

◆ outer()

void N4VM::outer ( )

outer-interpreter

‍virtual machine execute single step (outer interpreter)

Returns
1: more token(s) in input buffer
0: buffer empty (yield control back to hardware)

‍console ok prompt if tib is empty

‍get a token from console

‍parse action from token (keep opcode in tmp)

‍immediate words,

‍execute colon word (user defined)

‍execute primitive built-in word,

‍push a number (literal) to stack top,

‍extended words, not implemented yet

‍or, error (unknown action)