diff --git a/README.md b/README.md index 23425e7..ff37776 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,11 @@ Currently missing big features (TODOs) are: - ~~Built-in Int/Float division and modulo~~ (DONE) - ~~Loops~~ (DONE) - ~~Intrinsic functions~~ (DONE) -- ~~Ability to specify types in literals~~ (DONE) +- ~~Ability to specify types in literals and variable definitions~~ (DONE) - Debug Information (PARTIALLY DONE) - Not-Unary - Importing types from other modules - Importable binops? -- Ability to specify types in variable definitions Big features that I want later but are not necessary: - Associated functions diff --git a/examples/array_structs.reid b/examples/array_structs.reid index e94fc0d..5daea58 100644 --- a/examples/array_structs.reid +++ b/examples/array_structs.reid @@ -17,7 +17,7 @@ fn main() -> u32 { let mut value = test(); let beep = [2, 3, 4]; - let boop = 3; + let boop: f32 = 3; let mut a = &mut value; diff --git a/examples/float.reid b/examples/float.reid index ebf0393..10e5e3e 100644 --- a/examples/float.reid +++ b/examples/float.reid @@ -1,9 +1,6 @@ // Arithmetic, function calls and imports! -pub fn test() -> u8 { - return 5; -} pub fn main() -> bool { - return 7.5 > (test() as f16); + return 7.5 > 5.001; } diff --git a/reid/src/ast/parse.rs b/reid/src/ast/parse.rs index 5e70e1f..7e36869 100644 --- a/reid/src/ast/parse.rs +++ b/reid/src/ast/parse.rs @@ -531,6 +531,13 @@ impl Parse for LetStatement { let mutability = stream.expect(Token::MutKeyword).is_ok(); if let Some(Token::Identifier(variable)) = stream.next() { + let ty = if let Some(Token::Colon) = stream.peek() { + stream.next(); // Consume colon + Some(stream.parse()?) + } else { + None + }; + let range = stream.get_range_prev().unwrap(); stream.expect(Token::Equals)?; @@ -538,7 +545,7 @@ impl Parse for LetStatement { stream.expect(Token::Semi)?; Ok(LetStatement { name: variable, - ty: None, + ty, mutable: mutability, value: expression, name_range: range, diff --git a/reid/src/mir/typecheck.rs b/reid/src/mir/typecheck.rs index 31c9269..465c15a 100644 --- a/reid/src/mir/typecheck.rs +++ b/reid/src/mir/typecheck.rs @@ -900,6 +900,13 @@ impl Literal { (L::Vague(VagueL::Number(v)), TypeKind::U32) => L::U32(v as u32), (L::Vague(VagueL::Number(v)), TypeKind::U64) => L::U64(v as u64), (L::Vague(VagueL::Number(v)), TypeKind::U128) => L::U128(v as u128), + (L::Vague(VagueL::Number(v)), TypeKind::F16) => L::F16(v as f32), + (L::Vague(VagueL::Number(v)), TypeKind::F32) => L::F32(v as f32), + (L::Vague(VagueL::Number(v)), TypeKind::F32B) => L::F32B(v as f32), + (L::Vague(VagueL::Number(v)), TypeKind::F64) => L::F64(v as f64), + (L::Vague(VagueL::Number(v)), TypeKind::F80) => L::F80(v as f64), + (L::Vague(VagueL::Number(v)), TypeKind::F128) => L::F128(v as f64), + (L::Vague(VagueL::Number(v)), TypeKind::F128PPC) => L::F128PPC(v as f64), (L::Vague(VagueL::Decimal(v)), TypeKind::F16) => L::F16(v as f32), (L::Vague(VagueL::Decimal(v)), TypeKind::F32) => L::F32(v as f32), (L::Vague(VagueL::Decimal(v)), TypeKind::F32B) => L::F32B(v as f32),