diff --git a/reid/src/ast/mod.rs b/reid/src/ast/mod.rs index bd0aa5e..99b31da 100644 --- a/reid/src/ast/mod.rs +++ b/reid/src/ast/mod.rs @@ -24,6 +24,13 @@ pub enum TypeKind { U32, U64, U128, + F16, + F16B, + F32, + F64, + F128, + F80, + F128PPC, String, Array(Box, u64), Custom(String), @@ -33,7 +40,8 @@ pub enum TypeKind { #[derive(Debug, Clone)] pub enum Literal { - Number(u64), + Integer(u64), + Decimal(f64), Bool(bool), String(String), } diff --git a/reid/src/ast/parse.rs b/reid/src/ast/parse.rs index b7dd6b8..2810707 100644 --- a/reid/src/ast/parse.rs +++ b/reid/src/ast/parse.rs @@ -53,6 +53,13 @@ impl Parse for Type { "u32" => TypeKind::U32, "u64" => TypeKind::U64, "u128" => TypeKind::U128, + "f16" => TypeKind::F16, + "f16b" => TypeKind::F16B, + "f32" => TypeKind::F32, + "f64" => TypeKind::F64, + "f80" => TypeKind::F80, + "f128" => TypeKind::F128, + "f128ppc" => TypeKind::F128PPC, "string" => TypeKind::String, _ => TypeKind::Custom(ident), } @@ -148,10 +155,25 @@ impl Parse for PrimaryExpression { Expression(Kind::VariableName(v.clone()), stream.get_range().unwrap()) } } - Token::DecimalValue(v) => Expression( - Kind::Literal(Literal::Number(*v)), - stream.get_range().unwrap(), - ), + Token::DecimalValue(v) => { + if let Some(Token::Dot) = stream.peek() { + stream.next(); // Consume dot + let Some(Token::DecimalValue(fractional)) = stream.next() else { + return Err(stream.expected_err("fractional part")?); + }; + let log = (fractional as f64).log10().ceil() as u32; + let value = (*v as f64) + (fractional as f64) / (10u64.pow(log) as f64); + Expression( + Kind::Literal(Literal::Decimal(value)), + stream.get_range_prev().unwrap(), + ) + } else { + Expression( + Kind::Literal(Literal::Integer(*v)), + stream.get_range_prev().unwrap(), + ) + } + } Token::StringLit(v) => Expression( Kind::Literal(Literal::String(v.clone())), stream.get_range().unwrap(), diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs index dcff4fb..cd1c29b 100644 --- a/reid/src/ast/process.rs +++ b/reid/src/ast/process.rs @@ -282,9 +282,10 @@ impl ast::BinaryOperator { impl ast::Literal { fn mir(&self) -> mir::Literal { match &self { - ast::Literal::Number(v) => mir::Literal::Vague(mir::VagueLiteral::Number(*v)), + ast::Literal::Integer(v) => mir::Literal::Vague(mir::VagueLiteral::Number(*v)), ast::Literal::Bool(v) => mir::Literal::Bool(*v), ast::Literal::String(val) => mir::Literal::String(val.clone()), + ast::Literal::Decimal(_) => todo!(), } } } @@ -314,6 +315,13 @@ impl From for mir::TypeKind { ast::TypeKind::Ptr(type_kind) => { mir::TypeKind::UserPtr(Box::new(mir::TypeKind::from(*type_kind.clone()))) } + ast::TypeKind::F16 => todo!(), + ast::TypeKind::F16B => todo!(), + ast::TypeKind::F32 => todo!(), + ast::TypeKind::F64 => todo!(), + ast::TypeKind::F128 => todo!(), + ast::TypeKind::F80 => todo!(), + ast::TypeKind::F128PPC => todo!(), } } } diff --git a/reid/src/mir/typecheck.rs b/reid/src/mir/typecheck.rs index 04a4a93..a257973 100644 --- a/reid/src/mir/typecheck.rs +++ b/reid/src/mir/typecheck.rs @@ -412,7 +412,6 @@ impl Expression { let both_t = lhs_type.collapse_into(&rhs_type)?; - dbg!(&op, &both_t, both_t.signed(), lhs.is_zero(), rhs.is_zero()); if *op == BinaryOperator::Minus && !lhs_type.signed() { if let (Some(lhs_val), Some(rhs_val)) = (lhs.num_value(), rhs.num_value()) { if lhs_val < rhs_val { diff --git a/reid_src/float.reid b/reid_src/float.reid new file mode 100644 index 0000000..7cbe158 --- /dev/null +++ b/reid_src/float.reid @@ -0,0 +1,5 @@ +// Arithmetic, function calls and imports! + +fn OneHalf(var1: f32) -> f32 { + return var1 * 1.5; +}