eForth1  v2.6
eforth_vm.cpp File Reference

eForth Virtual Machine module More...

#include "eforth_vm.h"
Include dependency graph for eforth_vm.cpp:

Namespaces

 EfVM
 

Macros

#define OP(name)   op##name
 
#define VTABLE   enum { OP(NOP) = 0, OPCODES }
 
#define DISPATCH(op)   switch(op)
 
#define _X(n, code)   case op##n: { DEBUG("%s",#n); { code; } break; }
 

Functions

void EfVM::_init ()
 
void EfVM::_qrx ()
 

( – c ) fetch a char from console

More...
 
void EfVM::_txsto ()
 

(c – ) send a char to console

More...
 
void EfVM::_out (U16 p, U16 v)
 

Arduino port setting

More...
 
void vm_init (PGM_P rom, U8 *ram, void *io_stream, const char *code)
 
void _ccall ()
 
void vm_cfunc (int n, CFP fp)
 

function pointer

More...
 
void vm_push (int v)
 push value onto VM data stack More...
 
int vm_pop ()
 pop TOS off VM data stack More...
 

Variables

VM Registers
DUEfVM::S
 data stack pointer, 'stack' in Dr. Ting's More...
 
DUEfVM::R
 return stack pointer, 'rack' in Dr. Ting's More...
 
DU EfVM::T
 TOS, cached top of stack value. More...
 
DU EfVM::I
 RTOS, cached loop counter on return stack. More...
 
IO Streaming interface
Stream * EfVM::io
 IO Stream, tied to Serial usually. More...
 
Memory Management Unit
PGM_P EfVM::_rom
 ROM, Forth built-in words stored in Flash. More...
 
U8EfVM::_ram
 RAM, for user defined words. More...
 
U8EfVM::_pre
 Forth code pre-defined/embedded in .ino. More...
 
CFP EfVM::_api [CFUNC_MAX]
 C API function pointer. More...
 
VM Registers
DUEfVM::S
 data stack pointer, 'stack' in Dr. Ting's More...
 
DUEfVM::R
 return stack pointer, 'rack' in Dr. Ting's More...
 
DU EfVM::T
 TOS, cached top of stack value. More...
 
DU EfVM::I
 RTOS, cached loop counter on return stack. More...
 
IO Streaming interface
Stream * EfVM::io
 IO Stream, tied to Serial usually. More...
 
Memory Management Unit
PGM_P EfVM::_rom
 ROM, Forth built-in words stored in Flash. More...
 
U8EfVM::_ram
 RAM, for user defined words. More...
 
U8EfVM::_pre
 Forth code pre-defined/embedded in .ino. More...
 
CFP EfVM::_api [CFUNC_MAX]
 C API function pointer. More...
 

Detailed Description

eForth Virtual Machine module

Revision Note: Threading model evolution 202212 EfVMSub module - vtable subroutine calling 202301 indirect threading - computed label jumping 202302 direct threading - opcode => code(); continue = $NEXT 202405 add computed_goto; DS,RS,top,rtop=>S,R,T,I

Macro Definition Documentation

◆ OP

#define OP (   name)    op##name

eForth virtual machine outer interpreter (single-step) execution unit

Returns
0 - exit

◆ VTABLE

#define VTABLE   enum { OP(NOP) = 0, OPCODES }

◆ DISPATCH

#define DISPATCH (   op)    switch(op)

◆ _X

#define _X (   n,
  code 
)    case op##n: { DEBUG("%s",#n); { code; } break; }

Function Documentation

◆ vm_init()

void vm_init ( PGM_P  rom,
U8 ram,
void *  io_stream,
const char *  code 
)
  • resetting user variables

◆ _ccall()

void _ccall ( )

C interface implementation

TODO: build formal C callstack construct

fetch C function pointer

pop off TOS

call C function

◆ vm_cfunc()

void vm_cfunc ( int  n,
CFP  fp 
)

function pointer

assign C interface (in slot n)

◆ vm_push()

void vm_push ( int  v)

push value onto VM data stack

proxy to VM

◆ vm_pop()

int vm_pop ( )

pop TOS off VM data stack