Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions language/data/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -250,4 +258,6 @@ pub enum TokenTypes {
Char = 70,
/// A blank line
BlankLine = 71,
// Added Integer Types take 72 - 78

}
29 changes: 24 additions & 5 deletions language/parser/src/parser/code_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -61,7 +61,14 @@ pub fn parse_line(parser_utils: &mut ParserUtils, state: ParseState) -> Result<O
if effect.is_some() {
match token.token_type {
TokenTypes::Float
| TokenTypes::Integer
| TokenTypes::IntegerI8
| TokenTypes::IntegerI16
| TokenTypes::IntegerI32
| TokenTypes::IntegerI64
| TokenTypes::IntegerU8
| TokenTypes::IntegerU16
| TokenTypes::IntegerU32
| TokenTypes::IntegerU64
| TokenTypes::Char
| TokenTypes::True
| TokenTypes::False
Expand Down Expand Up @@ -284,13 +291,25 @@ fn parse_basic_line(
));
ControlFlow::Skipping
}
TokenTypes::Integer => {
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),
Expand Down
17 changes: 13 additions & 4 deletions language/syntax/src/program/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,13 @@ pub enum EffectType {
CreateArray(Vec<Effects>),
/// 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
Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions lib/core/src/math.rv
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ trait LessThan<T> {
fn less_than(self, other: T) -> bool;
}

// TODO: Uncomment after number-casting is implemented
//#[priority(-10)]
//trait Order<T> {
// fn order(self, other: T) -> i8;
//}

#[priority(-10)]
#[operation({}<={})]
trait LessOrEqual<T> {
Expand Down Expand Up @@ -371,6 +377,19 @@ pub internal impl<T: Number, E: Number> LessThan<E> for T {
}
}

// TODO: Uncomment after number-casting is implemented
//pub impl<T: Number, E: Number> Order<E> 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<T: GreaterThan<Number>, E: Number> LessOrEqual<E> for T {
fn less_or_equal(self, other: E) -> bool {
return !(self.greater_than(other));
Expand Down