Automate g_sys structure handling for web.
This commit is contained in:
6
Makefile
6
Makefile
@ -242,6 +242,9 @@ $(GEN)/web_cases.js: $(GEN)/dump_web_opcodes | $(GEN)
|
|||||||
$(GEN)/web_dict.js: $(GEN)/dump_web_opcodes | $(GEN)
|
$(GEN)/web_dict.js: $(GEN)/dump_web_opcodes | $(GEN)
|
||||||
$< dict >$@
|
$< dict >$@
|
||||||
|
|
||||||
|
$(GEN)/web_sys.js: $(GEN)/dump_web_opcodes | $(GEN)
|
||||||
|
$< sys >$@
|
||||||
|
|
||||||
WEB_BOOT = $(COMMON_PHASE1) common/extra.fs \
|
WEB_BOOT = $(COMMON_PHASE1) common/extra.fs \
|
||||||
posix/posix.fs posix/allocation.fs posix/termios.fs \
|
posix/posix.fs posix/allocation.fs posix/termios.fs \
|
||||||
$(COMMON_PHASE2) \
|
$(COMMON_PHASE2) \
|
||||||
@ -297,7 +300,8 @@ $(WEB)/ueforth.js: \
|
|||||||
web/web.template.js \
|
web/web.template.js \
|
||||||
$(GEN)/web_boot.js \
|
$(GEN)/web_boot.js \
|
||||||
$(GEN)/web_dict.js \
|
$(GEN)/web_dict.js \
|
||||||
$(GEN)/web_cases.js | $(WEB)
|
$(GEN)/web_cases.js \
|
||||||
|
$(GEN)/web_sys.js | $(WEB)
|
||||||
$^ >$@
|
$^ >$@
|
||||||
|
|
||||||
# ---- POSIX ----
|
# ---- POSIX ----
|
||||||
|
|||||||
@ -16,3 +16,23 @@
|
|||||||
#define SMUDGE 2
|
#define SMUDGE 2
|
||||||
#define BUILTIN_FORK 4
|
#define BUILTIN_FORK 4
|
||||||
#define BUILTIN_MARK 8
|
#define BUILTIN_MARK 8
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
cell_t *heap, **current, ***context;
|
||||||
|
cell_t *latestxt, 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;
|
||||||
|
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;
|
||||||
|
void *DOCREATE_OP;
|
||||||
|
const BUILTIN_WORD *builtins;
|
||||||
|
} G_SYS;
|
||||||
|
|||||||
@ -43,25 +43,6 @@ enum {
|
|||||||
#undef V
|
#undef V
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
cell_t *heap, **current, ***context;
|
|
||||||
cell_t *latestxt, 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;
|
|
||||||
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;
|
|
||||||
void *DOCREATE_OP;
|
|
||||||
const BUILTIN_WORD *builtins;
|
|
||||||
} G_SYS;
|
|
||||||
static G_SYS *g_sys = 0;
|
static G_SYS *g_sys = 0;
|
||||||
|
|
||||||
static cell_t convert(const char *pos, cell_t n, cell_t base, cell_t *ret) {
|
static cell_t convert(const char *pos, cell_t n, cell_t base, cell_t *ret) {
|
||||||
|
|||||||
@ -36,6 +36,7 @@ PLATFORM_SIMULATED_OPCODE_LIST
|
|||||||
#define heap_caps_get_largest_free_block(x) SIM_HEAP_SIZE
|
#define heap_caps_get_largest_free_block(x) SIM_HEAP_SIZE
|
||||||
#define heap_caps_get_free_size(x) SIM_HEAP_SIZE
|
#define heap_caps_get_free_size(x) SIM_HEAP_SIZE
|
||||||
|
|
||||||
|
#include "common/bits.h"
|
||||||
#include "common/core.h"
|
#include "common/core.h"
|
||||||
#include "common/interp.h"
|
#include "common/interp.h"
|
||||||
#include "gen/esp32_boot.h"
|
#include "gen/esp32_boot.h"
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#define VOCABULARY_LIST V(forth) V(internals)
|
#define VOCABULARY_LIST V(forth) V(internals)
|
||||||
|
|
||||||
|
#include "common/bits.h"
|
||||||
#include "common/core.h"
|
#include "common/core.h"
|
||||||
#include "common/interp.h"
|
#include "common/interp.h"
|
||||||
|
|
||||||
|
|||||||
@ -65,8 +65,39 @@ int main(int argc, char *argv[]) {
|
|||||||
PLATFORM_OPCODE_LIST
|
PLATFORM_OPCODE_LIST
|
||||||
OPCODE_LIST
|
OPCODE_LIST
|
||||||
#undef XV
|
#undef XV
|
||||||
|
} else if (argc == 2 && strcmp(argv[1], "sys") == 0) {
|
||||||
|
G_SYS *g_sys = 0;
|
||||||
|
#define G_SYS 256
|
||||||
|
printf(" const g_sys = %d;\n", G_SYS);
|
||||||
|
#define EMITSYS(name) \
|
||||||
|
printf(" const g_sys_%s = %d;\n", #name, 256 + 4 * (((cell_t*) g_sys) - ((cell_t *) &g_sys->name)));
|
||||||
|
EMITSYS(heap);
|
||||||
|
EMITSYS(current);
|
||||||
|
EMITSYS(context);
|
||||||
|
EMITSYS(latestxt);
|
||||||
|
EMITSYS(notfound);
|
||||||
|
EMITSYS(heap_start);
|
||||||
|
EMITSYS(heap_size);
|
||||||
|
EMITSYS(stack_cells);
|
||||||
|
EMITSYS(boot);
|
||||||
|
EMITSYS(boot_size);
|
||||||
|
EMITSYS(tib);
|
||||||
|
EMITSYS(ntib);
|
||||||
|
EMITSYS(tin);
|
||||||
|
EMITSYS(state);
|
||||||
|
EMITSYS(base);
|
||||||
|
EMITSYS(argc);
|
||||||
|
EMITSYS(argv);
|
||||||
|
EMITSYS(runner);
|
||||||
|
EMITSYS(rp);
|
||||||
|
EMITSYS(DOLIT_XT);
|
||||||
|
EMITSYS(DOFLIT_XT);
|
||||||
|
EMITSYS(DOEXIT_XT);
|
||||||
|
EMITSYS(YIELD_XT);
|
||||||
|
EMITSYS(DOCREATE_OP);
|
||||||
|
EMITSYS(builtins);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "USAGE: %s cases/dict\n", argv[1]);
|
fprintf(stderr, "USAGE: %s cases/dict/sys\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -18,6 +18,7 @@ var code = fs.readFileSync(process.argv[2]).toString();
|
|||||||
var boot = fs.readFileSync(process.argv[3]).toString();
|
var boot = fs.readFileSync(process.argv[3]).toString();
|
||||||
var dict = fs.readFileSync(process.argv[4]).toString();
|
var dict = fs.readFileSync(process.argv[4]).toString();
|
||||||
var cases = fs.readFileSync(process.argv[5]).toString();
|
var cases = fs.readFileSync(process.argv[5]).toString();
|
||||||
|
var sys = fs.readFileSync(process.argv[6]).toString();
|
||||||
|
|
||||||
function ReplaceAll(haystack, needle, replacement) {
|
function ReplaceAll(haystack, needle, replacement) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -98,5 +99,6 @@ cases = ReplaceAll(cases, '; ', ';\n ');
|
|||||||
code = code.replace('{{boot}}', function() { return boot; });
|
code = code.replace('{{boot}}', function() { return boot; });
|
||||||
code = code.replace('{{dict}}', function() { return dict; });
|
code = code.replace('{{dict}}', function() { return dict; });
|
||||||
code = code.replace('{{cases}}', function() { return cases; });
|
code = code.replace('{{cases}}', function() { return cases; });
|
||||||
|
code = code.replace(/[{][{]sys[}][}]/g, function() { return sys; });
|
||||||
|
|
||||||
console.log(code);
|
console.log(code);
|
||||||
|
|||||||
@ -26,32 +26,8 @@ var heap = new ArrayBuffer(HEAP_SIZE);
|
|||||||
var i32 = new Int32Array(heap);
|
var i32 = new Int32Array(heap);
|
||||||
var u8 = new Uint8Array(heap);
|
var u8 = new Uint8Array(heap);
|
||||||
var objects = [SetEval];
|
var objects = [SetEval];
|
||||||
var g_sys = 256; // Placed past a gap.
|
|
||||||
var g_sys_heap = g_sys + 0 * 4;
|
{{sys}}
|
||||||
var g_sys_current = g_sys + 1 * 4;
|
|
||||||
var g_sys_context = g_sys + 2 * 4;
|
|
||||||
var g_sys_latestxt = g_sys + 3 * 4;
|
|
||||||
var g_sys_notfound = g_sys + 4 * 4;
|
|
||||||
var g_sys_heap_start = g_sys + 5 * 4;
|
|
||||||
var g_sys_heap_size = g_sys + 6 * 4;
|
|
||||||
var g_sys_stack_cells = g_sys + 7 * 4;
|
|
||||||
var g_sys_boot = g_sys + 8 * 4;
|
|
||||||
var g_sys_boot_size = g_sys + 9 * 4;
|
|
||||||
var g_sys_tib = g_sys + 10 * 4;
|
|
||||||
var g_sys_ntib = g_sys + 11 * 4;
|
|
||||||
var g_sys_tin = g_sys + 12 * 4;
|
|
||||||
var g_sys_state = g_sys + 13 * 4;
|
|
||||||
var g_sys_base = g_sys + 14 * 4;
|
|
||||||
var g_sys_argc = g_sys + 15 * 4;
|
|
||||||
var g_sys_argv = g_sys + 16 * 4;
|
|
||||||
var g_sys_runner = g_sys + 17 * 4;
|
|
||||||
var g_sys_rp = g_sys + 18 * 4;
|
|
||||||
var g_sys_DOLIT_XT = g_sys + 19 * 4;
|
|
||||||
var g_sys_DOFLIT_XT = g_sys + 20 * 4;
|
|
||||||
var g_sys_DOEXIT_XT = g_sys + 21 * 4;
|
|
||||||
var g_sys_YIELD_XT = g_sys + 22 * 4;
|
|
||||||
var g_sys_DOCREATE_OP = g_sys + 23 * 4;
|
|
||||||
var g_sys_builtins = g_sys + 24 * 4;
|
|
||||||
|
|
||||||
function SetEval(sp) {
|
function SetEval(sp) {
|
||||||
var index = i32[sp--];
|
var index = i32[sp--];
|
||||||
@ -119,7 +95,7 @@ function comma(value) {
|
|||||||
|
|
||||||
function create(name, flags, opcode) {
|
function create(name, flags, opcode) {
|
||||||
i32[g_sys_heap>>2] = Load(i32[g_sys_heap>>2], name); // name
|
i32[g_sys_heap>>2] = Load(i32[g_sys_heap>>2], name); // name
|
||||||
g_sys_heap = (g_sys_heap + 3) & ~3;
|
i32[g_sys_heap>>2] = (i32[g_sys_heap>>2] + 3) & ~3;
|
||||||
|
|
||||||
i32[i32[g_sys_heap>>2]>>2] = name.length; // length
|
i32[i32[g_sys_heap>>2]>>2] = name.length; // length
|
||||||
i32[g_sys_heap>>2] += 4;
|
i32[g_sys_heap>>2] += 4;
|
||||||
@ -231,39 +207,14 @@ function VM(stdlib, foreign, heap) {
|
|||||||
var memmove = foreign.memmove;
|
var memmove = foreign.memmove;
|
||||||
var convert = foreign.convert;
|
var convert = foreign.convert;
|
||||||
var evaluate1 = foreign.evaluate1;
|
var evaluate1 = foreign.evaluate1;
|
||||||
var log = foreign.log;
|
var emitlog = foreign.log;
|
||||||
|
|
||||||
var u8 = new stdlib.Uint8Array(heap);
|
var u8 = new stdlib.Uint8Array(heap);
|
||||||
var i16 = new stdlib.Int16Array(heap);
|
var i16 = new stdlib.Int16Array(heap);
|
||||||
var i32 = new stdlib.Int32Array(heap);
|
var i32 = new stdlib.Int32Array(heap);
|
||||||
var f32 = new stdlib.Float32Array(heap);
|
var f32 = new stdlib.Float32Array(heap);
|
||||||
|
|
||||||
const g_sys = 256;
|
{{sys}}
|
||||||
var g_sys_heap = g_sys + 0 * 4;
|
|
||||||
var g_sys_current = g_sys + 1 * 4;
|
|
||||||
var g_sys_context = g_sys + 2 * 4;
|
|
||||||
var g_sys_latestxt = g_sys + 3 * 4;
|
|
||||||
var g_sys_notfound = g_sys + 4 * 4;
|
|
||||||
var g_sys_heap_start = g_sys + 5 * 4;
|
|
||||||
var g_sys_heap_size = g_sys + 6 * 4;
|
|
||||||
var g_sys_stack_cells = g_sys + 7 * 4;
|
|
||||||
var g_sys_boot = g_sys + 8 * 4;
|
|
||||||
var g_sys_boot_size = g_sys + 9 * 4;
|
|
||||||
var g_sys_tib = g_sys + 10 * 4;
|
|
||||||
var g_sys_ntib = g_sys + 11 * 4;
|
|
||||||
var g_sys_tin = g_sys + 12 * 4;
|
|
||||||
var g_sys_state = g_sys + 13 * 4;
|
|
||||||
var g_sys_base = g_sys + 14 * 4;
|
|
||||||
var g_sys_argc = g_sys + 15 * 4;
|
|
||||||
var g_sys_argv = g_sys + 16 * 4;
|
|
||||||
var g_sys_runner = g_sys + 17 * 4;
|
|
||||||
var g_sys_rp = g_sys + 18 * 4;
|
|
||||||
var g_sys_DOLIT_XT = g_sys + 19 * 4;
|
|
||||||
var g_sys_DOFLIT_XT = g_sys + 20 * 4;
|
|
||||||
var g_sys_DOEXIT_XT = g_sys + 21 * 4;
|
|
||||||
var g_sys_YIELD_XT = g_sys + 22 * 4;
|
|
||||||
var g_sys_DOCREATE_OP = g_sys + 23 * 4;
|
|
||||||
var g_sys_builtins = g_sys + 24 * 4;
|
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
var tos = 0;
|
var tos = 0;
|
||||||
@ -282,11 +233,11 @@ function VM(stdlib, foreign, heap) {
|
|||||||
tos = i32[sp>>2]|0; sp = (sp - 4)|0;
|
tos = i32[sp>>2]|0; sp = (sp - 4)|0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
w = i32[ip>>2]|0;
|
w = i32[ip>>2]|0;
|
||||||
log(ip|0);
|
emitlog(ip|0);
|
||||||
ip = (ip + 4)|0;
|
ip = (ip + 4)|0;
|
||||||
decode: for (;;) {
|
decode: for (;;) {
|
||||||
ir = u8[w]|0;
|
ir = u8[w]|0;
|
||||||
log(ir|0);
|
emitlog(ir|0);
|
||||||
switch (ir&0xff) {
|
switch (ir&0xff) {
|
||||||
{{cases}}
|
{{cases}}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -48,6 +48,7 @@ static LRESULT WindowProcShim(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
#define VOCABULARY_LIST V(forth) V(internals)
|
#define VOCABULARY_LIST V(forth) V(internals)
|
||||||
|
|
||||||
|
#include "common/bits.h"
|
||||||
#include "common/core.h"
|
#include "common/core.h"
|
||||||
#include "windows/interp.h"
|
#include "windows/interp.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user