Error fixes

This commit is contained in:
Kyler Olsen 2025-11-29 14:03:22 -07:00
parent b402f32e68
commit 2086ee503d
1 changed files with 9 additions and 39 deletions

View File

@ -440,7 +440,6 @@ Boolean load_builtins(InterpreterState *interpreter_state) {
uint64_t ai = 0; \ uint64_t ai = 0; \
uint64_t type = 0; \ uint64_t type = 0; \
if (interpreter_state->stack == NULL) return FALSE; \ if (interpreter_state->stack == NULL) return FALSE; \
if (interpreter_state->stack->next == NULL) return FALSE; \
\ \
switch (interpreter_state->stack->type) { \ switch (interpreter_state->stack->type) { \
case STACK_IDENTIFIER: \ case STACK_IDENTIFIER: \
@ -917,7 +916,10 @@ Boolean builtin_not_equal_to(InterpreterState *interpreter_state) {
} }
Boolean builtin_abs(InterpreterState *interpreter_state) { Boolean builtin_abs(InterpreterState *interpreter_state) {
NUMERIC_TYPES; NUMERIC_TYPE;
if (!((type & NUMERIC_SIGNED) | (type & NUMERIC_FLOAT)))
return FALSE;
StackItem *node = interpreter_state->stack; StackItem *node = interpreter_state->stack;
interpreter_state->stack = interpreter_state->stack->next; interpreter_state->stack = interpreter_state->stack->next;
@ -939,7 +941,7 @@ Boolean builtin_abs(InterpreterState *interpreter_state) {
.type = TOKEN_INTEGER, .type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){ .integer_literal = (IntegerLiteral){
.type = INTEGER_I64, .type = INTEGER_I64,
.value = abs(ai), .value = labs((int64_t)ai),
}, },
}); });
} else if (type & NUMERIC_SIGNED && type & NUMERIC_32) { } else if (type & NUMERIC_SIGNED && type & NUMERIC_32) {
@ -947,7 +949,7 @@ Boolean builtin_abs(InterpreterState *interpreter_state) {
.type = TOKEN_INTEGER, .type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){ .integer_literal = (IntegerLiteral){
.type = INTEGER_I32, .type = INTEGER_I32,
.value = abs(ai), .value = labs((int64_t)ai),
}, },
}); });
} else if (type & NUMERIC_SIGNED && type & NUMERIC_16) { } else if (type & NUMERIC_SIGNED && type & NUMERIC_16) {
@ -955,47 +957,15 @@ Boolean builtin_abs(InterpreterState *interpreter_state) {
.type = TOKEN_INTEGER, .type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){ .integer_literal = (IntegerLiteral){
.type = INTEGER_I16, .type = INTEGER_I16,
.value = abs(ai), .value = labs((int64_t)ai),
},
});
} else if (type & NUMERIC_SIGNED) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I8,
.value = abs(ai),
},
});
} else if (type & NUMERIC_64) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U64,
.value = abs(ai),
},
});
} else if (type & NUMERIC_32) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U32,
.value = abs(ai),
},
});
} else if (type & NUMERIC_16) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U16,
.value = abs(ai),
}, },
}); });
} else { } else {
return push_token(interpreter_state, (Token){ return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER, .type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){ .integer_literal = (IntegerLiteral){
.type = INTEGER_U8, .type = INTEGER_I8,
.value = abs(ai), .value = labs((int64_t)ai),
}, },
}); });
} }