commit 9fe129f822afdc30ef19b639ecbac5ffe53c3821
parent f513fb21947f001c52a1ff283e2e7c4038d1158f
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Mon, 3 Apr 2023 19:12:12 -0400
halcc: Collapse OS prompt!
Diffstat:
11 files changed, 43 insertions(+), 21 deletions(-)
diff --git a/Makefile b/Makefile
@@ -66,8 +66,8 @@ testhal: dusk
echo "' byefail ' abort realias f<< tests/asm/hal.fs bye" | ./dusk || (echo; exit 1)
.PHONY: testtext
-testtext: dusk
- echo "' byefail ' abort realias f<< tests/text/all.fs bye" | ./dusk || (echo; exit 1)
+testcos: dusk
+ echo "' byefail ' abort realias f<< tests/emul/cos/all.fs bye" | ./dusk || (echo; exit 1)
.PHONY: clean
clean:
diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs
@@ -193,8 +193,8 @@ MAXLITSZ Stack :new structbind Stack _list
'(' of isChar?^
\ can be an expression or a typecast
nextt dup parseType if ( tok type )
- \ TODO: actually process the typecast
- nip parseDeclarator drop read) nextt parseFactor
+ nip parseDeclarator read) nextt parseFactor ( type res )
+ tuck Result :typecast
else ( tok ) parseExpression read) parsePostfixOp then
endof
'"' of isChar?^ MAXLITSZ _litarena :[
diff --git a/fs/comp/c/expr.fs b/fs/comp/c/expr.fs
@@ -110,6 +110,15 @@ struct[ Result
1 of = :basesz endof
drop 4 endcase ;
: :toint ( self -- ) UintCDecl over to cdecl 0 swap to lvl ;
+ create _masks $ff , $ffff ,
+ : :typecast ( cdecl self -- )
+ dup :hasW? if
+ over typesize over cdecl typesize < if
+ over typesize 1- CELLSZ * _masks + @ i) and, then
+ else over typesize over cdecl typesize > if dup :?>W then then
+ over swap to@! cdecl swap ( old new )
+ over CDecl storage over to CDecl storage
+ swap CDecl offset swap to CDecl offset ;
]struct
BOPSCNT wordtbl _tbl ( a b -- n )
diff --git a/fs/doc/cc/usage.txt b/fs/doc/cc/usage.txt
@@ -50,8 +50,6 @@ are a few differences:
* No "varargs". pspop() and pspush() replace that functionality.
* "struct MyStruct {...};" automatically creates a "typedef" to the struct.
* The "struct" keyword can't be used to reference structs, only to define them.
-* There's a maximum of 3 indirection levels for types. "int ***i;" is fine,
- "int ****i;" is not.
* No bit fields. I expect that they're not worth their complexity weight, not
only to parse them and generate them correctly, but also to do so in an
efficient manner. The plan is to port code using bit fields with manual
diff --git a/fs/doc/hal.txt b/fs/doc/hal.txt
@@ -58,6 +58,16 @@ Width-aware compiler words:
cmp, op --
[+n], n op -- *Z*
+## 8b) and 16b) arithmetics
+
+8b) and 16b) modifiers only apply to memory access and all arithmetics are
+"upscaled" to 32-bit with regards to flags settings and carry management
+(the C flag is never set in 16b) or 8b) mode).
+
+This also applies to cmp, which means that, for example,
+"$4242 LIT>W, RSP) 8b) cmp," will never set the Z flag because even if RSP) is
+$42, comparison is done one the whole W register.
+
## High HAL
The "high" layer of the HAL is provided by the assembler.
diff --git a/fs/emul/cos/cvm.fs b/fs/emul/cos/cvm.fs
@@ -1,7 +1,7 @@
?f<< /emul/cos/tools/blkpack.fs
cc<< /emul/cos/cvm.c
-S" COSVM" findTypedef CType :export
+S" COSVM" findTypedef CDecl :export
: cos
COS_init
diff --git a/fs/tests/all.fs b/fs/tests/all.fs
@@ -6,7 +6,7 @@ f<< /tests/fs/all.fs
f<< /tests/comp/c/all.fs
f<< /tests/asm/all.fs
\ f<< /tests/ar/all.fs
-\ f<< /tests/emul/all.fs
+f<< /tests/emul/all.fs
f<< /tests/gr/all.fs
f<< /tests/text/all.fs
." All tests passed\n"
diff --git a/fs/tests/asm/hal.fs b/fs/tests/asm/hal.fs
@@ -179,4 +179,10 @@ code test18 ( ... idx -- n )
1 test18 12 #eq
2 test18 42 #eq
2drop drop
+
+\ 16-bit and 8-bit arithmetics are properly upscaled to 32-bit in W/A registers
+code test19 ( a b -- n )
+ PSP) 16b) +, nip, exit,
+
+1 $1ffff test19 $20000 #eq
testend
diff --git a/fs/tests/emul/all.fs b/fs/tests/emul/all.fs
@@ -1,2 +1,2 @@
f<< /tests/emul/cos/all.fs
-f<< /tests/emul/uxn/all.fs
+\ f<< /tests/emul/uxn/all.fs
diff --git a/fs/tests/emul/cos/cvm.fs b/fs/tests/emul/cos/cvm.fs
@@ -1,7 +1,7 @@
?f<< /tests/harness.fs
?f<< /comp/c/lib.fs
cc<< /emul/cos/cvm.c
-S" COSVM" findTypedef CType :export
+S" COSVM" findTypedef CDecl :export
testbegin
\ Testing COS CVM
@@ -15,10 +15,10 @@ vm running #
\ The "dummy.bin" file is a test handcrafted binary with the equivalent of
\ but without any word name:
\ (address of BOOT) JMP
-\ CODE (xt) $0c c,
-\ CODE (b) $0f c, $07 ( next ) c,
-\ CODE BYE $3b c,
-\ CODE (n) $10 c, $07 c,
+\ CODE (xt) $0c c,
+\ CODE (b) $0f c, $07 ( next ) c,
+\ CODE BYE $3b c,
+\ CODE (n) $10 c, $07 c,
\ CODE + 1c c, 07 c,
\ CODE >R $3e c, 07 c,
\ CODE (next) $09 c, $07 c,
@@ -26,7 +26,7 @@ vm running #
\ CODE AND $27 c, $07 c,
\ : BOOT 42 3 >R BEGIN 1 + NEXT 44 AND 0 PC! BYE ;
-60 COS_steps not #
-COS_printdbg
+60 COS_steps not #
+COS_printdbg
myres 44 #eq
testend
diff --git a/posix/vm.c b/posix/vm.c
@@ -246,17 +246,16 @@ static void entry(char *name) {
/* Operations */
static dword opaddr;
static dword *opdst;
-static dword opmask;
static dword (*mget)(dword a);
static void (*mset)(dword a, dword val);
static dword mget16(dword a) { return (dword)gw(a); }
static dword mget8(dword a) { return (dword)gb(a); }
static void mset16(dword a, dword val) { sw(a, (word)val); }
static void mset8(dword a, dword val) { sb(a, (byte)val); }
-#define M32B mget = gdr; mset = sdr; opmask = 0xffffffff
-#define M16B mget = mget16; mset = mset16; opmask = 0xffff
-#define M8B mget = mget8; mset = mset8; opmask=0xff
-static dword def_opdget() { return *opdst & opmask; }
+#define M32B mget = gdr; mset = sdr
+#define M16B mget = mget16; mset = mset16
+#define M8B mget = mget8; mset = mset8
+static dword def_opdget() { return *opdst; }
static void def_opdset(dword val) { *opdst = val; }
static dword def_opsget() { return mget(opaddr); }
static void def_opsset(dword val) { mset(opaddr, val); }