diff --git a/language/data/src/tokens.rs b/language/data/src/tokens.rs index 9b8e5939..b974a72b 100644 --- a/language/data/src/tokens.rs +++ b/language/data/src/tokens.rs @@ -177,8 +177,16 @@ pub enum TokenTypes { CodeEnd = 35, /// A variable name Variable = 36, - /// An integer - Integer = 37, + /// Integers + IntegerI8 = 37, + IntegerI16 = 72, // Note number pattern break + IntegerI32 = 73, + IntegerI64 = 74, + + IntegerU8 = 75, + IntegerU16 = 76, + IntegerU32 = 77, + IntegerU64 = 78, /// A float Float = 38, /// A type being called, always comes after a period (like variable.method()) @@ -250,4 +258,6 @@ pub enum TokenTypes { Char = 70, /// A blank line BlankLine = 71, + // Added Integer Types take 72 - 78 + } diff --git a/language/parser/src/parser/code_parser.rs b/language/parser/src/parser/code_parser.rs index be70a599..16a28a69 100644 --- a/language/parser/src/parser/code_parser.rs +++ b/language/parser/src/parser/code_parser.rs @@ -6,7 +6,7 @@ use std::mem; use syntax::async_util::UnparsedType; use syntax::errors::ParsingError; use syntax::errors::{ErrorSource, ParsingMessage}; -use syntax::program::code::{EffectType, Effects, Expression, ExpressionType}; +use syntax::program::code::{EffectType, Effects, Expression, ExpressionType, IntType}; use syntax::program::function::CodeBody; /// Parsers a block of code into its return type (if all code paths lead to a single type, or else a line) and the code body. @@ -61,7 +61,14 @@ pub fn parse_line(parser_utils: &mut ParserUtils, state: ParseState) -> Result { + TokenTypes::IntegerI8 | TokenTypes::IntegerI16 | TokenTypes::IntegerI32 | TokenTypes::IntegerI64 | + TokenTypes::IntegerU8 | TokenTypes::IntegerU16 | TokenTypes::IntegerU32 | TokenTypes::IntegerU64 => { *effect = Some(Effects::new( Span::new(parser_utils.file, parser_utils.index), - EffectType::Int(token.to_string(parser_utils.buffer).parse().unwrap()), + EffectType::Int(token.to_string(parser_utils.buffer).parse().unwrap(), match token.token_type { + TokenTypes::IntegerI8 => IntType::I8, + TokenTypes::IntegerI16 => IntType::I16, + TokenTypes::IntegerI32 => IntType::I32, + TokenTypes::IntegerI64 => IntType::I64, + TokenTypes::IntegerU8 => IntType::U8, + TokenTypes::IntegerU16 => IntType::U16, + TokenTypes::IntegerU32 => IntType::U32, + TokenTypes::IntegerU64 => IntType::U64, + _ => panic!(), + + }), )); ControlFlow::Skipping - } + } TokenTypes::Char => { *effect = Some(Effects::new( Span::new(parser_utils.file, parser_utils.index), diff --git a/language/syntax/src/program/code.rs b/language/syntax/src/program/code.rs index 19228c8f..ba4f3c21 100644 --- a/language/syntax/src/program/code.rs +++ b/language/syntax/src/program/code.rs @@ -168,10 +168,13 @@ pub enum EffectType { CreateArray(Vec), /// A float Float(f64), - /// An integer - Int(i64), - /// An unsigned integer - UInt(u64), + // /// An integer + // Int(i64), + // Int(i32), + // /// An unsigned integer + // UInt(u64), + /// Integer types + Int(u64, IntType), /// A boolean Bool(bool), /// A character @@ -180,6 +183,12 @@ pub enum EffectType { String(String), } +#[derive(Clone, Debug)] +pub enum IntType { + I8, I16, I32, I64, + U8, U16, U32, U64, +} + /// Effects that have been finalized and are ready for compilation #[derive(Clone, Debug)] pub struct FinalizedEffects { diff --git a/lib/core/src/math.rv b/lib/core/src/math.rv index b4158e8c..f8e9c453 100644 --- a/lib/core/src/math.rv +++ b/lib/core/src/math.rv @@ -27,6 +27,12 @@ trait LessThan { fn less_than(self, other: T) -> bool; } +// TODO: Uncomment after number-casting is implemented +//#[priority(-10)] +//trait Order { +// fn order(self, other: T) -> i8; +//} + #[priority(-10)] #[operation({}<={})] trait LessOrEqual { @@ -371,6 +377,19 @@ pub internal impl LessThan for T { } } +// TODO: Uncomment after number-casting is implemented +//pub impl Order for T { +// fn order(self, other: E) -> i8 { +// if (self.greater_than(other)) { +// return 1; +// } else if (self.equal(other)) { +// return 0; +// } else { +// return -1; +// } +// } +//} + pub impl, E: Number> LessOrEqual for T { fn less_or_equal(self, other: E) -> bool { return !(self.greater_than(other));