Added basic putuint to the standard library, i need to implement proper 0 handling but that probably needs and if statement

This commit is contained in:
cannoli-fruit 2026-07-26 01:48:43 -04:00
commit 5b7dd220ae
6 changed files with 94 additions and 2 deletions

View file

@ -85,6 +85,9 @@ static inline bool isKW(Lz_SB *sb) {
|| SBeq(sb, "u-")
|| SBeq(sb, "u*")
|| SBeq(sb, "u/")
|| SBeq(sb, "u%")
|| SBeq(sb, "u>")
|| SBeq(sb, "u<")
|| SBeq(sb, "pop")
|| SBeq(sb, "$inc")
;
@ -276,6 +279,47 @@ codegen:
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "u-")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" SubR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "u*")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" MulR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "u/")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" DivR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "u%")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" ModR64 98, 97\n");
printf(" pushstack 98\n");
break;
}
if (SBeq(&tokenAccumulator, "u>")) {
printf(" popstack 97\n");
printf(" popstack 98\n");
printf(" Cmp64 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, "pop")) {
printf(" popstack 113\n");
break;
@ -354,7 +398,7 @@ codegen:
if (tokenAccumulator.cnt < 128) {
memcpy(varName, tokenAccumulator.data+1,
tokenAccumulator.cnt-1);
varName[tokenAccumulator.cnt] = 0;
varName[tokenAccumulator.cnt-1] = 0;
} else {
memcpy(varName, tokenAccumulator.data+1, 127);
varName[127] = 0;
@ -367,7 +411,7 @@ codegen:
}
}
if (addr == 0) {
fprintf(stderr, "Undeclared variable %s in function %s",
fprintf(stderr, "Undeclared variable %s in function %s\n",
varName, funcName);
exit(1);
}