commit 2ab6da8bddae3d3b063a0608cebfc1e90214de9e
parent 26616840b09b8589dcc905d443dd3940092fc794
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Mon, 19 Sep 2022 16:02:31 -0400
cc/vm/i386: fix backward jumps
And make dowhilesum test pass, with TODO note.
Diffstat:
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/cc/vm/i386.fs b/fs/cc/vm/i386.fs
@@ -286,7 +286,7 @@ struct+[ VMOp
vmop :compile vmop loc $f and VM_REGISTER = if
vmop :compile else -1 i) then
test, ( sets Z ) vmop :init ;
-: vmjz, ( a -- ) vmtest, jz, ;
+: vmjz, ( a -- ) vmtest, abs>rel jz, ;
: vmjz[, ( -- a ) 0 vmjz, _ ;
-: vmjnz, ( a -- ) vmtest, jnz, ;
+: vmjnz, ( a -- ) vmtest, abs>rel jnz, ;
: vmjnz[, ( -- a ) 0 vmjnz, _ ;
diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c
@@ -182,10 +182,12 @@ 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--;
+ res = res + n;
+ n--;
} while (n);
return res;
}