duskos

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

commit cf81d5d9c011fe1233ee5307adfeabcfa6da2ebc
parent 42115cb411e1f7b5293b2d1137765169030a5902
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri,  7 Oct 2022 18:00:47 -0400

cc: allow expressions in subscript[] operator

Previously, only a factor was accepted.

Diffstat:
Mfs/app/cos/cvm.c | 2+-
Mfs/cc/ast.fs | 2+-
Mfs/tests/cc/cc.fs | 2+-
Mfs/tests/cc/test.c | 9+++++----
4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/fs/app/cos/cvm.c b/fs/app/cos/cvm.c @@ -106,7 +106,6 @@ static void iowr_blk(byte val) /* get/set word from/to memory */ static word gw(word addr) { - // Compiles up to this point! return vm.mem[addr+1] << 8 | vm.mem[addr]; } static void sw(word addr, word val) { vm.mem[addr] = val; @@ -114,6 +113,7 @@ static void sw(word addr, word val) { } static word peek() { return gw(vm.SP); } /* pop word from SP */ +// Compiles up to this point! static word pop() { word n = peek(); vm.SP+=2; return n; } word VM_PS_pop() { return pop(); } diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -304,7 +304,7 @@ alias noop parseFactor ( tok -- node ) \ forward declaration '[' of isChar?^ ( inode ) \ x[y] is the equivalent of *(x+y) BinaryOp :new+ ( inode bnode ) tuck Node :add ( bnode ) - nextt parseFactor nextt ']' expectChar ( bnode node ) + nextt parseExpression nextt ']' expectChar ( bnode node ) over Node :add ( bnode ) UnaryOp :new* ( bnode unode ) tuck Node :add ( unode ) parsePostfixOp diff --git a/fs/tests/cc/cc.fs b/fs/tests/cc/cc.fs @@ -59,7 +59,7 @@ S" foobar" dup 6 'X' set8b S" foobaX" #s= 5 dowhilesum 15 #eq 42 unaryopmut 42 #eq create mydata 42 , $12345678 , $23456789 , -mydata structget $5678 #eq +mydata structget $35 #eq mydata $42 structset mydata 4 + @ $42345678 #eq 42 globstructset globstructget 42 #eq globdata 4 + 16b @ 42 #eq diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c @@ -226,17 +226,18 @@ int unaryopmut(int n) { return n; } -typedef short MyType; +typedef char MyType; typedef MyType** MyTypePtr; struct MyStruct { int foo; - MyType bar; - char baz[2]; + short bar; + MyType baz[2]; }; MyType structget(MyStruct *s) { - return s->bar; + int x = 1; + return s->baz[x-1] + 1; } void structset(MyStruct *s, char val) { s->baz[1] = val;