~vdupras/duskos

3165a626e3de4bd195640b144974d2fe0f52175e — Virgil Dupras a month ago 2a0b4df
cc: rename AST_LVALUE to AST_IDENT

Classification as lvalue at the AST phase was wrong. "foobar" could be a
function name or a lvalue, but at the parsing phase, we don't know yet.
2 files changed, 11 insertions(+), 11 deletions(-)

M fs/cc/ast.fs
M fs/cc/gen.fs
M fs/cc/ast.fs => fs/cc/ast.fs +9 -9
@@ 42,7 42,7 @@ create bopsprectbl 1 c, 1 c, 0 c, 0 c, 2 c, 2 c, 2 c, 2 c,
4 const AST_CONSTANT
5 const AST_STATEMENTS
6 const AST_ARGSPECS
7 const AST_LVALUE
7 const AST_IDENT
8 const AST_UNARYOP
9 const AST_POSTFIXOP
10 const AST_BINARYOP


@@ 176,7 176,7 @@ alias noop parseExpression ( tok -- node ) \ forward declaration
  AST_LIST createnode nextt dup S" }" s= if drop exit then
  begin ( lnode tok ) case
      of isIdent? ( lnode )
        AST_LVALUE createnode swap , ( lnode lvnode ) over addnode endof
        AST_IDENT createnode swap , ( lnode inode ) over addnode endof
      of parse ( lnode n )
        AST_CONSTANT createnode swap , ( lnode cnode ) over addnode endof
      _err


@@ 188,9 188,9 @@ alias noop parseExpression ( tok -- node ) \ forward declaration
    endcase
  nextt again ;

: parsePostfixOp ( tok lvnode -- node )
  over S" [" s= if ( tok lvnode ) \ x[y] is the equivalent of *(x+y)
    nip AST_BINARYOP createnode 0 ( + ) , ( lvnode bnode )
: parsePostfixOp ( tok inode -- node )
  over S" [" s= if ( tok inode ) \ x[y] is the equivalent of *(x+y)
    nip AST_BINARYOP createnode 0 ( + ) , ( inode bnode )
    tuck addnode ( bnode )
    AST_CONSTANT createnode nextt parse _assert , ( bnode cnode )
    nextt ']' expectChar


@@ 198,14 198,14 @@ alias noop parseExpression ( tok -- node ) \ forward declaration
    AST_UNARYOP createnode 4 ( * ) , ( bnode unode )
    tuck addnode ( unode )
  else
    over popid if ( tok lvnode opid )
      AST_POSTFIXOP createnode swap , ( tok lvnode opnode )
    over popid if ( tok inode opid )
      AST_POSTFIXOP createnode swap , ( tok inode opnode )
      tuck addnode ( tok opnode ) nip ( node )
    else swap to nexttputback then then ;

\ A factor can be:
\ 1. A constant
\ 2. A Lvalue
\ 2. A Lvalue (AST_IDENT)
\ 3. A unaryop/postfixop containing a factor
\ 4. A function call
\ 5. An expression inside () parens.


@@ 224,7 224,7 @@ alias noop parseExpression ( tok -- node ) \ forward declaration
        nextt dup S" ," s= if drop else to nexttputback then
      repeat ( tok ) ')' expectChar
    else ( prevtok newtok ) \ lvalue
      swap AST_LVALUE createnode swap , ( tok lvnode ) parsePostfixOp then
      swap AST_IDENT createnode swap , ( tok inode ) parsePostfixOp then
  endof
  ( case else ) \ Constant
    r@ parse if AST_CONSTANT createnode swap , else 0 then

M fs/cc/gen.fs => fs/cc/gen.fs +2 -2
@@ 54,7 54,7 @@ alias noop gennode ( node -- ) \ forward declaration
  firstchild ?dup if begin dup gennode nextsibling ?dup not until then ;

: spit ( a u -- ) A>r >r >A begin Ac@+ .x1 next r>A ;
: lv>decl ( lvnode -- dnode )
: lv>decl ( inode -- dnode )
  dup ast.lvalue.name dup rot AST_FUNCTION parentnodeid ( name name fnode )
  ast.func.finddecl ?dup not if ( name )
    ast.unit.find dup _assert else


@@ 70,7 70,7 @@ alias noop gennode ( node -- ) \ forward declaration

\ Return the "pointer arithmetic size" of "node".
: node*arisz ( node -- n )
  dup nodeid AST_LVALUE = if ( node )
  dup nodeid AST_IDENT = if ( node )
    lv>decl dup ast.decl.type ( dnode type )
    swap ast.decl.nbelem ( nbelem ) 1 > if type*lvl+ then *ariunitsz ( n ) else
    drop 1 then ;