duskos

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

commit ff183d43f10bcea2870e39b941990dbe7be2da27
parent c9d9ec4f6478df10a609e5649e15fd2d3425ae35
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 20 Sep 2022 15:05:58 -0400

cc: fix bug in binop tree mangling logic

Diffstat:
Mfs/cc/ast.fs | 4+++-
Mfs/cc/lib.fs | 5+----
Mfs/tests/cc/cc.fs | 3++-
Mfs/tests/cc/test.c | 21++++++++++++---------
4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -388,10 +388,12 @@ current to parseFactor \ another binop! who will get fn? bn1 or bn2? the one that has the \ best precedence! rot ( fn bn2 bn1 ) over Op opid bopprec - over Op opid bopprec < if + over Op opid bopprec < if ( fn bn2 bn1 ) \ bn2 wins. add fn to bn2, add bn2 to bn1, bn2 becomes bn rot> tuck Node :add ( bn1 bn2 ) dup rot Node :add ( bn2->bn ) else \ bn1 wins. add fn to bn1, bn1 to bn2, bn2 becomes bn + dup Node parent if \ bn1 has a parent! bn2 needs to replace it. + 2dup Node :replace then rot over Node :add ( bn2 bn1 ) over Node :add ( bn2->bn ) then ( bn ) nextt repeat ( bn fn tok ) \ not a binop diff --git a/fs/cc/lib.fs b/fs/cc/lib.fs @@ -68,10 +68,7 @@ $100 MemIO :new const _sio if (isdigit(c)) { n = 0; do { - // TODO: fix expr "n = (n*10) + c - '0'" - n = n * 10; - n = n + c; - n = n - '0'; + n = (n * 10) + c - '0'; c = fgetc(iohdl); } while (isdigit(c)); fputback(c, iohdl); diff --git a/fs/tests/cc/cc.fs b/fs/tests/cc/cc.fs @@ -12,7 +12,6 @@ binopor 42 #eq binopxor 42 #eq binopshl 336 #eq binopshr 10 #eq -2 3 binop1 1 #eq boolops 0 #eq variables 82 #eq funcall 42 #eq @@ -52,6 +51,8 @@ S" foobar" dup 6 'X' set8b S" foobaX" #s= 5 whilesum 15 #eq 5 dowhilesum 15 #eq 42 unaryopmut 42 #eq +2 3 binop1 1 #eq +'2' binop2 44 #eq \ and what about inline functions? :cfunc int myinline() { return 42; } diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c @@ -30,12 +30,6 @@ extern int binopshl() { extern int binopshr() { return 42 >> 2; } -// test some bug I was having -extern int binop1(int a, int b) { - int c; - c = a ^ b; - return c; -} extern int boolops() { return 66 < 54 && 2 == 2; } @@ -182,12 +176,10 @@ extern void whilesum(int n) { } return res; } -// TODO: fix "res = res + n--" which is broken on i386 extern void dowhilesum(int n) { int res = 0; do { - res = res + n; - n--; + res = res + n--; } while (n); return res; } @@ -196,3 +188,14 @@ extern int unaryopmut(int n) { !n; return n; } +// Below this comment are simple construct that were buggy before +extern int binop1(int a, int b) { + int c; + c = a ^ b; + return c; +} +extern int binop2(int n) { + int x = 42; + x = x + n - '0'; + return x; +}