Implemented shl and shr

This commit is contained in:
Kyler Olsen 2025-11-29 15:07:52 -07:00
parent 0512147e6d
commit aa8a69b261
1 changed files with 154 additions and 4 deletions

View File

@ -1234,13 +1234,163 @@ Boolean builtin_seed(InterpreterState *interpreter_state) {
}
Boolean builtin_shl(InterpreterState *interpreter_state) {
(void)interpreter_state;
NUMERIC_TYPES;
(void)af;
(void)bf;
if (type & NUMERIC_FLOAT)
return FALSE;
StackItem *node = interpreter_state->stack;
interpreter_state->stack = interpreter_state->stack->next->next;
node->next->next = NULL;
clean_stack(node);
if (type & NUMERIC_SIGNED && type & NUMERIC_64) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I64,
.value = bi << ai,
},
});
} else if (type & NUMERIC_SIGNED && type & NUMERIC_32) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I32,
.value = bi << ai,
},
});
} else if (type & NUMERIC_SIGNED && type & NUMERIC_16) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I16,
.value = bi << ai,
},
});
} else if (type & NUMERIC_SIGNED) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I8,
.value = bi << ai,
},
});
} else if (type & NUMERIC_64) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U64,
.value = bi << ai,
},
});
} else if (type & NUMERIC_32) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U32,
.value = bi << ai,
},
});
} else if (type & NUMERIC_16) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U16,
.value = bi << ai,
},
});
} else {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U8,
.value = bi << ai,
},
});
}
}
Boolean builtin_shr(InterpreterState *interpreter_state) {
(void)interpreter_state;
NUMERIC_TYPES;
(void)af;
(void)bf;
if (type & NUMERIC_FLOAT)
return FALSE;
StackItem *node = interpreter_state->stack;
interpreter_state->stack = interpreter_state->stack->next->next;
node->next->next = NULL;
clean_stack(node);
if (type & NUMERIC_SIGNED && type & NUMERIC_64) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I64,
.value = bi >> ai,
},
});
} else if (type & NUMERIC_SIGNED && type & NUMERIC_32) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I32,
.value = bi >> ai,
},
});
} else if (type & NUMERIC_SIGNED && type & NUMERIC_16) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I16,
.value = bi >> ai,
},
});
} else if (type & NUMERIC_SIGNED) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_I8,
.value = bi >> ai,
},
});
} else if (type & NUMERIC_64) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U64,
.value = bi >> ai,
},
});
} else if (type & NUMERIC_32) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U32,
.value = bi >> ai,
},
});
} else if (type & NUMERIC_16) {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U16,
.value = bi >> ai,
},
});
} else {
return push_token(interpreter_state, (Token){
.type = TOKEN_INTEGER,
.integer_literal = (IntegerLiteral){
.type = INTEGER_U8,
.value = bi >> ai,
},
});
}
}
Boolean builtin_sin(InterpreterState *interpreter_state) {