aboutsummaryrefslogtreecommitdiffstats
path: root/forthmachine.c
diff options
context:
space:
mode:
authordan <[email protected]>2023-06-03 18:25:58 -0400
committerdan <[email protected]>2023-06-03 18:25:58 -0400
commitf59e909a1adaf545dba4c77d83523eeb5063fbcb (patch)
tree0c3b1a133d9023c2e988afd79233e363f348859d /forthmachine.c
parentb528f7d498b301bcfbd42ea011ed31569f36b378 (diff)
downloadforth-f59e909a1adaf545dba4c77d83523eeb5063fbcb.tar.gz
forth-f59e909a1adaf545dba4c77d83523eeb5063fbcb.tar.bz2
forth-f59e909a1adaf545dba4c77d83523eeb5063fbcb.zip
feat: add do ... loop;
Diffstat (limited to 'forthmachine.c')
-rw-r--r--forthmachine.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/forthmachine.c b/forthmachine.c
index 6cdefb5..d831106 100644
--- a/forthmachine.c
+++ b/forthmachine.c
@@ -11,8 +11,9 @@ forthmachine* forthmachine_new(errorhandler errorhandler) {
fm->ot = optable_new(errorhandler);
fm->s = stack_new(errorhandler);
fm->outputbuffer = (char*)malloc(sizeof(char) * MAX_OUTPUT_BUFFER_SIZE);
- fm->errorhandler = errorhandler;
strcpy(fm->outputbuffer, "");
+ fm->errorhandler = errorhandler;
+ fm->lcs = stack_new(errorhandler);
return fm;
}
@@ -39,6 +40,18 @@ static void op_exec(wordop* op, forthmachine* fm) {
}
break;
}
+ case compileditem_doloopcontrol:
+ {
+ int index = stack_pop(fm->lcs);
+ int limit = stack_pop(fm->lcs);
+ index++;
+ if (index < limit) {
+ j = op->oplist[j].loopbackto - 1;
+ stack_push(fm->lcs, limit);
+ stack_push(fm->lcs, index);
+ }
+ break;
+ }
}
}
break;