From 374a5d5c5dc158179ec15b6511b0a558669a4ab9 Mon Sep 17 00:00:00 2001 From: zongor Date: Mon, 16 Feb 2026 22:53:04 -0800 Subject: [PATCH] remove unnecessary code --- src/tools/compiler/compiler.c | 134 +--------------------------------- 1 file changed, 4 insertions(+), 130 deletions(-) diff --git a/src/tools/compiler/compiler.c b/src/tools/compiler/compiler.c index 91e2ade..93db49b 100644 --- a/src/tools/compiler/compiler.c +++ b/src/tools/compiler/compiler.c @@ -98,76 +98,6 @@ u32 get_ref(ScopeTable *st, const char *name, u32 length) { return sym->ref; } -u32 get_ptr(Token token, ScopeTable *st) { - if (token.type == TOKEN_IDENTIFIER) { - return get_ref(st, token.start, token.length); - } - - if (token.type == TOKEN_LITERAL_INT) { - return atoi(token.start); - } - - if (token.type == TOKEN_LITERAL_NAT) { - char *endptr; - u32 out = (u32)strtoul(token.start, &endptr, 10); - if (endptr == token.start || *endptr != '\0') { - fprintf(stderr, "Invalid decimal literal at line %d: %.*s\n", token.line, - token.length, token.start); - exit(1); - } - return out; - } - - fprintf(stderr, "Error: Not a pointer or symbol at line %d: %.*s\n", - token.line, token.length, token.start); - exit(1); -} - -u32 get_reg(Token token, ScopeTable *st) { - if (token.type == TOKEN_IDENTIFIER) { - return get_ref(st, token.start, token.length); - } - - if (token.type == TOKEN_BIG_MONEY) { - token = next_token(); - return atoi(token.start); - } - - fprintf(stderr, "Error: Not a register or symbol at line %d: %.*s\n", - token.line, token.length, token.start); - exit(1); -} - -Token next_id_or_reg() { - Token token = next_token(); - if (token.type == TOKEN_IDENTIFIER) { - return token; - } - - if (token.type == TOKEN_BIG_MONEY) { - token = next_token(); - return token; - } - - printf("Not an ID or register at line %d: %.*s\n", token.line, token.length, - token.start); - exit(1); - - return token; -} - -Token next_id_or_ptr() { - Token token = next_token(); - - if (token.type != TOKEN_IDENTIFIER && token.type != TOKEN_LITERAL_NAT && - token.type != TOKEN_LITERAL_INT && token.type != TOKEN_LITERAL_REAL) { - printf("Not an ID or register at line %d: %.*s\n", token.line, token.length, - token.start); - exit(1); - } - return token; -} - Token next_token_is(TokenType type) { Token token = next_token(); if (token.type != type) { @@ -268,7 +198,7 @@ void define_plex(VM *vm, ScopeTable *st) { */ void define_function(VM *vm, ScopeTable *st) { Symbol s; - s.scope = GLOBAL; + s.scope = LOCAL; s.type = FUNCTION; Token name = next_token_is(TOKEN_IDENTIFIER); @@ -513,7 +443,7 @@ void build_symbol_table(VM *vm, char *source, ScopeTable *st) { continue; } - get_reg(next, st); + get_ref(st, next.start, next.length); vm->cp++; next_token_is(TOKEN_SEMICOLON); continue; @@ -524,63 +454,7 @@ void build_symbol_table(VM *vm, char *source, ScopeTable *st) { #endif if (token.type == TOKEN_IDENTIFIER) { /* check to see if it is an opcode first */ - if (strleq(token.start, "exit", token.length)) { - - vm->cp++; - - next_token(); - vm->cp += 4; - -#ifdef DEBUG_PRINT - printf("code[%d] = exit\n", vm->cp); -#endif - - next_token_is(TOKEN_SEMICOLON); - } else if (strleq(token.start, "call", token.length)) { - - vm->cp++; - - next_token_is(TOKEN_IDENTIFIER); - vm->cp += 4; - - vm->cp++; - Token next = next_token_is(TOKEN_LPAREN); - next = next_token(); - while (next.type != TOKEN_RPAREN) { - get_reg(next, st); - vm->cp++; - next = next_token(); - } - - next = next_token(); - if (next.type == TOKEN_SEMICOLON) { - vm->cp++; - } else { - next = next_token(); - get_reg(next, st); - vm->cp++; - } -#ifdef DEBUG_PRINT - printf("code[%d] = call\n", vm->cp); -#endif - continue; - } else if (strleq(token.start, "syscall", token.length)) { - - vm->cp++; - - Token next = next_token(); - vm->cp += 4; - - next = next_token(); - while (next.type != TOKEN_SEMICOLON) { - get_reg(next, st); - vm->cp++; - next = next_token(); - } -#ifdef DEBUG_PRINT - printf("code[%d] = syscall\n", vm->cp); -#endif - continue; + if (false) { } else { /* some other identifier */ printf("Unknown id at line %d: %.*s\n", token.line, token.length, @@ -675,7 +549,7 @@ void emit_bytecode(VM *vm, char *source, ScopeTable *st) { continue; } - u32 reg = get_reg(next, st); + u32 reg = get_ref(st, next.start, next.length); emit_byte(vm, reg); vm->cp++; next_token_is(TOKEN_SEMICOLON);