commit 103aa689c609fcfdf9fc0e89ba7c28c9522a46f5
parent 07fa8923d560d3ee8c47034093cad401d0181b2c
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 8 Oct 2022 11:03:54 -0400
cc: allow Ident nodes in List initializations
Diffstat:
4 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/fs/app/cos/cvm.c b/fs/app/cos/cvm.c
@@ -18,6 +18,7 @@ typedef unsigned char byte;
typedef unsigned short word;
typedef byte (*IORD) ();
typedef void (*IOWR) (byte);
+typedef void (*VMOP) ();
struct COSVM {
byte mem[ #[ MEMSIZE ]# ];
@@ -220,8 +221,7 @@ static void LT() {
word b = pop(); word a = pop(); push(a<b); }
#[ 67 const OPCNT ]#
-// Compiles up to this point!
-static void (*ops[ #[ OPCNT c]# ])() = {
+static VMOP ops[ #[ OPCNT ]# ] = {
DUP, DROP, PUSHi, PUSHii, SWAP, OVER, ROT, lblnext, CBR, NEXT,
CALLi, JMPi, lblxt, EXIT, CDUP, LIT8, LIT16, JMPii, lbldoes, lblval,
NULL, EXECUTE, NULL, NULL, NULL, NULL, RDROP, NULL, PLUS, SUB, BR,
@@ -231,6 +231,7 @@ static void (*ops[ #[ OPCNT c]# ])() = {
RFETCH, RS2PS, PS2RS, CFETCH, FETCH, STORE, CSTORE
};
+// Compiles up to this point!
static void opexec(byte op) {
if (op < #[ OPCNT c]# ) {
ops[op]();
diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs
@@ -160,9 +160,9 @@ extends ASTNode struct[ Ident
: :new ( name -- node ) AST_IDENT ASTNode :new swap s, ;
: :finddecl ( self -- dnode-or-fnode-or-0 )
- dup name dup rot AST_FUNCTION swap Node :findparent
- ( name name fnode ) Function :finddecl ?dup not if ( name )
- findSymbol else nip then dup to lastidentfound ;
+ dup name dup rot AST_FUNCTION swap Node :findparent ( name name fnode )
+ dup if Function :finddecl else nip then ?dup if ( name d-or-fnode )
+ nip else ( name ) findSymbol then dup to lastidentfound ;
]struct
extends ASTNode struct[ Op
@@ -277,17 +277,13 @@ ASTIDCNT wordtbl astdatatbl ( node -- node )
\ Parse words
alias noop parseExpression ( tok -- node ) \ forward declaration
+alias noop parseFactor ( tok -- node ) \ forward declaration
\ The first '{' has already been read
: parseList ( -- node )
AST_LIST ASTNode :new nextt dup '}' isChar? if drop exit then
- begin ( lnode tok ) case
- of isIdent? ( lnode )
- r@ Ident :new ( lnode inode ) over Node :add endof
- of parse ( lnode n )
- Constant :new ( lnode cnode ) over Node :add endof
- _err
- endcase
+ begin ( lnode tok )
+ parseFactor over Node :add
nextt case
'}' of isChar?^ rdrop exit endof
',' of isChar?^ endof
@@ -295,8 +291,6 @@ alias noop parseExpression ( tok -- node ) \ forward declaration
endcase
nextt again ;
-alias noop parseFactor ( tok -- node ) \ forward declaration
-
\ parses, if possible, a postfix operator. If none, this is a noop.
\ We parse postfix args as long as there are any.
: parsePostfixOp ( node -- node )
diff --git a/fs/cc/gen.fs b/fs/cc/gen.fs
@@ -199,11 +199,13 @@ ASTIDCNT wordtbl gentbl ( node -- )
else \ nothing special needed, regular resolution
gennode selop^ gennode selop^ then
bopgentblpost r> Op opid wexec ;
-\ TODO: this doesn't work with lvalues yet
:w ( List )
+ vmop :noop#
dup Node :childcount dup 1+ CELLSZ * syspad :allot dup >r ( node len a )
over >r !+ swap Node firstchild begin ( a node )
- dup Constant value ( a node value ) rot !+ ( node a )
+ dup gennode \ value to vmop
+ vmop :loclo VM_CONSTANT = _assert ( a node )
+ vmop arg vmop :init rot !+ ( node a )
swap Node nextsibling next ( a node ) 2drop
r> constarray>op ;
:w ( If )
diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c
@@ -252,6 +252,9 @@ void globstructset(short val) {
globdata.bar = val;
}
+// support ident in global arrays
+static void globfuncs[3] = {retconst, NULL, neg};
+
// Below this comment are simple construct that were buggy before
int binop1(int a, int b) {
int c;