Hacky version of SSMOD for now on web.

This commit is contained in:
Brad Nelson
2022-07-13 22:12:14 -07:00
parent 09fb5b9bb9
commit ff31b4e739
4 changed files with 21 additions and 5 deletions

View File

@ -261,9 +261,7 @@ $(GEN)/web_sys.js: $(GEN)/dump_web_opcodes | $(GEN)
$< sys >$@
WEB_BOOT = $(COMMON_PHASE1e) \
posix/posix.fs posix/allocation.fs posix/termios.fs \
$(COMMON_PHASE2) \
posix/autoboot.fs \
common/fini.fs
$(GEN)/web_boot.js: tools/source_to_string.js $(WEB_BOOT) | $(GEN)
$< -web boot $(VERSION) $(REVISION) $(WEB_BOOT) >$@

View File

@ -105,6 +105,7 @@ int main(int argc, char *argv[]) {
EMITSYS(DOCREATE_OP);
EMITSYS(builtins);
printf(" const OP_DOCREATE = %d;\n", OP_DOCREATE);
printf(" const OP_DODOES = %d;\n", OP_DODOES);
printf(" const OP_DOCOL = %d;\n", OP_DOCOL);
printf(" const OP_DOVAR = %d;\n", OP_DOVAR);
printf(" const OP_DOCON = %d;\n", OP_DOCON);

View File

@ -118,7 +118,10 @@ cases = ReplaceAll(cases, /ADDROF[(]([^)]+)[)]/, 'OP_$1');
cases = ReplaceAll(cases, 'return rp', 'i32[g_sys_rp>>2] = rp | 0; return');
cases = ReplaceAll(cases, 'SSMOD_FUNC', '');
cases = ReplaceAll(cases, 'SSMOD_FUNC',
'sp = (sp + 4)|0; i32[sp>>2] = tos|0; ' +
'SSMOD(sp|0); tos = i32[sp>>2]|0; sp = (sp - 8)|0');
// Keep Together vvv
cases = ReplaceAll(cases, /tos ([^=]?)= /, 'txx $1= ');
cases = ReplaceAll(cases, ' tos', ' (tos|0)');

View File

@ -86,6 +86,11 @@ function TOBODY(xt) {
return xt + (i32[xt>>2] === OP_DOCREATE || i32[xt>>2] === OP_DODOES ? 2 : 1);
}
function DOES(ip) {
i32[i32[i32[g_sys_current>>2]>>2]>>2] = OP_DODOES;
i32[(i32[i32[g_sys_current>>2]>>2] + 4)>>2] = ip;
}
function BUILTIN_ITEM(i) {
return i32[g_sys_builtins>>2] + 4 * 3 * i;
}
@ -143,6 +148,15 @@ function CCOMMA(value) {
i32[g_sys_heap>>2]++;
}
function SSMOD(sp) {
var a = i32[(sp - 8)>>2];
var b = i32[(sp - 4)>>2];
var c = i32[sp>>2];
a *= b;
i32[(sp - 8)>>2] = a / c;
i32[sp>>2] = a % c;
}
function Finish() {
if (i32[g_sys_latestxt>>2] && !i32[TOPARAMS(i32[g_sys_latestxt>>2])>>2]) {
var sz = i32[g_sys_heap>>2] - (g_sys_latestxt + 4);
@ -518,8 +532,8 @@ var ffi = {
'log': function(n) { console.log(n); },
'COMMA': function(n) { COMMA(n); },
'CCOMMA': function(n) { COMMA(n); },
'SSMOD': function() { console.log('ssmod'); },
'DOES': function() { console.log('does'); },
'SSMOD': function(sp) { SSMOD(sp); },
'DOES': function(ip) { DOES(ip); },
'DOIMMEDIATE': function() { DOIMMEDIATE(); },
'UNSMUDGE': function() { UNSMUDGE(); },
};