Adding memory capacity and base fields.

This commit is contained in:
Brad Nelson
2022-01-08 18:47:54 -08:00
parent a81e01aaa5
commit d676d018cc
14 changed files with 56 additions and 41 deletions

View File

@ -52,25 +52,29 @@
: 2@ ( a -- lo hi ) dup @ swap cell+ @ ;
: 2! ( lo hi a -- ) dup >r cell+ ! r> ! ;
( System Variables )
: 'tib ( -- a ) 'sys 0 cells + ;
: #tib ( -- a ) 'sys 1 cells + ;
: >in ( -- a ) 'sys 2 cells + ;
: state ( -- a ) 'sys 3 cells + ;
: base ( -- a ) 'sys 4 cells + ;
: 'heap ( -- a ) 'sys 5 cells + ;
: current ( -- a ) 'sys 6 cells + ;
: 'context ( -- a ) 'sys 7 cells + ; : context 'context @ cell+ ;
: 'notfound ( -- a ) 'sys 8 cells + ;
( Dictionary )
: here ( -- a ) 'heap @ ;
: allot ( n -- ) 'heap +! ;
: here ( -- a ) 'sys @ ;
: allot ( n -- ) 'sys +! ;
: aligned ( a -- a ) cell 1 - dup >r + r> invert and ;
: align here aligned here - allot ;
: , ( n -- ) here ! cell allot ;
: c, ( ch -- ) here c! 1 allot ;
( Constants and Variables )
: constant ( n "name" -- ) create , does> @ ;
: variable ( "name" -- ) create 0 , ;
( System Variables )
: sys: ( a -- a' "name" ) dup constant cell+ ;
'sys sys: 'heap sys: current sys: 'context sys: 'notfound
sys: 'heap-start sys: 'heap-size sys: 'stack-cells
sys: 'boot sys: 'boot-size
sys: 'tib sys: #tib sys: >in
sys: state sys: base
sys: 'argc sys: 'argv sys: 'runner
: context ( -- a ) 'context @ cell+ ;
: remaining ( -- n ) 'heap-start @ 'heap-size @ + 'heap @ - ;
( Compilation State )
: [ 0 state ! ; immediate
: ] -1 state ! ; immediate
@ -112,10 +116,6 @@
: immediate? ( xt -- f ) >flags @ 1 and 0= 0= ;
: postpone ' dup immediate? if , else aliteral ['] , , then ; immediate
( Constants and Variables )
: constant ( n "name" -- ) create , does> @ ;
: variable ( "name" -- ) create 0 , ;
( Stack Convience )
sp@ constant sp0
rp@ constant rp0
@ -256,3 +256,6 @@ create input-buffer input-limit allot
: quit begin ['] evaluate-buffer catch
if 0 state ! sp0 sp! fp0 fp! rp0 rp! ." ERROR" cr then
prompt refill drop again ;
: raw-ok ." v{{VERSION}} - rev {{REVISION}}" cr
remaining . ." bytes heap free" cr
prompt refill drop quit ;

View File

@ -28,12 +28,18 @@
#endif
static struct {
cell_t *heap, **current, ***context, notfound;
cell_t *heap_start;
cell_t heap_size, stack_cells;
const char *boot;
cell_t boot_size;
const char *tib;
cell_t ntib, tin, state, base;
cell_t *heap, **current, ***context, notfound;
int argc;
char **argv;
cell_t *(*runner)(cell_t *rp); // pointer to forth_run
// Layout not used by Forth.
cell_t *rp; // spot to park main thread
cell_t DOLIT_XT, DOFLIT_XT, DOEXIT_XT, YIELD_XT;
} g_sys;
@ -191,10 +197,16 @@ static cell_t *forth_run(cell_t *initrp);
static void forth_init(int argc, char *argv[], void *heap,
const char *src, cell_t src_len) {
g_sys.heap = ((cell_t *) heap) + 4; // Leave a little room.
float *fp = (float *) (g_sys.heap + 1); g_sys.heap += STACK_SIZE;
cell_t *rp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
cell_t *sp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
g_sys.heap_start = (cell_t *) heap;
g_sys.heap_size = HEAP_SIZE;
g_sys.stack_cells = STACK_CELLS;
g_sys.boot = src;
g_sys.boot_size = src_len;
g_sys.heap = g_sys.heap_start + 4; // Leave a little room.
float *fp = (float *) (g_sys.heap + 1); g_sys.heap += STACK_CELLS;
cell_t *rp = g_sys.heap + 1; g_sys.heap += STACK_CELLS;
cell_t *sp = g_sys.heap + 1; g_sys.heap += STACK_CELLS;
// FORTH vocabulary
*g_sys.heap++ = 0; cell_t *forth = g_sys.heap;

View File

@ -103,5 +103,4 @@ typedef int64_t dcell_t;
sp = evaluate1(sp, &tfp); \
fp = tfp; w = *sp--; DROP; if (w) JMPW) \
Y(EXIT, ip = (cell_t *) *rp--) \
X(";", SEMICOLON, UNSMUDGE(); COMMA(g_sys.DOEXIT_XT); g_sys.state = 0) \
X(";", SEMICOLON, UNSMUDGE(); COMMA(g_sys.DOEXIT_XT); g_sys.state = 0)

View File

@ -48,12 +48,14 @@ transfer{
'context 'notfound notfound
immediate? input-buffer ?echo ?arrow. arrow
evaluate1 evaluate-buffer
'sys 'heap aliteral
'sys 'heap aliteral 'heap-start 'heap-size
'stack-cells 'boot 'boot-size
'argc 'argv 'runner
leaving( )leaving leaving leaving,
(do) (?do) (+loop)
parse-quote digit $@ raw.s
tib-setup input-limit
[SKIP] [SKIP]'
[SKIP] [SKIP]' raw-ok
}transfer
forth definitions

View File

@ -63,4 +63,4 @@ led OUTPUT pinMode
high led pin
( Setup entry )
: ok ." ESP32forth v{{VERSION}} - rev {{REVISION}}" cr prompt refill drop quit ;
internals : ok ." ESP32forth" raw-ok ; forth

View File

@ -85,7 +85,7 @@
#include <sys/select.h>
#define HEAP_SIZE (100 * 1024)
#define STACK_SIZE 512
#define STACK_CELLS 512
#define INTERRUPT_STACK_CELLS 64
// Optional hook to pull in words for userwords.h

View File

@ -189,4 +189,4 @@ O_RDWR constant r/w
forth
( Setup entry )
: ok ." uEforth v{{VERSION}} - rev {{REVISION}}" cr prompt refill drop quit ;
internals : ok ." uEforth" raw-ok ; forth

View File

@ -13,9 +13,6 @@
\ limitations under the License.
( Arguments )
internals definitions
: 'argc ( -- a ) 'sys 9 cells + ;
: 'argv ( -- a ) 'sys 10 cells + ;
forth definitions internals
: argc ( -- n ) 'argc @ ;
: argv ( n -- a n ) cells 'argv @ + @ z>s ;

View File

@ -21,7 +21,7 @@
#include "common/calls.h"
#define HEAP_SIZE (10 * 1024 * 1024)
#define STACK_SIZE (64 * 1024)
#define STACK_CELLS (8 * 1024)
#define PLATFORM_OPCODE_LIST \
Y(DLSYM, tos = (cell_t) dlsym(a1, a0); --sp) \

View File

@ -47,7 +47,8 @@ create event xevent-size allot
display gc white XSetBackground drop
display window gc 0 0 width @ 2/ height @ 2/ XFillRectangle drop
;
: de event xevent-size
: handle-event
event xevent-size
event c@ .
event c@ Expose = if
draw
@ -67,5 +68,5 @@ create event xevent-size allot
then
event c@ MapNotify = if ." MapNotify" then
cr ;
: 1e display event XNextEvent drop de ;
: gg begin draw 1e again ;
: do-event display event XNextEvent drop handle-event ;
: gg begin draw do-event again ;

View File

@ -42,6 +42,7 @@ R| ( string| -- a n ) Creates a temporary counted string ending with |
DUMP ( a n -- ) Dump a memory region
SEE ( "name" -- ) Attempt to decompile a word
VARIABLE ECHO -- Determines if commands are echoed
REMAINING ( -- n ) Bytes remaining in Forth heap.
</pre>
<h5>Vocabularies</h5>

View File

@ -17,7 +17,7 @@
(function() {
const HEAP_SIZE = (1024 * 1024);
const STACK_SIZE = 4096;
const STACK_CELLS = 4096;
const boot = `
{{boot}}
@ -133,9 +133,9 @@ function Init() {
InitDictionary();
i32[g_sp>>2] = i32[g_heap>>2] + 1;
i32[g_heap>>2] += STACK_SIZE;
i32[g_heap>>2] += STACK_CELLS;
i32[g_rp>>2] = i32[g_heap>>2] + 1;
i32[g_heap>>2] += STACK_SIZE;
i32[g_heap>>2] += STACK_CELLS;
i32[((i32[g_current]>>2) - 4)>>2] = 1; // Make ; IMMMEDIATE
// Do not need DOLIT_XT, DOEXIT_XT, YIELD_XT (do by convention)
i32[g_notfound>>2] = Find('DROP');

View File

@ -160,5 +160,5 @@ r/o w/o or constant r/w
forth
( Setup entry )
: ok ." uEforth v{{VERSION}} - rev {{REVISION}}" cr prompt refill drop quit ;
internals : ok ." uEforth" raw-ok ; forth
' forth ( leave on stack for fini.fs )

View File

@ -33,7 +33,7 @@
#include "common/calls.h"
#define HEAP_SIZE (10 * 1024 * 1024)
#define STACK_SIZE (64 * 1024)
#define STACK_CELLS (8 * 1024)
#define PLATFORM_OPCODE_LIST \
Y(GETPROCADDRESS, \