Fix bug with max-sized ints
This commit is contained in:
parent
dc5c5940ef
commit
50d3d60a7f
4 changed files with 5 additions and 4 deletions
|
@ -40,7 +40,7 @@ impl<'source> fmt::Display for AstNode<'source> {
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Expression<'source> {
|
pub enum Expression<'source> {
|
||||||
EmptyLiteral(),
|
EmptyLiteral(),
|
||||||
IntLiteral(i64),
|
IntLiteral(i128),
|
||||||
BoolLiteral(bool),
|
BoolLiteral(bool),
|
||||||
Identifier(&'source str),
|
Identifier(&'source str),
|
||||||
UnaryOp(&'source str, Box<AstNode<'source>>),
|
UnaryOp(&'source str, Box<AstNode<'source>>),
|
||||||
|
|
|
@ -109,7 +109,8 @@ fn visit_ast_node<'source>(
|
||||||
EmptyLiteral() => add_var(&Type::Unit, types),
|
EmptyLiteral() => add_var(&Type::Unit, types),
|
||||||
IntLiteral(val) => {
|
IntLiteral(val) => {
|
||||||
let var = add_var(&Type::Int, types);
|
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
|
var
|
||||||
}
|
}
|
||||||
BoolLiteral(val) => {
|
BoolLiteral(val) => {
|
||||||
|
|
|
@ -275,7 +275,7 @@ fn parse_int_literal<'source>(pos: &mut usize, tokens: &[Token]) -> AstNode<'sou
|
||||||
let expr = IntLiteral(
|
let expr = IntLiteral(
|
||||||
token
|
token
|
||||||
.text
|
.text
|
||||||
.parse::<i64>()
|
.parse::<i128>()
|
||||||
.unwrap_or_else(|_| panic!("Fatal parser error! Invalid value in token {token}")),
|
.unwrap_or_else(|_| panic!("Fatal parser error! Invalid value in token {token}")),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub enum Type {
|
||||||
|
|
||||||
#[derive(PartialEq, PartialOrd, Debug, Copy, Clone)]
|
#[derive(PartialEq, PartialOrd, Debug, Copy, Clone)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
Int(i64),
|
Int(i128),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Func(fn(&[Value]) -> Value),
|
Func(fn(&[Value]) -> Value),
|
||||||
None(),
|
None(),
|
||||||
|
|
Reference in a new issue