Implemented if statements and file includes checking (that was a hard seg fault to find 🫠)
This commit is contained in:
parent
5b7dd220ae
commit
52f97d2fe4
2 changed files with 39 additions and 0 deletions
|
|
@ -78,6 +78,9 @@ static inline bool isKW(Lz_SB *sb) {
|
||||||
|| SBeq(sb, "swap")
|
|| SBeq(sb, "swap")
|
||||||
|| SBeq(sb, "while")
|
|| SBeq(sb, "while")
|
||||||
|| SBeq(sb, "do")
|
|| SBeq(sb, "do")
|
||||||
|
|| SBeq(sb, "if")
|
||||||
|
|| SBeq(sb, "then")
|
||||||
|
|| SBeq(sb, "endif")
|
||||||
|| SBeq(sb, "endwhile")
|
|| SBeq(sb, "endwhile")
|
||||||
|| SBeq(sb, "==")
|
|| SBeq(sb, "==")
|
||||||
|| SBeq(sb, "not")
|
|| SBeq(sb, "not")
|
||||||
|
|
@ -252,6 +255,24 @@ codegen:
|
||||||
printf("__whiletail_%d:\n", lbl);
|
printf("__whiletail_%d:\n", lbl);
|
||||||
break;
|
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, "==")) {
|
if (SBeq(&tokenAccumulator, "==")) {
|
||||||
// Hacked like crazy...
|
// Hacked like crazy...
|
||||||
printf(" popstack 110\n");
|
printf(" popstack 110\n");
|
||||||
|
|
@ -338,6 +359,10 @@ codegen:
|
||||||
memcpy(fname, tokenAccumulator.data, tokenAccumulator.cnt);
|
memcpy(fname, tokenAccumulator.data, tokenAccumulator.cnt);
|
||||||
fname[tokenAccumulator.cnt] = 0;
|
fname[tokenAccumulator.cnt] = 0;
|
||||||
FILE *f = fopen(fname, "rb");
|
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);
|
lz_da_append(inpfiles, f);
|
||||||
isInclude = false;
|
isInclude = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
14
flagpole/tests/ifs.fp
Normal file
14
flagpole/tests/ifs.fp
Normal 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
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue