Implemented if statements and file includes checking (that was a hard seg fault to find 🫠)

This commit is contained in:
cannoli-fruit 2026-07-26 04:48:04 -04:00
commit 52f97d2fe4
2 changed files with 39 additions and 0 deletions

View file

@ -78,6 +78,9 @@ static inline bool isKW(Lz_SB *sb) {
|| SBeq(sb, "swap")
|| SBeq(sb, "while")
|| SBeq(sb, "do")
|| SBeq(sb, "if")
|| SBeq(sb, "then")
|| SBeq(sb, "endif")
|| SBeq(sb, "endwhile")
|| SBeq(sb, "==")
|| SBeq(sb, "not")
@ -252,6 +255,24 @@ codegen:
printf("__whiletail_%d:\n", lbl);
break;
}
if (SBeq(&tokenAccumulator, "if")) {
lz_da_append(labelStack, counter);
break;
}
if (SBeq(&tokenAccumulator, "then")) {
int lbl = labelStack.data[labelStack.cnt-1];
//int lbl = lz_da_pop(labelStack);
//lz_da_append(labelStack, lbl);
printf(" popstack 123\n");
printf(" RSetF 123\n");
printf(" JmpIE __iftail_%d\n", lbl);
break;
}
if (SBeq(&tokenAccumulator, "endif")) {
int lbl = lz_da_pop(labelStack);
printf("__iftail_%d:\n", lbl);
break;
}
if (SBeq(&tokenAccumulator, "==")) {
// Hacked like crazy...
printf(" popstack 110\n");
@ -338,6 +359,10 @@ codegen:
memcpy(fname, tokenAccumulator.data, tokenAccumulator.cnt);
fname[tokenAccumulator.cnt] = 0;
FILE *f = fopen(fname, "rb");
if (!f) {
fprintf(stderr, "Could not open file %s or doesn't exist\n",
fname);
}
lz_da_append(inpfiles, f);
isInclude = false;
break;

14
flagpole/tests/ifs.fp Normal file
View file

@ -0,0 +1,14 @@
$inc fvmstd.fp
proc main
"Delete System32?" :puts :newline
"(y/n)" :puts :newline
:getchar @c
if &c 0x79 == then
"It appears to have failed, are you on linux?" :puts :newline
endif
if &c 0x6E == then
"Alright, have a nice day" :puts :newline
endif
endproc