Implemented drop directive and fibonacci program

This commit is contained in:
cannoli-fruit 2026-07-26 23:20:39 -04:00
commit 1140b5b140
2 changed files with 26 additions and 0 deletions

View file

@ -87,6 +87,7 @@ static inline bool isKW(Lz_SB *sb) {
|| SBeq(sb, "st8") || SBeq(sb, "st8")
|| SBeq(sb, "dup") || SBeq(sb, "dup")
|| SBeq(sb, "swap") || SBeq(sb, "swap")
|| SBeq(sb, "drop")
|| SBeq(sb, "while") || SBeq(sb, "while")
|| SBeq(sb, "do") || SBeq(sb, "do")
|| SBeq(sb, "if") || SBeq(sb, "if")
@ -261,6 +262,10 @@ codegen:
printf(" pushstack 119\n"); printf(" pushstack 119\n");
break; break;
} }
if (SBeq(&tokenAccumulator, "drop")) {
printf(" popstack 118\n");
break;
}
if (SBeq(&tokenAccumulator, "while")) { if (SBeq(&tokenAccumulator, "while")) {
lz_da_append(labelStack, counter); lz_da_append(labelStack, counter);
commentStack(&labelStack); commentStack(&labelStack);

21
flagpole/tests/fib.fp Normal file
View file

@ -0,0 +1,21 @@
$inc fvmstd.fp
proc fib
if dup 0 == then
drop 0 return
endif
if dup 1 == then
drop 1 return
endif
dup
1 u- :fib
swap
2 u- :fib
u+
endproc
proc main
"Idx: " :puts :getuint
:fib :putuint
endproc