Implemented negative numbers and more importantly glendasay

This commit is contained in:
cannoli-fruit 2026-07-28 22:26:30 -04:00
commit 02aa3f707b
7 changed files with 226 additions and 26 deletions

View file

@ -105,6 +105,13 @@ static inline bool isKW(Lz_SB *sb) {
|| SBeq(sb, "u%")
|| SBeq(sb, "u>")
|| SBeq(sb, "u<")
|| SBeq(sb, "i+")
|| SBeq(sb, "i-")
|| SBeq(sb, "i*")
|| SBeq(sb, "i/")
|| SBeq(sb, "i%")
|| SBeq(sb, "i>")
|| SBeq(sb, "i<")
|| SBeq(sb, "pop")
|| SBeq(sb, "$inc")
;
@ -303,6 +310,7 @@ codegen:
printf(" JmpIE __iftail_%d\n", lbl);
break;
}
if (SBeq(&tokenAccumulator, "endif")) {
commentStack(&labelStack);
int lbl = lz_da_pop(labelStack);
@ -411,6 +419,68 @@ codegen:
printf(" pushstack 112\n");
break;
}
if (SBeq(&tokenAccumulator, "i+")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" AddR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "i-")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" SubR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "i*")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" IMulR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "i/")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" IDivR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "i%")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" IModR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "i>")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" ICmp64 98, 97\n");
printf(" JmpIP __Cmp%d\n", counter);
printf(" MovI64 112, 0\n");
printf(" Jmp __DoneCmp%d\n", counter);
printf("__Cmp%d:\n", counter);
printf(" MovI64 112, 1\n");
printf("__DoneCmp%d:\n", counter);
printf(" pushstack 112\n");
break;
}
if (SBeq(&tokenAccumulator, "i<")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" ICmp64 98, 97\n");
printf(" JmpIN __Cmp%d\n", counter);
printf(" MovI64 112, 0\n");
printf(" Jmp __DoneCmp%d\n", counter);
printf("__Cmp%d:\n", counter);
printf(" MovI64 112, 1\n");
printf("__DoneCmp%d:\n", counter);
printf(" pushstack 112\n");
break;
}
if (SBeq(&tokenAccumulator, "pop")) {
printf(" popstack 113\n");
break;
@ -535,7 +605,7 @@ codegen:
}
case TOKEN_STRINGLIT: {
printf(" Jmp endstring%d\n", counter);
printf("string%d db '"LZ_STR_FMT"', 0\n",
printf("string%d db \""LZ_STR_FMT"\", 0\n",
counter,
LZ_STR_PRINTF(tokenAccumulator));
printf("endstring%d:\n", counter);