duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit cea8998261c6915e453edc02bad8b0fb13da105d
parent f6985c0591295e6d2d573e7f2599fe95cb86ea6a
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed,  3 Aug 2022 17:26:17 -0400

cvm: add parse

Diffstat:
Mposix/tmpboot.fs | 2+-
Mposix/vm.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 61 insertions(+), 15 deletions(-)

diff --git a/posix/tmpboot.fs b/posix/tmpboot.fs @@ -1 +1 @@ -Hello world! +Hello 'X' diff --git a/posix/vm.c b/posix/vm.c @@ -15,14 +15,14 @@ The VM is little endian. #define MEMSZ 0x100000 // 1MB #define STACKSZ 0x800 #define RSTOP MEMSZ -#define PSTOP RSTOP-STACKSZ +#define PSTOP (RSTOP-STACKSZ) #define SYSVARSSZ 0x80 -#define SYSVARS (PSTOP-STACKSZ)-SYSVARSSZ +#define SYSVARS ((PSTOP-STACKSZ)-SYSVARSSZ) #define HERE SYSVARS -#define CURRENT HERE+4 -#define COMPILING CURRENT+4 -#define INRD COMPILING+4 -#define CURWORD INRD+4 +#define CURRENT (HERE+4) +#define COMPILING (CURRENT+4) +#define INRD (COMPILING+4) +#define CURWORD (INRD+4) #define HEREMAX SYSVARS @@ -542,7 +542,53 @@ static void WORD() { // op: 4f } } -#define OPCNT 0x50 +static void PARSE() { // op: 50 + dword s = ppop(); + byte len = gb(s++); + dword n = 0; + dword neg = 0; + byte c; + if (!len) goto err; + switch (gb(s)) { + case '\'': + if (len != 3) goto err; + if (gb(s+2) != '\'') goto err; + n = gb(s+1); + break; + case '$': + s++; len--; + if (!len) goto err; + while (len--) { + c = (gb(s++) | 0x20) - '0'; + if (c >= 10) { + c -= ('a'-'0'); + if (c >= 6) goto err; + c += 10; + } + n *= 16; + n += c; + } + break; + case '-': + neg = 0x80000000; + s++; len--; + if (!len) goto err; + default: // decimal + while (len--) { + c = gb(s++) - '0'; + if (c >= 10) goto err; + n *= 10; + n += c; + } + n |= neg; + } + ppush(n); ppush(1); + return; +err: + ppush(0); +} + +#define OPCNT 0x51 static void (*ops[OPCNT])() = { BR, CALL, RET, LIT, BYE, BYEFAIL, QUIT, ABORT, EXECUTE, CELL, VAL, ALIAS, DOES, SLIT, CBR, NEXT, @@ -553,7 +599,8 @@ static void (*ops[OPCNT])() = { CSTORE, CWRITE, WFETCH, WSTORE, FETCH, STORE, ADDSTORE, WRITE, ADD, SUB, MUL, DIVMOD, AND, OR, XOR, BOOL, NOT, LT, SHLC, SHRC, LSHIFT, RSHIFT, LITN, EXECUTEWR, - EXITWR, MOVE, MOVEWR, RTYPE, WNF, STACKCHK, MAYBEWORD, WORD}; + EXITWR, MOVE, MOVEWR, RTYPE, WNF, STACKCHK, MAYBEWORD, WORD, + PARSE}; static char *opnames[OPCNT] = { "(br)", NULL, NULL, NULL, "bye", "bytefail", "quit", "(abort)", @@ -565,7 +612,8 @@ static char *opnames[OPCNT] = { "c!", "c,", "w@", "w!", "@", "!", "+!", ",", "+", "-", "*", "/mod", "and", "or", "xor", "bool", "not", "<", "<<c", ">>c", "lshift", "rshift", "litn", "execute,", - "exit,", "move", "move,", "rtype", "(wnf)", "stack?", "maybeword", "word"}; + "exit,", "move", "move,", "rtype", "(wnf)", "stack?", "maybeword", "word", + "parse"}; static void oprun1() { // run next op byte opcode = vm.mem[vm.PC++]; @@ -636,11 +684,9 @@ static void buildsysdict() { callwr(find("c@")); callwr(find("rtype")); callwr(find("word")); - callwr(find("dup")); - callwr(find("1+")); - callwr(find("swap")); - callwr(find("c@")); - callwr(find("rtype")); + callwr(find("parse")); + callwr(find("drop")); + callwr(find("(emit)")); callwr(find("bye")); }