Restructure more to allow tiers.
This commit is contained in:
37
Makefile
37
Makefile
@ -190,14 +190,12 @@ COMMON_PHASE1 = common/comments.fs \
|
|||||||
common/structures.fs
|
common/structures.fs
|
||||||
|
|
||||||
COMMON_PHASE1e = common/comments.fs \
|
COMMON_PHASE1e = common/comments.fs \
|
||||||
common/extra1.fs \
|
common/tier2_forth.fs \
|
||||||
common/boot.fs \
|
common/boot.fs \
|
||||||
common/extra2.fs \
|
|
||||||
common/io.fs \
|
common/io.fs \
|
||||||
common/conditionals.fs \
|
common/conditionals.fs \
|
||||||
common/vocabulary.fs \
|
common/vocabulary.fs \
|
||||||
common/floats.fs \
|
common/floats.fs \
|
||||||
common/extra3.fs \
|
|
||||||
common/structures.fs
|
common/structures.fs
|
||||||
|
|
||||||
COMMON_PHASE2 = common/tasks.fs common/utils.fs common/locals.fs \
|
COMMON_PHASE2 = common/tasks.fs common/utils.fs common/locals.fs \
|
||||||
@ -247,7 +245,8 @@ $(GEN)/esp32_boot.h: tools/source_to_string.js $(ESP32_BOOT) | $(GEN)
|
|||||||
|
|
||||||
$(GEN)/dump_web_opcodes: \
|
$(GEN)/dump_web_opcodes: \
|
||||||
web/dump_web_opcodes.c \
|
web/dump_web_opcodes.c \
|
||||||
common/opcodes.h \
|
common/tier0_opcodes.h \
|
||||||
|
common/tier1_opcodes.h \
|
||||||
common/bits.h \
|
common/bits.h \
|
||||||
common/floats.h | $(GEN)
|
common/floats.h | $(GEN)
|
||||||
$(CXX) $(CFLAGS) $< -o $@
|
$(CXX) $(CFLAGS) $< -o $@
|
||||||
@ -330,8 +329,9 @@ $(POSIX):
|
|||||||
|
|
||||||
$(POSIX)/ueforth: \
|
$(POSIX)/ueforth: \
|
||||||
posix/main.c \
|
posix/main.c \
|
||||||
common/opcodes.h \
|
common/tier0_opcodes.h \
|
||||||
common/extra_opcodes.h \
|
common/tier1_opcodes.h \
|
||||||
|
common/tier2_opcodes.h \
|
||||||
common/calls.h \
|
common/calls.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
@ -354,8 +354,9 @@ $(WINDOWS):
|
|||||||
|
|
||||||
$(WINDOWS)/uEf32.obj: \
|
$(WINDOWS)/uEf32.obj: \
|
||||||
windows/main.c \
|
windows/main.c \
|
||||||
common/opcodes.h \
|
common/tier0_opcodes.h \
|
||||||
common/extra_opcodes.h \
|
common/tier1_opcodes.h \
|
||||||
|
common/tier2_opcodes.h \
|
||||||
common/calls.h \
|
common/calls.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
@ -372,8 +373,9 @@ $(WINDOWS)/uEf32.exe: \
|
|||||||
|
|
||||||
$(WINDOWS)/uEf64.obj: \
|
$(WINDOWS)/uEf64.obj: \
|
||||||
windows/main.c \
|
windows/main.c \
|
||||||
common/opcodes.h \
|
common/tier0_opcodes.h \
|
||||||
common/extra_opcodes.h \
|
common/tier1_opcodes.h \
|
||||||
|
common/tier2_opcodes.h \
|
||||||
common/calls.h \
|
common/calls.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
@ -406,8 +408,9 @@ $(GEN)/esp32_sim_opcodes.h: $(GEN)/print-esp32-builtins | $(GEN)
|
|||||||
$(ESP32_SIM)/Esp32forth-sim: \
|
$(ESP32_SIM)/Esp32forth-sim: \
|
||||||
esp32/sim_main.cpp \
|
esp32/sim_main.cpp \
|
||||||
esp32/main.cpp \
|
esp32/main.cpp \
|
||||||
common/opcodes.h \
|
common/tier0_opcodes.h \
|
||||||
common/extra_opcodes.h \
|
common/tier1_opcodes.h \
|
||||||
|
common/tier2_opcodes.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
@ -429,8 +432,9 @@ $(ESP32)/ESP32forth:
|
|||||||
|
|
||||||
ESP32_PARTS = tools/replace.js \
|
ESP32_PARTS = tools/replace.js \
|
||||||
esp32/template.ino \
|
esp32/template.ino \
|
||||||
common/opcodes.h \
|
common/tier0_opcodes.h \
|
||||||
common/extra_opcodes.h \
|
common/tier1_opcodes.h \
|
||||||
|
common/tier2_opcodes.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/bits.h \
|
common/bits.h \
|
||||||
@ -446,8 +450,9 @@ $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth
|
|||||||
cat esp32/template.ino | tools/replace.js \
|
cat esp32/template.ino | tools/replace.js \
|
||||||
VERSION=$(VERSION) \
|
VERSION=$(VERSION) \
|
||||||
REVISION=$(REVISION) \
|
REVISION=$(REVISION) \
|
||||||
opcodes=@common/opcodes.h \
|
tier0_opcodes=@common/tier0_opcodes.h \
|
||||||
extra_opcodes=@common/extra_opcodes.h \
|
tier1_opcodes=@common/tier1_opcodes.h \
|
||||||
|
tier2_opcodes=@common/tier2_opcodes.h \
|
||||||
calling=@common/calling.h \
|
calling=@common/calling.h \
|
||||||
floats=@common/floats.h \
|
floats=@common/floats.h \
|
||||||
bits=@common/bits.h \
|
bits=@common/bits.h \
|
||||||
|
|||||||
@ -140,7 +140,19 @@ e: check-boot
|
|||||||
out: (
|
out: (
|
||||||
;e
|
;e
|
||||||
|
|
||||||
e: check-extra-opcodes
|
e: check-tier2-opcodes
|
||||||
|
out: >flags
|
||||||
|
out: >params
|
||||||
|
out: >size
|
||||||
|
out: >link&
|
||||||
|
out: >link
|
||||||
|
out: >name
|
||||||
|
out: >body
|
||||||
|
out: aligned
|
||||||
|
out: align
|
||||||
|
;e
|
||||||
|
|
||||||
|
e: check-tier1-opcodes
|
||||||
out: nip
|
out: nip
|
||||||
out: rdrop
|
out: rdrop
|
||||||
out: */
|
out: */
|
||||||
@ -190,19 +202,9 @@ e: check-extra-opcodes
|
|||||||
|
|
||||||
out: here
|
out: here
|
||||||
out: allot
|
out: allot
|
||||||
out: aligned
|
|
||||||
out: align
|
|
||||||
out: ,
|
out: ,
|
||||||
out: c,
|
out: c,
|
||||||
|
|
||||||
out: >flags
|
|
||||||
out: >params
|
|
||||||
out: >size
|
|
||||||
out: >link&
|
|
||||||
out: >link
|
|
||||||
out: >name
|
|
||||||
out: >body
|
|
||||||
|
|
||||||
out: current
|
out: current
|
||||||
out: #tib
|
out: #tib
|
||||||
out: >in
|
out: >in
|
||||||
@ -212,7 +214,7 @@ e: check-extra-opcodes
|
|||||||
out: latestxt
|
out: latestxt
|
||||||
;e
|
;e
|
||||||
|
|
||||||
e: check-core-opcodes
|
e: check-tier0-opcodes
|
||||||
out: 0=
|
out: 0=
|
||||||
out: 0<
|
out: 0<
|
||||||
out: +
|
out: +
|
||||||
@ -454,8 +456,9 @@ e: check-phase1
|
|||||||
|
|
||||||
e: check-opcodes
|
e: check-opcodes
|
||||||
check-float-opcodes
|
check-float-opcodes
|
||||||
check-extra-opcodes
|
check-tier2-opcodes
|
||||||
check-core-opcodes
|
check-tier1-opcodes
|
||||||
|
check-tier0-opcodes
|
||||||
;e
|
;e
|
||||||
|
|
||||||
e: check-desktop
|
e: check-desktop
|
||||||
|
|||||||
@ -22,8 +22,9 @@ static cell_t *forth_run(cell_t *init_rp) {
|
|||||||
name, ((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, \
|
name, ((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, \
|
||||||
sizeof(name) - 1, (VOC_ ## flags & 0xff), && OP_ ## op,
|
sizeof(name) - 1, (VOC_ ## flags & 0xff), && OP_ ## op,
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
EXTRA_OPCODE_LIST
|
TIER2_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0,
|
||||||
};
|
};
|
||||||
@ -38,7 +39,8 @@ static cell_t *forth_run(cell_t *init_rp) {
|
|||||||
rp = init_rp; UNPARK; NEXT;
|
rp = init_rp; UNPARK; NEXT;
|
||||||
#define Z(flags, name, op, code) OP_ ## op: { code; } NEXT;
|
#define Z(flags, name, op, code) OP_ ## op: { code; } NEXT;
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
EXTRA_OPCODE_LIST
|
TIER2_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ typedef struct {
|
|||||||
const void *code;
|
const void *code;
|
||||||
} BUILTIN_WORD;
|
} BUILTIN_WORD;
|
||||||
|
|
||||||
#define OPCODE_LIST \
|
#define TIER0_OPCODE_LIST \
|
||||||
X("0=", ZEQUAL, tos = !tos ? -1 : 0) \
|
X("0=", ZEQUAL, tos = !tos ? -1 : 0) \
|
||||||
X("0<", ZLESS, tos = (tos|0) < 0 ? -1 : 0) \
|
X("0<", ZLESS, tos = (tos|0) < 0 ? -1 : 0) \
|
||||||
X("+", PLUS, tos += *sp--) \
|
X("+", PLUS, tos += *sp--) \
|
||||||
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#define EXTRA_OPCODE_LIST \
|
#define TIER1_OPCODE_LIST \
|
||||||
Y(nip, NIP) \
|
Y(nip, NIP) \
|
||||||
Y(rdrop, --rp) \
|
Y(rdrop, --rp) \
|
||||||
XV(forth, "*/", STARSLASH, SSMOD_FUNC; NIP) \
|
XV(forth, "*/", STARSLASH, SSMOD_FUNC; NIP) \
|
||||||
@ -26,12 +26,12 @@
|
|||||||
Y(rot, w = sp[-1]; sp[-1] = *sp; *sp = tos; tos = w) \
|
Y(rot, w = sp[-1]; sp[-1] = *sp; *sp = tos; tos = w) \
|
||||||
X("-rot", MROT, w = tos; tos = *sp; *sp = sp[-1]; sp[-1] = w) \
|
X("-rot", MROT, w = tos; tos = *sp; *sp = sp[-1]; sp[-1] = w) \
|
||||||
X("?dup", QDUP, if (tos) DUP) \
|
X("?dup", QDUP, if (tos) DUP) \
|
||||||
X("<", LESS, tos = (*sp--) < tos ? -1 : 0) \
|
X("<", LESS, tos = *sp < tos ? -1 : 0; --sp) \
|
||||||
X(">", GREATER, tos = (*sp--) > tos ? -1 : 0) \
|
X(">", GREATER, tos = *sp > tos ? -1 : 0; --sp) \
|
||||||
X("<=", LESSEQ, tos = (*sp--) <= tos ? -1 : 0) \
|
X("<=", LESSEQ, tos = *sp <= tos ? -1 : 0; --sp) \
|
||||||
X(">=", GREATEREQ, tos = (*sp--) >= tos ? -1 : 0) \
|
X(">=", GREATEREQ, tos = *sp >= tos ? -1 : 0; --sp) \
|
||||||
X("=", EQUAL, tos = (*sp--) == tos ? -1 : 0) \
|
X("=", EQUAL, tos = *sp == tos ? -1 : 0; --sp) \
|
||||||
X("<>", NOTEQUAL, tos = (*sp--) != tos ? -1 : 0) \
|
X("<>", NOTEQUAL, tos = *sp != tos ? -1 : 0; --sp) \
|
||||||
X("0<>", ZNOTEQUAL, tos = tos ? -1 : 0) \
|
X("0<>", ZNOTEQUAL, tos = tos ? -1 : 0) \
|
||||||
Y(bl, DUP; tos = ' ') \
|
Y(bl, DUP; tos = ' ') \
|
||||||
Y(nl, DUP; tos = '\n') \
|
Y(nl, DUP; tos = '\n') \
|
||||||
@ -48,7 +48,7 @@
|
|||||||
X("2drop", TWODROP, NIP; DROP) \
|
X("2drop", TWODROP, NIP; DROP) \
|
||||||
X("2dup", TWODUP, DUP; tos = sp[-1]; DUP; tos = sp[-1]) \
|
X("2dup", TWODUP, DUP; tos = sp[-1]; DUP; tos = sp[-1]) \
|
||||||
X("2@", TWOAT, DUP; *sp = *(cell_t *) tos; tos = ((cell_t *) tos)[1]) \
|
X("2@", TWOAT, DUP; *sp = *(cell_t *) tos; tos = ((cell_t *) tos)[1]) \
|
||||||
X("2!", TWOSTORE, ((cell_t *) tos)[0] = sp[-1]; \
|
X("2!", TWOSTORE, *(cell_t *) tos = sp[-1]; \
|
||||||
((cell_t *) tos)[1] = *sp; sp -= 2; DROP) \
|
((cell_t *) tos)[1] = *sp; sp -= 2; DROP) \
|
||||||
Y(cmove, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \
|
Y(cmove, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \
|
||||||
X("cmove>", cmove2, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \
|
X("cmove>", cmove2, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \
|
||||||
@ -60,17 +60,8 @@
|
|||||||
Y(abs, tos = tos < 0 ? -tos : tos) \
|
Y(abs, tos = tos < 0 ? -tos : tos) \
|
||||||
Y(here, DUP; tos = (cell_t) g_sys->heap) \
|
Y(here, DUP; tos = (cell_t) g_sys->heap) \
|
||||||
Y(allot, g_sys->heap = (cell_t *) (tos + (cell_t) g_sys->heap); DROP) \
|
Y(allot, g_sys->heap = (cell_t *) (tos + (cell_t) g_sys->heap); DROP) \
|
||||||
Y(aligned, tos = CELL_ALIGNED(tos)) \
|
|
||||||
Y(align, g_sys->heap = (cell_t *) CELL_ALIGNED(g_sys->heap)) \
|
|
||||||
X(",", COMMA, COMMA(tos); DROP) \
|
X(",", COMMA, COMMA(tos); DROP) \
|
||||||
X("c,", CCOMMA, CCOMMA(tos); DROP) \
|
X("c,", CCOMMA, CCOMMA(tos); DROP) \
|
||||||
X(">flags", TOFLAGS, tos = *TOFLAGS(tos)) \
|
|
||||||
X(">params", TOPARAMS, tos = *TOPARAMS(tos)) \
|
|
||||||
X(">size", TOSIZE, tos = TOSIZE(tos)) \
|
|
||||||
X(">link&", TOLINKAT, tos = (cell_t) TOLINK(tos)) \
|
|
||||||
X(">link", TOLINK, tos = *TOLINK(tos)) \
|
|
||||||
X(">name", TONAME, DUP; *sp = (cell_t) TONAME(tos); tos = *TONAMELEN(tos)) \
|
|
||||||
X(">body", TOBODY, tos = (cell_t) TOBODY(tos)) \
|
|
||||||
XV(internals, "'heap", THEAP, DUP; tos = (cell_t) &g_sys->heap) \
|
XV(internals, "'heap", THEAP, DUP; tos = (cell_t) &g_sys->heap) \
|
||||||
Y(current, DUP; tos = (cell_t) &g_sys->current) \
|
Y(current, DUP; tos = (cell_t) &g_sys->current) \
|
||||||
XV(internals, "'context", TCONTEXT, DUP; tos = (cell_t) &g_sys->context) \
|
XV(internals, "'context", TCONTEXT, DUP; tos = (cell_t) &g_sys->context) \
|
||||||
@ -89,8 +80,5 @@
|
|||||||
XV(internals, "'argc", ARGC, DUP; tos = (cell_t) &g_sys->argc) \
|
XV(internals, "'argc", ARGC, DUP; tos = (cell_t) &g_sys->argc) \
|
||||||
XV(internals, "'argv", ARGV, DUP; tos = (cell_t) &g_sys->argv) \
|
XV(internals, "'argv", ARGV, DUP; tos = (cell_t) &g_sys->argv) \
|
||||||
XV(internals, "'runner", RUNNER, DUP; tos = (cell_t) &g_sys->runner) \
|
XV(internals, "'runner", RUNNER, DUP; tos = (cell_t) &g_sys->runner) \
|
||||||
YV(internals, fill32, cell_t c = tos; DROP; cell_t n = tos; DROP; \
|
|
||||||
uint32_t *a = (uint32_t *) tos; DROP; \
|
|
||||||
for (;n;--n) *a++ = c) \
|
|
||||||
Y(context, DUP; tos = (cell_t) (g_sys->context + 1)) \
|
Y(context, DUP; tos = (cell_t) (g_sys->context + 1)) \
|
||||||
Y(latestxt, DUP; tos = (cell_t) g_sys->latestxt)
|
Y(latestxt, DUP; tos = (cell_t) g_sys->latestxt)
|
||||||
@ -54,8 +54,6 @@
|
|||||||
( Dictionary )
|
( Dictionary )
|
||||||
: here ( -- a ) 'sys @ ;
|
: here ( -- a ) 'sys @ ;
|
||||||
: allot ( n -- ) 'sys +! ;
|
: allot ( n -- ) 'sys +! ;
|
||||||
: aligned ( a -- a ) cell 1 - dup >r + r> invert and ;
|
|
||||||
: 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 ;
|
||||||
|
|
||||||
@ -68,6 +66,7 @@
|
|||||||
sys: 'tib sys: #tib sys: >in
|
sys: 'tib sys: #tib sys: >in
|
||||||
sys: state sys: base
|
sys: state sys: base
|
||||||
sys: 'argc sys: 'argv sys: 'runner
|
sys: 'argc sys: 'argv sys: 'runner
|
||||||
|
drop
|
||||||
: context ( -- a ) 'context @ cell+ ;
|
: context ( -- a ) 'context @ cell+ ;
|
||||||
: latestxt ( -- xt ) 'latestxt @ ;
|
: latestxt ( -- xt ) 'latestxt @ ;
|
||||||
|
|
||||||
@ -77,15 +76,6 @@
|
|||||||
: ' bl parse 2dup find dup >r -rot r> 0= 'notfound @ execute 2drop ;
|
: ' bl parse 2dup find dup >r -rot r> 0= 'notfound @ execute 2drop ;
|
||||||
: literal aliteral ; immediate
|
: literal aliteral ; immediate
|
||||||
|
|
||||||
( Dictionary Format )
|
|
||||||
: >flags& ( xt -- a ) cell - ; : >flags ( xt -- flags ) >flags& c@ ;
|
|
||||||
: >name-length ( xt -- n ) >flags& 1+ c@ ;
|
|
||||||
: >params ( xt -- n ) >flags& 2 + sw@ $ffff and ;
|
|
||||||
: >size ( xt -- n ) dup >params cells swap >name-length aligned + 3 cells + ;
|
|
||||||
: >link& ( xt -- a ) 2 cells - ; : >link ( xt -- a ) >link& @ ;
|
|
||||||
: >name ( xt -- a n ) dup >name-length swap >link& over aligned - swap ;
|
|
||||||
: >body ( xt -- a ) dup @ [ ' >flags @ ] literal = 2 + cells + ;
|
|
||||||
|
|
||||||
: f= ( r r -- f ) f- f0= ;
|
: f= ( r r -- f ) f- f0= ;
|
||||||
: f< ( r r -- f ) f- f0< ;
|
: f< ( r r -- f ) f- f0< ;
|
||||||
: f> ( r r -- f ) fswap f< ;
|
: f> ( r r -- f ) fswap f< ;
|
||||||
@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
3.14159265359e fconstant pi
|
3.14159265359e fconstant pi
|
||||||
|
|
||||||
: fill32 ( a n v ) swap >r swap r> 0 ?do 2dup ! cell+ loop 2drop ;
|
|
||||||
|
|
||||||
( Transfer internals that are extra opcodes )
|
( Transfer internals that are extra opcodes )
|
||||||
internals definitions
|
internals definitions
|
||||||
transfer{
|
transfer{
|
||||||
27
common/tier2_forth.fs
Normal file
27
common/tier2_forth.fs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
\ Copyright 2022 Bradley D. Nelson
|
||||||
|
\
|
||||||
|
\ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
\ you may not use this file except in compliance with the License.
|
||||||
|
\ You may obtain a copy of the License at
|
||||||
|
\
|
||||||
|
\ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
\
|
||||||
|
\ Unless required by applicable law or agreed to in writing, software
|
||||||
|
\ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
\ See the License for the specific language governing permissions and
|
||||||
|
\ limitations under the License.
|
||||||
|
|
||||||
|
( Dictionary Format )
|
||||||
|
: >flags& ( xt -- a ) cell - ; : >flags ( xt -- flags ) >flags& c@ ;
|
||||||
|
: >name-length ( xt -- n ) >flags& 1+ c@ ;
|
||||||
|
: >params ( xt -- n ) >flags& 2 + sw@ $ffff and ;
|
||||||
|
: >size ( xt -- n ) dup >params cells swap >name-length aligned + 3 cells + ;
|
||||||
|
: >link& ( xt -- a ) 2 cells - ; : >link ( xt -- a ) >link& @ ;
|
||||||
|
: >name ( xt -- a n ) dup >name-length swap >link& over aligned - swap ;
|
||||||
|
: >body ( xt -- a ) dup @ [ ' >flags @ ] literal = 2 + cells + ;
|
||||||
|
|
||||||
|
: aligned ( a -- a ) cell 1 - dup >r + r> invert and ;
|
||||||
|
: align here aligned here - allot ;
|
||||||
|
|
||||||
|
: fill32 ( a n v ) swap >r swap r> 0 ?do 2dup ! cell+ loop 2drop ;
|
||||||
27
common/tier2_opcodes.h
Normal file
27
common/tier2_opcodes.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2021 Bradley D. Nelson
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#define TIER2_OPCODE_LIST \
|
||||||
|
X(">flags", TOFLAGS, tos = *TOFLAGS(tos)) \
|
||||||
|
X(">params", TOPARAMS, tos = *TOPARAMS(tos)) \
|
||||||
|
X(">size", TOSIZE, tos = TOSIZE(tos)) \
|
||||||
|
X(">link&", TOLINKAT, tos = (cell_t) TOLINK(tos)) \
|
||||||
|
X(">link", TOLINK, tos = *TOLINK(tos)) \
|
||||||
|
X(">name", TONAME, DUP; *sp = (cell_t) TONAME(tos); tos = *TONAMELEN(tos)) \
|
||||||
|
X(">body", TOBODY, tos = (cell_t) TOBODY(tos)) \
|
||||||
|
Y(aligned, tos = CELL_ALIGNED(tos)) \
|
||||||
|
Y(align, g_sys->heap = (cell_t *) CELL_ALIGNED(g_sys->heap)) \
|
||||||
|
YV(internals, fill32, cell_t c = tos; DROP; cell_t n = tos; DROP; \
|
||||||
|
uint32_t *a = (uint32_t *) tos; DROP; \
|
||||||
|
for (;n;--n) *a++ = c)
|
||||||
@ -13,8 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "esp32/options.h"
|
#include "esp32/options.h"
|
||||||
#include "common/opcodes.h"
|
#include "common/tier0_opcodes.h"
|
||||||
#include "common/extra_opcodes.h"
|
#include "common/tier1_opcodes.h"
|
||||||
|
#include "common/tier2_opcodes.h"
|
||||||
#include "common/floats.h"
|
#include "common/floats.h"
|
||||||
#include "common/calling.h"
|
#include "common/calling.h"
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
{{options}}
|
{{options}}
|
||||||
{{opcodes}}
|
{{tier0_opcodes}}
|
||||||
{{extra_opcodes}}
|
{{tier1_opcodes}}
|
||||||
|
{{tier2_opcodes}}
|
||||||
{{floats}}
|
{{floats}}
|
||||||
{{calling}}
|
{{calling}}
|
||||||
{{builtins.h}}
|
{{builtins.h}}
|
||||||
|
|||||||
@ -15,8 +15,9 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "common/opcodes.h"
|
#include "common/tier0_opcodes.h"
|
||||||
#include "common/extra_opcodes.h"
|
#include "common/tier1_opcodes.h"
|
||||||
|
#include "common/tier2_opcodes.h"
|
||||||
#include "common/floats.h"
|
#include "common/floats.h"
|
||||||
#include "common/calling.h"
|
#include "common/calling.h"
|
||||||
#include "common/calls.h"
|
#include "common/calls.h"
|
||||||
|
|||||||
@ -98,7 +98,7 @@ additional non-essential extra opcodes were added in place of high-level
|
|||||||
words.</b></p>
|
words.</b></p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
See <a href="https://github.com/flagxor/ueforth/blob/main/common/opcodes.h">opcodes.h</a>.
|
See <a href="https://github.com/flagxor/ueforth/blob/main/common/tier0_opcodes.h">tier0_opcodes.h</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@ -19,7 +19,8 @@
|
|||||||
#define SSMOD_FUNC SSMOD_FUNC
|
#define SSMOD_FUNC SSMOD_FUNC
|
||||||
#define COMMA COMMA
|
#define COMMA COMMA
|
||||||
|
|
||||||
#include "common/opcodes.h"
|
#include "common/tier0_opcodes.h"
|
||||||
|
#include "common/tier1_opcodes.h"
|
||||||
#include "common/floats.h"
|
#include "common/floats.h"
|
||||||
#include "common/bits.h"
|
#include "common/bits.h"
|
||||||
|
|
||||||
@ -32,7 +33,8 @@
|
|||||||
enum {
|
enum {
|
||||||
#define Z(flags, name, op, code) OP_ ## op,
|
#define Z(flags, name, op, code) OP_ ## op,
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,7 +56,8 @@ int main(int argc, char *argv[]) {
|
|||||||
#define Z(flags, name, op, code) \
|
#define Z(flags, name, op, code) \
|
||||||
printf(" case %d: // %s\n %s; break;\n", OP_ ## op, name, #code);
|
printf(" case %d: // %s\n %s; break;\n", OP_ ## op, name, #code);
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
} else if (argc == 2 && strcmp(argv[1], "dict") == 0) {
|
} else if (argc == 2 && strcmp(argv[1], "dict") == 0) {
|
||||||
#define V(name) \
|
#define V(name) \
|
||||||
@ -67,7 +70,8 @@ int main(int argc, char *argv[]) {
|
|||||||
((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, \
|
((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, \
|
||||||
(VOC_ ## flags & 0xff), OP_ ## op);
|
(VOC_ ## flags & 0xff), OP_ ## op);
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
} else if (argc == 2 && strcmp(argv[1], "sys") == 0) {
|
} else if (argc == 2 && strcmp(argv[1], "sys") == 0) {
|
||||||
G_SYS *g_sys = 0;
|
G_SYS *g_sys = 0;
|
||||||
|
|||||||
@ -37,19 +37,29 @@ cases = ReplaceAll(cases, 'DUP;', '*++sp = tos;');
|
|||||||
|
|
||||||
cases = ReplaceAll(cases, 'tos += sizeof(float)', 'tos = (tos + 4)|0');
|
cases = ReplaceAll(cases, 'tos += sizeof(float)', 'tos = (tos + 4)|0');
|
||||||
cases = ReplaceAll(cases, 'tos *= sizeof(float)', 'tos = (tos * 4)|0');
|
cases = ReplaceAll(cases, 'tos *= sizeof(float)', 'tos = (tos * 4)|0');
|
||||||
|
cases = ReplaceAll(cases, 'tos += sizeof(cell_t)', 'tos = (tos + 4)|0');
|
||||||
|
cases = ReplaceAll(cases, 'tos *= sizeof(cell_t)', 'tos = (tos * 4)|0');
|
||||||
|
|
||||||
cases = ReplaceAll(cases, 'tos += *sp--', 'tos = (tos + *sp)|0; --sp');
|
cases = ReplaceAll(cases, 'tos += *sp--', 'tos = (tos + *sp)|0; --sp');
|
||||||
|
cases = ReplaceAll(cases, 'tos = (*sp--) - tos', 'tos = (*sp - tos)|0; --sp');
|
||||||
|
cases = ReplaceAll(cases, 'tos *= *sp--', 'tos = imul(tos, *sp); --sp');
|
||||||
|
cases = ReplaceAll(cases, ' -tos', ' (-tos)|0');
|
||||||
|
cases = ReplaceAll(cases, '++tos', 'tos = (tos + 1)|0');
|
||||||
|
cases = ReplaceAll(cases, '--tos', 'tos = (tos - 1)|0');
|
||||||
|
|
||||||
cases = ReplaceAll(cases, /tos (.)= /, 'tos = tos $1 ');
|
cases = ReplaceAll(cases, /tos (.)= /, 'tos = tos $1 ');
|
||||||
cases = ReplaceAll(cases, '*((cell_t *) *ip) = ', 'i32[i32[ip>>2]>>2] = ');
|
cases = ReplaceAll(cases, '*((cell_t *) *ip) = ', 'i32[i32[ip>>2]>>2] = ');
|
||||||
cases = ReplaceAll(cases, /[*](.)p[+][+]/, '*$1p, ++$1p');
|
cases = ReplaceAll(cases, /[*](.)p[+][+]/, '*$1p, ++$1p');
|
||||||
cases = ReplaceAll(cases, /[*](.)p[-][-]/, '*$1p, --$1p');
|
cases = ReplaceAll(cases, /[*](.)p[-][-]/, '*$1p, --$1p');
|
||||||
cases = ReplaceAll(cases, /[*][+][+](.)p/, '++$1p, *$1p');
|
cases = ReplaceAll(cases, /[*][+][+](.)p/, '++$1p, *$1p');
|
||||||
cases = ReplaceAll(cases, '*(cell_t *) tos = ', 'i32[tos>>2] = ');
|
cases = ReplaceAll(cases, '*(cell_t *) tos = ', 'i32[tos>>2] = ');
|
||||||
|
cases = ReplaceAll(cases, '((cell_t *) tos)[1] = ', 'i32[(tos + 4)>>2] = ');
|
||||||
cases = ReplaceAll(cases, '*(int32_t *) tos = ', 'i32[tos>>2] = ');
|
cases = ReplaceAll(cases, '*(int32_t *) tos = ', 'i32[tos>>2] = ');
|
||||||
cases = ReplaceAll(cases, '*(int16_t *) tos = ', 'i16[tos>>1] = ');
|
cases = ReplaceAll(cases, '*(int16_t *) tos = ', 'i16[tos>>1] = ');
|
||||||
cases = ReplaceAll(cases, '*(uint8_t *) tos = ', 'u8[tos] = ');
|
cases = ReplaceAll(cases, '*(uint8_t *) tos = ', 'u8[tos] = ');
|
||||||
cases = ReplaceAll(cases, '*(float *) tos = ', 'f32[tos>>2] = ');
|
cases = ReplaceAll(cases, '*(float *) tos = ', 'f32[tos>>2] = ');
|
||||||
cases = ReplaceAll(cases, '*(cell_t *) tos', '(i32[tos>>2]|0)');
|
cases = ReplaceAll(cases, '*(cell_t *) tos', '(i32[tos>>2]|0)');
|
||||||
|
cases = ReplaceAll(cases, '((cell_t *) tos)[1]', '(i32[(tos + 4)>>2]|0)');
|
||||||
cases = ReplaceAll(cases, '*(int32_t *) tos', '(i32[tos>>2]|0)');
|
cases = ReplaceAll(cases, '*(int32_t *) tos', '(i32[tos>>2]|0)');
|
||||||
cases = ReplaceAll(cases, '*(uint32_t *) tos', '(i32[tos>>2]>>>0)');
|
cases = ReplaceAll(cases, '*(uint32_t *) tos', '(i32[tos>>2]>>>0)');
|
||||||
cases = ReplaceAll(cases, '*(int16_t *) tos', '(i16[tos>>1]|0)');
|
cases = ReplaceAll(cases, '*(int16_t *) tos', '(i16[tos>>1]|0)');
|
||||||
@ -90,12 +100,15 @@ cases = ReplaceAll(cases, '(float *) ', '');
|
|||||||
cases = ReplaceAll(cases, '(float) ', '');
|
cases = ReplaceAll(cases, '(float) ', '');
|
||||||
cases = ReplaceAll(cases, '0.0f', 'fround(0.0)');
|
cases = ReplaceAll(cases, '0.0f', 'fround(0.0)');
|
||||||
cases = ReplaceAll(cases, '1.0f', 'fround(1.0)');
|
cases = ReplaceAll(cases, '1.0f', 'fround(1.0)');
|
||||||
|
cases = ReplaceAll(cases, "' '", '32');
|
||||||
|
cases = ReplaceAll(cases, "'\\n'", '10');
|
||||||
cases = ReplaceAll(cases, /[(]ucell_t[)] ([^ ;)]+)/, '($1>>>0)');
|
cases = ReplaceAll(cases, /[(]ucell_t[)] ([^ ;)]+)/, '($1>>>0)');
|
||||||
|
|
||||||
cases = ReplaceAll(cases, '*(w + 4)', '(i32[(w + 4)>>2]|0)');
|
cases = ReplaceAll(cases, '*(w + 4)', '(i32[(w + 4)>>2]|0)');
|
||||||
cases = ReplaceAll(cases, 'w + 4 * 2', '(w+8)|0');
|
cases = ReplaceAll(cases, 'w + 4 * 2', '(w+8)|0');
|
||||||
cases = ReplaceAll(cases, 'w + 4', '(w+4)|0');
|
cases = ReplaceAll(cases, 'w + 4', '(w+4)|0');
|
||||||
|
|
||||||
|
cases = ReplaceAll(cases, '(g_sys->context + 1)', '(i32[g_sys_context>>2]|0 + 4)|0');
|
||||||
cases = ReplaceAll(cases, '&g_sys->builtins->code', '((i32[g_sys_builtins>>2] + 8)|0)');
|
cases = ReplaceAll(cases, '&g_sys->builtins->code', '((i32[g_sys_builtins>>2] + 8)|0)');
|
||||||
cases = ReplaceAll(cases, /[&]g_sys[-][>]([A-Za-z_]+)/, 'g_sys_$1');
|
cases = ReplaceAll(cases, /[&]g_sys[-][>]([A-Za-z_]+)/, 'g_sys_$1');
|
||||||
cases = ReplaceAll(cases, /g_sys[-][>]([A-Za-z_]+) [=] /, 'i32[g_sys_$1>>2] = ');
|
cases = ReplaceAll(cases, /g_sys[-][>]([A-Za-z_]+) [=] /, 'i32[g_sys_$1>>2] = ');
|
||||||
|
|||||||
@ -19,8 +19,9 @@
|
|||||||
enum {
|
enum {
|
||||||
#define Z(flags, name, op, code) OP_ ## op,
|
#define Z(flags, name, op, code) OP_ ## op,
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
EXTRA_OPCODE_LIST
|
TIER2_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,8 +31,9 @@ static cell_t *forth_run(cell_t *init_rp) {
|
|||||||
name, ((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, sizeof(name) - 1, \
|
name, ((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, sizeof(name) - 1, \
|
||||||
(VOC_ ## flags & 0xff), (void *) OP_ ## op,
|
(VOC_ ## flags & 0xff), (void *) OP_ ## op,
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
EXTRA_OPCODE_LIST
|
TIER2_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
};
|
};
|
||||||
@ -51,8 +53,9 @@ work:
|
|||||||
switch (*(cell_t *) w & 0xff) {
|
switch (*(cell_t *) w & 0xff) {
|
||||||
#define Z(flags, name, op, code) case OP_ ## op: { code; } NEXT;
|
#define Z(flags, name, op, code) case OP_ ## op: { code; } NEXT;
|
||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
EXTRA_OPCODE_LIST
|
TIER2_OPCODE_LIST
|
||||||
OPCODE_LIST
|
TIER1_OPCODE_LIST
|
||||||
|
TIER0_OPCODE_LIST
|
||||||
#undef Z
|
#undef Z
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,8 +27,9 @@
|
|||||||
if (*sp < 0) { *sp += tos; tos = b - 1; } else { tos = b; }
|
if (*sp < 0) { *sp += tos; tos = b - 1; } else { tos = b; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "common/opcodes.h"
|
#include "common/tier0_opcodes.h"
|
||||||
#include "common/extra_opcodes.h"
|
#include "common/tier1_opcodes.h"
|
||||||
|
#include "common/tier2_opcodes.h"
|
||||||
#include "common/floats.h"
|
#include "common/floats.h"
|
||||||
#include "common/calling.h"
|
#include "common/calling.h"
|
||||||
#include "common/calls.h"
|
#include "common/calls.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user