Adding memory capacity and base fields.
This commit is contained in:
@ -52,25 +52,29 @@
|
|||||||
: 2@ ( a -- lo hi ) dup @ swap cell+ @ ;
|
: 2@ ( a -- lo hi ) dup @ swap cell+ @ ;
|
||||||
: 2! ( lo hi a -- ) dup >r cell+ ! r> ! ;
|
: 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 )
|
( Dictionary )
|
||||||
: here ( -- a ) 'heap @ ;
|
: here ( -- a ) 'sys @ ;
|
||||||
: allot ( n -- ) 'heap +! ;
|
: allot ( n -- ) 'sys +! ;
|
||||||
: aligned ( a -- a ) cell 1 - dup >r + r> invert and ;
|
: aligned ( a -- a ) cell 1 - dup >r + r> invert and ;
|
||||||
: align here aligned here - allot ;
|
: align here aligned here - allot ;
|
||||||
: , ( n -- ) here ! cell allot ;
|
: , ( n -- ) here ! cell allot ;
|
||||||
: c, ( ch -- ) here c! 1 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 )
|
( Compilation State )
|
||||||
: [ 0 state ! ; immediate
|
: [ 0 state ! ; immediate
|
||||||
: ] -1 state ! ; immediate
|
: ] -1 state ! ; immediate
|
||||||
@ -112,10 +116,6 @@
|
|||||||
: immediate? ( xt -- f ) >flags @ 1 and 0= 0= ;
|
: immediate? ( xt -- f ) >flags @ 1 and 0= 0= ;
|
||||||
: postpone ' dup immediate? if , else aliteral ['] , , then ; immediate
|
: postpone ' dup immediate? if , else aliteral ['] , , then ; immediate
|
||||||
|
|
||||||
( Constants and Variables )
|
|
||||||
: constant ( n "name" -- ) create , does> @ ;
|
|
||||||
: variable ( "name" -- ) create 0 , ;
|
|
||||||
|
|
||||||
( Stack Convience )
|
( Stack Convience )
|
||||||
sp@ constant sp0
|
sp@ constant sp0
|
||||||
rp@ constant rp0
|
rp@ constant rp0
|
||||||
@ -256,3 +256,6 @@ create input-buffer input-limit allot
|
|||||||
: quit begin ['] evaluate-buffer catch
|
: quit begin ['] evaluate-buffer catch
|
||||||
if 0 state ! sp0 sp! fp0 fp! rp0 rp! ." ERROR" cr then
|
if 0 state ! sp0 sp! fp0 fp! rp0 rp! ." ERROR" cr then
|
||||||
prompt refill drop again ;
|
prompt refill drop again ;
|
||||||
|
: raw-ok ." v{{VERSION}} - rev {{REVISION}}" cr
|
||||||
|
remaining . ." bytes heap free" cr
|
||||||
|
prompt refill drop quit ;
|
||||||
|
|||||||
@ -28,12 +28,18 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct {
|
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;
|
const char *tib;
|
||||||
cell_t ntib, tin, state, base;
|
cell_t ntib, tin, state, base;
|
||||||
cell_t *heap, **current, ***context, notfound;
|
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
cell_t *(*runner)(cell_t *rp); // pointer to forth_run
|
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 *rp; // spot to park main thread
|
||||||
cell_t DOLIT_XT, DOFLIT_XT, DOEXIT_XT, YIELD_XT;
|
cell_t DOLIT_XT, DOFLIT_XT, DOEXIT_XT, YIELD_XT;
|
||||||
} g_sys;
|
} g_sys;
|
||||||
@ -191,10 +197,16 @@ static cell_t *forth_run(cell_t *initrp);
|
|||||||
|
|
||||||
static void forth_init(int argc, char *argv[], void *heap,
|
static void forth_init(int argc, char *argv[], void *heap,
|
||||||
const char *src, cell_t src_len) {
|
const char *src, cell_t src_len) {
|
||||||
g_sys.heap = ((cell_t *) heap) + 4; // Leave a little room.
|
g_sys.heap_start = (cell_t *) heap;
|
||||||
float *fp = (float *) (g_sys.heap + 1); g_sys.heap += STACK_SIZE;
|
g_sys.heap_size = HEAP_SIZE;
|
||||||
cell_t *rp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
|
g_sys.stack_cells = STACK_CELLS;
|
||||||
cell_t *sp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
|
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
|
// FORTH vocabulary
|
||||||
*g_sys.heap++ = 0; cell_t *forth = g_sys.heap;
|
*g_sys.heap++ = 0; cell_t *forth = g_sys.heap;
|
||||||
|
|||||||
@ -103,5 +103,4 @@ typedef int64_t dcell_t;
|
|||||||
sp = evaluate1(sp, &tfp); \
|
sp = evaluate1(sp, &tfp); \
|
||||||
fp = tfp; w = *sp--; DROP; if (w) JMPW) \
|
fp = tfp; w = *sp--; DROP; if (w) JMPW) \
|
||||||
Y(EXIT, ip = (cell_t *) *rp--) \
|
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)
|
||||||
|
|
||||||
|
|||||||
@ -48,12 +48,14 @@ transfer{
|
|||||||
'context 'notfound notfound
|
'context 'notfound notfound
|
||||||
immediate? input-buffer ?echo ?arrow. arrow
|
immediate? input-buffer ?echo ?arrow. arrow
|
||||||
evaluate1 evaluate-buffer
|
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,
|
leaving( )leaving leaving leaving,
|
||||||
(do) (?do) (+loop)
|
(do) (?do) (+loop)
|
||||||
parse-quote digit $@ raw.s
|
parse-quote digit $@ raw.s
|
||||||
tib-setup input-limit
|
tib-setup input-limit
|
||||||
[SKIP] [SKIP]'
|
[SKIP] [SKIP]' raw-ok
|
||||||
}transfer
|
}transfer
|
||||||
forth definitions
|
forth definitions
|
||||||
|
|
||||||
|
|||||||
@ -63,4 +63,4 @@ led OUTPUT pinMode
|
|||||||
high led pin
|
high led pin
|
||||||
|
|
||||||
( Setup entry )
|
( Setup entry )
|
||||||
: ok ." ESP32forth v{{VERSION}} - rev {{REVISION}}" cr prompt refill drop quit ;
|
internals : ok ." ESP32forth" raw-ok ; forth
|
||||||
|
|||||||
@ -85,7 +85,7 @@
|
|||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
|
||||||
#define HEAP_SIZE (100 * 1024)
|
#define HEAP_SIZE (100 * 1024)
|
||||||
#define STACK_SIZE 512
|
#define STACK_CELLS 512
|
||||||
#define INTERRUPT_STACK_CELLS 64
|
#define INTERRUPT_STACK_CELLS 64
|
||||||
|
|
||||||
// Optional hook to pull in words for userwords.h
|
// Optional hook to pull in words for userwords.h
|
||||||
|
|||||||
@ -189,4 +189,4 @@ O_RDWR constant r/w
|
|||||||
forth
|
forth
|
||||||
|
|
||||||
( Setup entry )
|
( Setup entry )
|
||||||
: ok ." uEforth v{{VERSION}} - rev {{REVISION}}" cr prompt refill drop quit ;
|
internals : ok ." uEforth" raw-ok ; forth
|
||||||
|
|||||||
@ -13,9 +13,6 @@
|
|||||||
\ limitations under the License.
|
\ limitations under the License.
|
||||||
|
|
||||||
( Arguments )
|
( Arguments )
|
||||||
internals definitions
|
|
||||||
: 'argc ( -- a ) 'sys 9 cells + ;
|
|
||||||
: 'argv ( -- a ) 'sys 10 cells + ;
|
|
||||||
forth definitions internals
|
forth definitions internals
|
||||||
: argc ( -- n ) 'argc @ ;
|
: argc ( -- n ) 'argc @ ;
|
||||||
: argv ( n -- a n ) cells 'argv @ + @ z>s ;
|
: argv ( n -- a n ) cells 'argv @ + @ z>s ;
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
#include "common/calls.h"
|
#include "common/calls.h"
|
||||||
|
|
||||||
#define HEAP_SIZE (10 * 1024 * 1024)
|
#define HEAP_SIZE (10 * 1024 * 1024)
|
||||||
#define STACK_SIZE (64 * 1024)
|
#define STACK_CELLS (8 * 1024)
|
||||||
|
|
||||||
#define PLATFORM_OPCODE_LIST \
|
#define PLATFORM_OPCODE_LIST \
|
||||||
Y(DLSYM, tos = (cell_t) dlsym(a1, a0); --sp) \
|
Y(DLSYM, tos = (cell_t) dlsym(a1, a0); --sp) \
|
||||||
|
|||||||
@ -47,7 +47,8 @@ create event xevent-size allot
|
|||||||
display gc white XSetBackground drop
|
display gc white XSetBackground drop
|
||||||
display window gc 0 0 width @ 2/ height @ 2/ XFillRectangle 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@ .
|
||||||
event c@ Expose = if
|
event c@ Expose = if
|
||||||
draw
|
draw
|
||||||
@ -67,5 +68,5 @@ create event xevent-size allot
|
|||||||
then
|
then
|
||||||
event c@ MapNotify = if ." MapNotify" then
|
event c@ MapNotify = if ." MapNotify" then
|
||||||
cr ;
|
cr ;
|
||||||
: 1e display event XNextEvent drop de ;
|
: do-event display event XNextEvent drop handle-event ;
|
||||||
: gg begin draw 1e again ;
|
: gg begin draw do-event again ;
|
||||||
|
|||||||
@ -42,6 +42,7 @@ R| ( string| -- a n ) Creates a temporary counted string ending with |
|
|||||||
DUMP ( a n -- ) Dump a memory region
|
DUMP ( a n -- ) Dump a memory region
|
||||||
SEE ( "name" -- ) Attempt to decompile a word
|
SEE ( "name" -- ) Attempt to decompile a word
|
||||||
VARIABLE ECHO -- Determines if commands are echoed
|
VARIABLE ECHO -- Determines if commands are echoed
|
||||||
|
REMAINING ( -- n ) Bytes remaining in Forth heap.
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h5>Vocabularies</h5>
|
<h5>Vocabularies</h5>
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
const HEAP_SIZE = (1024 * 1024);
|
const HEAP_SIZE = (1024 * 1024);
|
||||||
const STACK_SIZE = 4096;
|
const STACK_CELLS = 4096;
|
||||||
|
|
||||||
const boot = `
|
const boot = `
|
||||||
{{boot}}
|
{{boot}}
|
||||||
@ -133,9 +133,9 @@ function Init() {
|
|||||||
|
|
||||||
InitDictionary();
|
InitDictionary();
|
||||||
i32[g_sp>>2] = i32[g_heap>>2] + 1;
|
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_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
|
i32[((i32[g_current]>>2) - 4)>>2] = 1; // Make ; IMMMEDIATE
|
||||||
// Do not need DOLIT_XT, DOEXIT_XT, YIELD_XT (do by convention)
|
// Do not need DOLIT_XT, DOEXIT_XT, YIELD_XT (do by convention)
|
||||||
i32[g_notfound>>2] = Find('DROP');
|
i32[g_notfound>>2] = Find('DROP');
|
||||||
|
|||||||
@ -160,5 +160,5 @@ r/o w/o or constant r/w
|
|||||||
forth
|
forth
|
||||||
|
|
||||||
( Setup entry )
|
( 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 )
|
' forth ( leave on stack for fini.fs )
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
#include "common/calls.h"
|
#include "common/calls.h"
|
||||||
|
|
||||||
#define HEAP_SIZE (10 * 1024 * 1024)
|
#define HEAP_SIZE (10 * 1024 * 1024)
|
||||||
#define STACK_SIZE (64 * 1024)
|
#define STACK_CELLS (8 * 1024)
|
||||||
|
|
||||||
#define PLATFORM_OPCODE_LIST \
|
#define PLATFORM_OPCODE_LIST \
|
||||||
Y(GETPROCADDRESS, \
|
Y(GETPROCADDRESS, \
|
||||||
|
|||||||
Reference in New Issue
Block a user