From f59e909a1adaf545dba4c77d83523eeb5063fbcb Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 3 Jun 2023 18:25:58 -0400 Subject: feat: add do ... loop; --- forthmachine.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'forthmachine.c') 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; -- cgit v1.2.3