formatting and shi

This commit is contained in:
2026-06-18 22:34:42 +02:00
parent 25a7829788
commit 3e1d0ba5d9
8 changed files with 343 additions and 331 deletions

View File

@@ -37,3 +37,5 @@ IndentGotoLabels: true
BinPackArguments: false
BinPackParameters: false
InsertTrailingCommas: Wrapped

View File

@@ -30,7 +30,9 @@
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡘⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
typedef struct noomC_LocalInfo {
enum { NOOMC_GLOBAL, NOOMC_LOCAL, NOOMC_UPVAL } type;
enum { NOOMC_GLOBAL,
NOOMC_LOCAL,
NOOMC_UPVAL } type;
unsigned int idx;
} noomC_LocalInfo;
@@ -165,8 +167,7 @@ static noom_Exit noomC_compile_expr(
noomC_Compiler* compiler,
const noomP_Parser* parser,
noomV_Function* func,
const noomP_Node *node
) {
const noomP_Node* node) {
noom_Exit result;
// Baba is You OST is a very cool soundtrack to code to Can recommend
if (node->type == NOOMP_NODE_NILLITERAL) {
@@ -313,12 +314,10 @@ static noom_Exit noomC_add_stuff_to_function(noom_LuaVM *vm, noomC_Compiler *com
if (noom_memeq(ap, al, "close", 5)) {
if (local.close) return NOOM_EINTERNAL;
local.close = 1;
}
else if (noom_memeq(ap, al, "const", 5)) {
} else if (noom_memeq(ap, al, "const", 5)) {
if (local.constant) return NOOM_EINTERNAL;
local.constant = 1;
}
else {
} else {
return NOOM_EINTERNAL;
}
}
@@ -331,8 +330,7 @@ static noom_Exit noomC_add_stuff_to_function(noom_LuaVM *vm, noomC_Compiler *com
result = noomC_emit_Aus(func, NOOMV_INSTR_PUSHNIL, 0, 0);
if (result != NOOM_OK) return result;
compiler->curstack++;
}
else {
} else {
const noomP_Node* value_node = node->subnodes[1];
const noom_Exit r = noomC_compile_expr(vm, compiler, parser, func, value_node);
if (r != NOOM_OK) return r;

View File

@@ -50,7 +50,7 @@ noom_uint_t noom_format_error(const noomP_Parser* parser, const char* program_na
[NOOMP_ERROR_EXPRESSION_NOT_STATEMENT] = {"loose expression is not a valid statement", 1},
[NOOMP_ERROR_FAKEATTRIBUTE] = {"invalid attribute", 2},
[NOOMP_ERROR_RETURN_NOT_END] = {"'return' must be the last statement in a block\n", 0},
[NOOMP_ERROR_FOR_WRONG_AMOUNT] = {"'for' initializer must have 2 or 3 expressions\n", 0}
[NOOMP_ERROR_FOR_WRONG_AMOUNT] = {"'for' initializer must have 2 or 3 expressions\n", 0},
};
static const struct noom_error lexer_errors[] = {
@@ -84,8 +84,7 @@ noom_uint_t noom_format_error(const noomP_Parser* parser, const char* program_na
if (parser->code[i] == '\n') {
row++;
column = 1;
}
else {
} else {
column++;
}
}

View File

@@ -123,7 +123,6 @@ noom_uint_t noomL_getnumber(const char* s, noomL_ErrorType* error, noom_LuaVersi
return 0;
}
}
}
if (len == 2) { // nothing after the x; malformed number.
@@ -202,7 +201,10 @@ noom_uint_t noomL_getcomment(const char* str, noomL_ErrorType* error) {
if (str[len] == '[') {
len++;
while (str[len] == '=') { longb_len++; len++; }
while (str[len] == '=') {
longb_len++;
len++;
}
if (str[len] == '[') {
// yay long bracket!
@@ -223,7 +225,10 @@ noom_uint_t noomL_getcomment(const char* str, noomL_ErrorType* error) {
noom_uint_t spos = len; // after the ] intentionally
noom_uint_t testlong = 0;
while (str[len] == '=') { testlong++; len++; }
while (str[len] == '=') {
testlong++;
len++;
}
if (str[len] == ']') { // actual long bracket! holy shit!
len++;
@@ -304,7 +309,8 @@ noom_uint_t noomL_getstring(const char* s, noomL_ErrorType* error, noom_LuaVersi
// fuckkkk
noom_uint_t count = 0;
for (noom_uint_t i = 0; i < 3; i++) {
if (noomL_isnumber(s[len + i])) count++; else break;
if (noomL_isnumber(s[len + i])) count++;
else break;
}
if (count == 3) { // could be too big
if ((s[len] > '2') || (s[len] == '2' && (s[len + 1] > '5' || (s[len + 1] == '5' && s[len + 2] > '5')))) {
@@ -397,9 +403,15 @@ noom_uint_t noomL_getstring(const char* s, noomL_ErrorType* error, noom_LuaVersi
noom_uint_t order = 0;
int succ = 0;
while (s[len] == '=') { order++; len++; }
while (s[len] == '=') {
order++;
len++;
}
if (s[len] == '[') { len++; succ = 1; }
if (s[len] == '[') {
len++;
succ = 1;
}
if (succ) { // it is a multi-line string.
while (1) {
@@ -408,7 +420,10 @@ noom_uint_t noomL_getstring(const char* s, noomL_ErrorType* error, noom_LuaVersi
noom_uint_t order2 = 0;
noom_uint_t startp = len; // intentionally after the `]`
while (s[len] == '=') { order2++; len++; }
while (s[len] == '=') {
order2++;
len++;
}
if (s[len] == ']' && order == order2) { // holy shit it's real
len++;
@@ -487,7 +502,6 @@ const char *noomL_formatTokenType(noomL_TokenType token_type) {
default:
return "unknown";
}
}
noomL_ErrorType noomL_lex(const char* s, noom_uint_t start, noomL_Token* token, noom_LuaVersion version) {

View File

@@ -82,8 +82,7 @@ int the_theoretical_function_to_execute_your_code_that_should_be_replaced_later(
puts("\x1b[0m");
puts("PARSE OUTPUT:");
print_node(program, 0);
}
else {
} else {
noom_uint_t bleh = noom_format_error(&parser, program_name, NULL, 0);
char* buf = noom_alloc(bleh);
noom_format_error(&parser, program_name, buf, bleh);
@@ -153,8 +152,7 @@ static int read_prompt(char* buf, int buf_size, char* prompt, const int required
const size_t len = noom_strlen(buf);
if (len > 0 && buf[len - 1] != '\n') {
while (getchar() != '\n' && !feof(stdin));
}
else if (len > 0) {
} else if (len > 0) {
buf[len - 1] = '\0';
}
} while (buf[0] == '\0' && required);
@@ -242,7 +240,8 @@ int main(int argc, char **argv) {
char* code = read_file(params.script_path);
if (code == 0) return 1;
int offset = 0;
if (code[0] == '#' && code[1] == '!') for (offset = 2; code[offset] && code[offset] != '\n'; offset++);
if (code[0] == '#' && code[1] == '!')
for (offset = 2; code[offset] && code[offset] != '\n'; offset++);
int e = the_theoretical_function_to_execute_your_code_that_should_be_replaced_later(code + offset, argv[0], params.script_path);
noom_free(code);
return e;
@@ -269,6 +268,8 @@ die:
" - execute stdin\n"
" -e stat execute string 'stat'\n"
" -v show version\n",
argv[0], err, argv[0]);
argv[0],
err,
argv[0]);
return 1;
}

View File

@@ -480,7 +480,6 @@ noomP_Node* noomP_parseComplexExpression(noomP_Parser* parser, noomP_Node* snode
return 0; // unexpected :(
}
node = new;
} else {
return node; // done
@@ -705,7 +704,6 @@ int noomP_infixOperatorBP(noomP_Parser* parser, noomL_Token* token, noom_uint_t*
*b = 63;
return 1;
// oh boy.
} else if (noom_memeq(parser->code + token->offset, token->length, "<", 1)) {
*a = 50;