commit af1e9820a0c0c744eeeceefca118701808dd3167
parent c16c967c7d8223c4c9a9562d71a06f97a1b1707e
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 9 Mar 2023 14:42:29 -0500
HAL: move "8b", "16b" and "+" out of the kernel
Diffstat:
2 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -1,4 +1,6 @@
code : ] code ] ;
+: :8b code8b ] ;
+: :16b code16b ] ;
: noop ;
: W) 0 ; : A) 1 ; : PSP) 2 ; : RSP) 3 ;
: dup, -4 ps+, PSP) !, ;
@@ -14,19 +16,25 @@ code drop drop, exit,
code 2drop 2drop, exit,
code rot PSP) @!, PSP) 4 +) @!, exit,
code rot> PSP) 4 +) @!, PSP) @!, exit,
-code nip 4 ps+, exit,
+: nip, 4 ps+, ;
+code nip nip, exit,
: over, dup, PSP) 4 +) @, ;
code over over, exit,
code 2dup W>A, PSP) @, -8 ps+, PSP) !, W<>A, PSP) 4 +) !, exit,
-code @ W) @, exit,
-code16b W) 16b @, exit,
-code8b W) 8b @, exit,
-: c@ 8b @ ; : w@ 16b @ ;
+code immediate dup, sysdict i) @, 4 W+n, W>A, A) @, $80 orn, A) !, drop, exit,
+: EMETA_16B $11 ; : EMETA_8B $10 ;
+code 16b dup, MOD LIT>A, EMETA_16B LIT>W, A) !, drop, exit, immediate
+code 8b dup, MOD LIT>A, EMETA_8B LIT>W, A) !, drop, exit, immediate
+
code ! W>A, PSP) @, A) !, 2drop, exit,
code16b W>A, PSP) @, A) 16b !, 2drop, exit,
code8b W>A, PSP) @, A) 8b !, 2drop, exit,
: c! 8b ! ; : w! 16b ! ;
+code @ W) @, exit,
+code16b W) 16b @, exit,
+code8b W) 8b @, exit,
+: c@ 8b @ ; : w@ 16b @ ;
code +! W>A, drop, A) +, A) !, drop, exit,
code16b W>A, drop, A) 16b +, A) 16b !, drop, exit,
code8b W>A, drop, A) 8b +, A) 8b !, drop, exit,
@@ -39,10 +47,6 @@ code execute W>A, drop, branchA,
code 1+ 1 W+n, exit,
code 1- -1 W+n, exit,
: litn -4 ps+, PSP) !, LIT>W, ;
-: e>w 5 + ;
-: w>e 5 - ;
-: current sysdict @ e>w ;
-: immediate current 1- dup c@ $80 or swap c! ;
: if 0 ?branch, ; immediate
: ifz 0 branchz, ; immediate
: ahead 0 branch, ; immediate
@@ -74,6 +78,7 @@ code 1- -1 W+n, exit,
: >r -4 rs+, RSP) !, drop, ; immediate
\ Arithmetic
+code + PSP) +, nip, exit,
: > swap < ;
: 0>= $80000000 < ;
: 0< 0>= not ;
@@ -147,9 +152,7 @@ alias @ llnext
-4 &+@ emeta
-4 &+ 'emeta
: metaadd ( id entry -- ) 'emeta lladd drop , ;
-: code8b EMETA_8B sysdict @ metaadd ;
: :8b code8b ] ;
-: code16b EMETA_16B sysdict @ metaadd ;
: :16b code16b ] ;
code @! >A, A@!, exit,
@@ -229,6 +232,10 @@ alias execute | immediate
dup 8b to@+ V2 = if j to@! i to V1 then next ( c )
drop rdrop r> ( i ) ;
+: e>w 5 + ;
+: w>e 5 - ;
+: current sysdict @ e>w ;
+
\ Emitting
$20 const SPC $0d const CR $0a const LF $08 const BS $1b const ESC
alias drop emit
diff --git a/posix/vm.c b/posix/vm.c
@@ -385,8 +385,7 @@ static void addmeta(dword id) {
static void CODE16() { addmeta(EMETA_16B); }
static void CODE8() { addmeta(EMETA_8B); }
-static void ADD() { vm.W += pnip(); } // 0x48
-static void SUB() { vm.W = pnip() - vm.W; }
+static void SUB() { vm.W = pnip() - vm.W; } // 0x48
static void MUL() { vm.W *= pnip(); }
// ( a b -- r q )
static void DIVMOD() { dword n = pnip(); ppush(n%vm.W); vm.W = n / vm.W; }
@@ -417,6 +416,9 @@ static void DBG() {
static void SHLN() { vm.W <<= gpcb(); } // 0x60
static void SHRN() { vm.W >>= gpcb(); }
+static void ANDN() { vm.W &= gpc(); }
+static void ORN() { vm.W |= gpc(); }
+static void XORN() { vm.W ^= gpc(); }
#define OPCNT 0x68
static void (*ops[OPCNT])() = {
@@ -429,10 +431,10 @@ static void (*ops[OPCNT])() = {
MAYBEWORD, WORD, PARSE, FIND, WNF, FINDMOD, NULL, NULL,
STACKCHK, COMPWORD, RUNWORD, COMPILING, STARTCOMP, STOPCOMP, NULL, NULL,
ALIGN4, ENTRY, CODE, CODE16, CODE8, NULL, NULL, NULL,
- ADD, SUB, MUL, DIVMOD, LT, NULL, NULL, NULL,
+ SUB, MUL, DIVMOD, LT, NULL, NULL, NULL, NULL,
AND, OR, XOR, BOOL, NOT, NULL, NULL, NULL,
BYE, BYEFAIL, QUIT, ABORT_, DBG, NULL, NULL, NULL,
- SHLN, SHRN, NULL, NULL, NULL, NULL, NULL, NULL,
+ SHLN, SHRN, ANDN, ORN, XORN, NULL, NULL, NULL,
};
static void oprun1() { // run next op
@@ -490,8 +492,8 @@ static void buildsysdict() {
wentry("]", 0x3c); wentry("[", 0x3d); makeimm();
wentry("align4", 0x40); wentry("entry", 0x41);
wentry("code", 0x42); wentry("code16b", 0x43); wentry("code8b", 0x44);
- wentry("+", 0x48); wentry("-", 0x49); wentry("*", 0x4a); wentry("/mod", 0x4b);
- wentry("<", 0x4c);
+ wentry("-", 0x48); wentry("*", 0x49); wentry("/mod", 0x4a);
+ wentry("<", 0x4b);
wentry("and", 0x50); wentry("or", 0x51); wentry("xor", 0x52);
wentry("bool", 0x53); wentry("not", 0x54);
wentry("bye", 0x58); wentry("byefail", 0x59);
@@ -531,6 +533,9 @@ static void buildsysdict() {
CODE8(); compopwr(0x27); retwr();
entry("<<n,"); compileop(0x60); cwritewr(); retwr();
entry(">>n,"); compileop(0x61); cwritewr(); retwr();
+ entry("andn,"); compileop(0x62); writewr(); retwr();
+ entry("orn,"); compileop(0x63); writewr(); retwr();
+ entry("xorn,"); compileop(0x64); writewr(); retwr();
entry("exit,"); compileop(0x02); retwr();
entry("execute,"); compileop(0x01); writewr(); retwr();
entry("branchA,"); compileop(0x03); retwr();
@@ -539,8 +544,6 @@ static void buildsysdict() {
entry("branchz,"); litwr(0x06); cwrite(0x05); retwr();
entry("branch!"); storewr(); retwr();
entry(";"); compileop(0x02); cwrite(0x3d); retwr(); makeimm();
- entry("16b"); litwr(EMETA_16B); alitwr(MOD); wstorewr(OPA); dropwr(); retwr(); makeimm();
- entry("8b"); litwr(EMETA_8B); alitwr(MOD); wstorewr(OPA); dropwr(); retwr(); makeimm();
sysalias("in<", "boot<");
inrdaddr = find("in<");
mainaddr = here();