1
0
Fork 0

Fix bug with max-sized ints

This commit is contained in:
Vili Sinervä 2025-02-26 19:29:36 +02:00
parent dc5c5940ef
commit 50d3d60a7f
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
4 changed files with 5 additions and 4 deletions

View file

@ -40,7 +40,7 @@ impl<'source> fmt::Display for AstNode<'source> {
#[derive(Debug, PartialEq, Clone)]
pub enum Expression<'source> {
EmptyLiteral(),
IntLiteral(i64),
IntLiteral(i128),
BoolLiteral(bool),
Identifier(&'source str),
UnaryOp(&'source str, Box<AstNode<'source>>),

View file

@ -109,7 +109,8 @@ fn visit_ast_node<'source>(
EmptyLiteral() => add_var(&Type::Unit, types),
IntLiteral(val) => {
let var = add_var(&Type::Int, types);
instructions.push(IrInstruction::new(ast.loc, LoadIntConst(*val, var.clone())));
let val = *val as i64;
instructions.push(IrInstruction::new(ast.loc, LoadIntConst(val, var.clone())));
var
}
BoolLiteral(val) => {

View file

@ -275,7 +275,7 @@ fn parse_int_literal<'source>(pos: &mut usize, tokens: &[Token]) -> AstNode<'sou
let expr = IntLiteral(
token
.text
.parse::<i64>()
.parse::<i128>()
.unwrap_or_else(|_| panic!("Fatal parser error! Invalid value in token {token}")),
);

View file

@ -10,7 +10,7 @@ pub enum Type {
#[derive(PartialEq, PartialOrd, Debug, Copy, Clone)]
pub enum Value {
Int(i64),
Int(i128),
Bool(bool),
Func(fn(&[Value]) -> Value),
None(),