duskos

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

commit c387d55843c5ddacde83b66f718fb1161be31af9
parent 20d96c07255311c38fdb8225362eb541560d5e1b
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Mon, 20 Mar 2023 21:48:01 -0400

halcc: incdecp()

Diffstat:
Mfs/comp/c/egen.fs | 6+++++-
Mfs/comp/c/fgen.fs | 4++--
Mfs/comp/c/op.fs | 8--------
Mfs/tests/comp/c/cc.fs | 2+-
Mfs/tests/comp/c/test2.c | 6++++++
5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs @@ -58,6 +58,9 @@ UOPSCNT wordtbl _tbl ( res -- res ) Result currentW ?dup if PS- Result :release then CType type if PS+ Result :W else Result :none then ; +: _incdec, ( res incsz -- res ) + swap bi+ Result :hal# | Result :?>W ( incsz res halop ) rot swap [+n], ; + \ parses, if possible, a postfix operator. If none, this is a noop. \ We parse postfix args as long as there are any. : parsePostfixOp ( res -- res ) @@ -67,7 +70,8 @@ UOPSCNT wordtbl _tbl ( res -- res ) '(' of isChar?^ _funcall parsePostfixOp endof S" ->" of s= abort" TODO ->" endof '.' of isChar?^ abort" TODO ." endof - of popid ( opid ) abort" TODO ++/--" endof + S" ++" of s= 1 _incdec, endof + S" --" of s= -1 _incdec, endof r@ to nexttputback endcase ; diff --git a/fs/comp/c/fgen.fs b/fs/comp/c/fgen.fs @@ -10,8 +10,6 @@ : _postlude _curfunc CType :argssize ?dup if ps+, then _locvars CType :size ?dup if rs+, then ; -: emitRet ( res -- ) Result :>W$ psneutral _postlude exit, ; -: emitNullRet ( -- ) _postlude drop, exit, ; alias noop parseStatement ( tok -- ) \ forward declaration @@ -26,6 +24,8 @@ alias noop parseStatement ( tok -- ) \ forward declaration else to nexttputback then ( jump_addr ) [compile] then ; +: emitRet ( res -- ) Result :>W$ psneutral _postlude exit, ; +: emitNullRet ( -- ) _postlude drop, exit, ; : _return \ empty returns are allowed ';' readChar? not if parseExpression emitRet read; else emitNullRet then ; diff --git a/fs/comp/c/op.fs b/fs/comp/c/op.fs @@ -9,14 +9,6 @@ UOPSCNT stringlist UOPTlist "-" "~" "!" "&" "*" "++" "--" UOPTlist sfind dup 0< if drop 0 else 1 then ; : uoptoken ( opid -- tok ) UOPTlist slistiter ; -\ Postfix operators -2 const POPSCNT -POPSCNT stringlist POPTlist "++" "--" - -: popid ( tok -- opid? f ) - POPTlist sfind dup 0< if drop 0 else 1 then ; -: poptoken ( opid -- tok ) POPTlist slistiter ; - \ Binary operators 31 const BOPSCNT BOPSCNT stringlist BOPTlist diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs @@ -29,8 +29,8 @@ ptrset 54 #eq 12 condif 13 #eq 42 condif 142 #eq 42 incdec 43 #eq -testend \s 54 incdecp 54 #eq +testend \s exprparens 9 #eq cnoop ( no result! ) scnt 0 #eq 42 ptrari 50 #eq diff --git a/fs/tests/comp/c/test2.c b/fs/tests/comp/c/test2.c @@ -113,3 +113,9 @@ int incdec(int x) { --x; return ++x; } +// test that the final "--" doesn't affect the result +int incdecp(int x) { + x++; + x--; + return x--; +}