diff --git a/examples/loops.reid b/examples/loops.reid index 8d66fe6..2c07934 100644 --- a/examples/loops.reid +++ b/examples/loops.reid @@ -1,9 +1,12 @@ // Arithmetic, function calls and imports! +import std::print; +import std::from_str; fn main() -> u32 { - for i in 0 to 10 { - print("hello") + let text = from_str("hello"); + for i in 0 .. 10 { + print(&text) } let mut num = 0; diff --git a/reid-llvm-lib/src/builder.rs b/reid-llvm-lib/src/builder.rs index 949a147..67de72b 100644 --- a/reid-llvm-lib/src/builder.rs +++ b/reid-llvm-lib/src/builder.rs @@ -440,7 +440,6 @@ impl Builder { } Instr::GetStructElemPtr(ptr_val, idx) => { let ptr_ty = ptr_val.get_type(&self)?; - dbg!(&ptr_ty); if let Type::Ptr(ty) = ptr_ty { if let Type::CustomType(val) = *ty { match self.type_data(&val).kind { diff --git a/reid/src/ast/parse.rs b/reid/src/ast/parse.rs index 34edad4..dfc519e 100644 --- a/reid/src/ast/parse.rs +++ b/reid/src/ast/parse.rs @@ -155,11 +155,12 @@ impl Parse for PrimaryExpression { } Token::DecimalValue(v) => { stream.next(); // Consume decimal - if let Some(Token::Dot) = stream.peek() { + if let (Some(Token::Dot), Some(Token::DecimalValue(fractional))) = + (stream.peek(), stream.peek2()) + { stream.next(); // Consume dot - let Some(Token::DecimalValue(fractional)) = stream.next() else { - return Err(stream.expected_err("fractional part")?); - }; + stream.next(); // Consume fractional + Expression( Kind::Literal(Literal::Decimal( format!("{}.{}", v, fractional) @@ -706,7 +707,8 @@ impl Parse for ForStatement { let start_range = stream.get_range().unwrap(); stream.expect(Token::In)?; let start = stream.parse()?; - stream.expect(Token::To)?; + stream.expect(Token::Dot)?; + stream.expect(Token::Dot)?; let end = stream.parse()?; Ok(ForStatement(idx, start_range, start, end, stream.parse()?)) diff --git a/reid/src/codegen.rs b/reid/src/codegen.rs index 5fd776b..ddb69c6 100644 --- a/reid/src/codegen.rs +++ b/reid/src/codegen.rs @@ -1001,7 +1001,6 @@ impl mir::Expression { let TypeKind::CodegenPtr(inner) = &struct_val.1 else { panic!("tried accessing non-pointer"); }; - dbg!(&inner); let TypeKind::CustomType(key) = *inner.clone() else { panic!("tried accessing non-custom-type"); }; diff --git a/reid/src/lexer.rs b/reid/src/lexer.rs index 176ef92..97f1f6f 100644 --- a/reid/src/lexer.rs +++ b/reid/src/lexer.rs @@ -46,11 +46,7 @@ pub enum Token { While, /// `for` For, - /// `from` - From, - /// `to` - To, - /// `to` + /// `In` In, // Symbols @@ -147,9 +143,7 @@ impl ToString for Token { Token::Struct => String::from("struct"), Token::AsKeyword => String::from("as"), Token::For => String::from("for"), - Token::From => String::from("from"), Token::In => String::from("in"), - Token::To => String::from("to"), Token::While => String::from("while"), Token::Semi => String::from(';'), Token::Equals => String::from('='), @@ -340,8 +334,6 @@ pub fn tokenize>(to_tokenize: T) -> Result, Error "for" => Token::For, "while" => Token::While, "in" => Token::In, - "from" => Token::From, - "to" => Token::To, _ => Token::Identifier(value), }; variant diff --git a/reid/src/mir/typecheck.rs b/reid/src/mir/typecheck.rs index 3819ddb..653b256 100644 --- a/reid/src/mir/typecheck.rs +++ b/reid/src/mir/typecheck.rs @@ -335,7 +335,14 @@ impl Block { None } } - StmtKind::While(while_statement) => todo!(), + StmtKind::While(WhileStatement { + condition, block, .. + }) => { + condition.typecheck(&mut state, typerefs, Some(&TypeKind::Bool))?; + block.typecheck(&mut state, typerefs, None)?; + + None + } }; if let Some((ReturnKind::Hard, _)) = ret { diff --git a/reid/src/mir/typeinference.rs b/reid/src/mir/typeinference.rs index c7e10f5..cfb1bcb 100644 --- a/reid/src/mir/typeinference.rs +++ b/reid/src/mir/typeinference.rs @@ -16,6 +16,7 @@ use super::{ IfExpression, Module, ReturnKind, StmtKind, TypeKind::*, VagueType::*, + WhileStatement, }; /// Struct used to implement Type Inference, where an intermediary @@ -126,7 +127,12 @@ impl Block { let expr_res = expr.infer_types(&mut state, &inner_refs); state.ok(expr_res, expr.1); } - StmtKind::While(while_statement) => todo!(), + StmtKind::While(WhileStatement { + condition, block, .. + }) => { + condition.infer_types(&mut state, &inner_refs)?; + block.infer_types(&mut state, &inner_refs)?; + } }; }