From 52f97d2fe49c650034e231ccc98e0fb1c507bee9 Mon Sep 17 00:00:00 2001 From: cannoli-fruit Date: Sun, 26 Jul 2026 04:48:04 -0400 Subject: [PATCH] =?UTF-8?q?Implemented=20if=20statements=20and=20file=20in?= =?UTF-8?q?cludes=20checking=20(that=20was=20a=20hard=20seg=20fault=20to?= =?UTF-8?q?=20find=20=F0=9F=AB=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flagpole/src/main.c | 25 +++++++++++++++++++++++++ flagpole/tests/ifs.fp | 14 ++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 flagpole/tests/ifs.fp diff --git a/flagpole/src/main.c b/flagpole/src/main.c index 79b17b4..4afd67d 100644 --- a/flagpole/src/main.c +++ b/flagpole/src/main.c @@ -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; diff --git a/flagpole/tests/ifs.fp b/flagpole/tests/ifs.fp new file mode 100644 index 0000000..7b9f971 --- /dev/null +++ b/flagpole/tests/ifs.fp @@ -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 +