diff --git a/SLS_C/src/builtin.c b/SLS_C/src/builtin.c index 630bba6..a58b379 100644 --- a/SLS_C/src/builtin.c +++ b/SLS_C/src/builtin.c @@ -440,7 +440,6 @@ Boolean load_builtins(InterpreterState *interpreter_state) { uint64_t ai = 0; \ uint64_t type = 0; \ if (interpreter_state->stack == NULL) return FALSE; \ - if (interpreter_state->stack->next == NULL) return FALSE; \ \ switch (interpreter_state->stack->type) { \ case STACK_IDENTIFIER: \ @@ -917,7 +916,10 @@ Boolean builtin_not_equal_to(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; interpreter_state->stack = interpreter_state->stack->next; @@ -939,7 +941,7 @@ Boolean builtin_abs(InterpreterState *interpreter_state) { .type = TOKEN_INTEGER, .integer_literal = (IntegerLiteral){ .type = INTEGER_I64, - .value = abs(ai), + .value = labs((int64_t)ai), }, }); } else if (type & NUMERIC_SIGNED && type & NUMERIC_32) { @@ -947,7 +949,7 @@ Boolean builtin_abs(InterpreterState *interpreter_state) { .type = TOKEN_INTEGER, .integer_literal = (IntegerLiteral){ .type = INTEGER_I32, - .value = abs(ai), + .value = labs((int64_t)ai), }, }); } else if (type & NUMERIC_SIGNED && type & NUMERIC_16) { @@ -955,47 +957,15 @@ Boolean builtin_abs(InterpreterState *interpreter_state) { .type = TOKEN_INTEGER, .integer_literal = (IntegerLiteral){ .type = INTEGER_I16, - .value = abs(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), + .value = labs((int64_t)ai), }, }); } else { return push_token(interpreter_state, (Token){ .type = TOKEN_INTEGER, .integer_literal = (IntegerLiteral){ - .type = INTEGER_U8, - .value = abs(ai), + .type = INTEGER_I8, + .value = labs((int64_t)ai), }, }); }