Add ability to specify variable types in let
This commit is contained in:
		
							parent
							
								
									ea8a833bdf
								
							
						
					
					
						commit
						6634597c92
					
				| @ -45,12 +45,11 @@ Currently missing big features (TODOs) are: | |||||||
| - ~~Built-in Int/Float division and modulo~~ (DONE) | - ~~Built-in Int/Float division and modulo~~ (DONE) | ||||||
| - ~~Loops~~ (DONE) | - ~~Loops~~ (DONE) | ||||||
| - ~~Intrinsic functions~~ (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) | - Debug Information (PARTIALLY DONE) | ||||||
| - Not-Unary | - Not-Unary | ||||||
| - Importing types from other modules | - Importing types from other modules | ||||||
| - Importable binops? | - Importable binops? | ||||||
| - Ability to specify types in variable definitions |  | ||||||
| 
 | 
 | ||||||
| Big features that I want later but are not necessary: | Big features that I want later but are not necessary: | ||||||
| - Associated functions | - Associated functions | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ fn main() -> u32 { | |||||||
|     let mut value = test(); |     let mut value = test(); | ||||||
| 
 | 
 | ||||||
|     let beep = [2, 3, 4]; |     let beep = [2, 3, 4]; | ||||||
|     let boop = 3; |     let boop: f32 = 3; | ||||||
| 
 | 
 | ||||||
|     let mut a = &mut value; |     let mut a = &mut value; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,9 +1,6 @@ | |||||||
| // Arithmetic, function calls and imports! | // Arithmetic, function calls and imports! | ||||||
| 
 | 
 | ||||||
| pub fn test() -> u8 { |  | ||||||
|   return 5; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| pub fn main() -> bool { | pub fn main() -> bool { | ||||||
|   return 7.5 > (test() as f16); |   return 7.5 > 5.001; | ||||||
| } | } | ||||||
|  | |||||||
| @ -531,6 +531,13 @@ impl Parse for LetStatement { | |||||||
|         let mutability = stream.expect(Token::MutKeyword).is_ok(); |         let mutability = stream.expect(Token::MutKeyword).is_ok(); | ||||||
| 
 | 
 | ||||||
|         if let Some(Token::Identifier(variable)) = stream.next() { |         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(); |             let range = stream.get_range_prev().unwrap(); | ||||||
|             stream.expect(Token::Equals)?; |             stream.expect(Token::Equals)?; | ||||||
| 
 | 
 | ||||||
| @ -538,7 +545,7 @@ impl Parse for LetStatement { | |||||||
|             stream.expect(Token::Semi)?; |             stream.expect(Token::Semi)?; | ||||||
|             Ok(LetStatement { |             Ok(LetStatement { | ||||||
|                 name: variable, |                 name: variable, | ||||||
|                 ty: None, |                 ty, | ||||||
|                 mutable: mutability, |                 mutable: mutability, | ||||||
|                 value: expression, |                 value: expression, | ||||||
|                 name_range: range, |                 name_range: range, | ||||||
|  | |||||||
| @ -900,6 +900,13 @@ impl Literal { | |||||||
|                 (L::Vague(VagueL::Number(v)), TypeKind::U32) => L::U32(v as u32), |                 (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::U64) => L::U64(v as u64), | ||||||
|                 (L::Vague(VagueL::Number(v)), TypeKind::U128) => L::U128(v as u128), |                 (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::F16) => L::F16(v as f32), | ||||||
|                 (L::Vague(VagueL::Decimal(v)), TypeKind::F32) => L::F32(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), |                 (L::Vague(VagueL::Decimal(v)), TypeKind::F32B) => L::F32B(v as f32), | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user