diff --git a/examples/or_bitwise.reid b/examples/or_bitwise.reid new file mode 100644 index 0000000..fb802f5 --- /dev/null +++ b/examples/or_bitwise.reid @@ -0,0 +1,10 @@ +// Arithmetic, function calls and imports! + + +fn main() -> bool { + let bwand = (0xff & 0xf0) >> 4; + let bwor = (0x0f | 0x00) << 4; + let bwxor = (0xf0 | 0x0f); + + return (bwxor == 255) && ((value == 15) || false) && (bwor == 240); +} \ No newline at end of file diff --git a/examples/test.reid b/examples/test.reid new file mode 100644 index 0000000..ff427e2 --- /dev/null +++ b/examples/test.reid @@ -0,0 +1,7 @@ +// Arithmetic, function calls and imports! + + +fn main() -> bool { + + return 5.0 > -1; +} \ No newline at end of file diff --git a/reid/src/ast/lexer.rs b/reid/src/ast/lexer.rs index c520362..984825f 100644 --- a/reid/src/ast/lexer.rs +++ b/reid/src/ast/lexer.rs @@ -88,6 +88,10 @@ pub enum Token { LessThan, /// `&` Et, + /// `|` + Pipe, + /// `^` + Hat, /// `!` Exclamation, @@ -174,6 +178,8 @@ impl ToString for Token { Token::GreaterThan => String::from('>'), Token::LessThan => String::from('<'), Token::Et => String::from('&'), + Token::Pipe => String::from('|'), + Token::Hat => String::from('^'), Token::Exclamation => String::from('!'), Token::ParenOpen => String::from('('), Token::ParenClose => String::from(')'), @@ -411,6 +417,8 @@ pub fn tokenize>(to_tokenize: T) -> Result, Error '>' => Token::GreaterThan, '<' => Token::LessThan, '&' => Token::Et, + '|' => Token::Pipe, + '^' => Token::Hat, '!' => Token::Exclamation, '(' => Token::ParenOpen, ')' => Token::ParenClose, diff --git a/reid/src/ast/mod.rs b/reid/src/ast/mod.rs index 104c1aa..a0b48d3 100644 --- a/reid/src/ast/mod.rs +++ b/reid/src/ast/mod.rs @@ -116,7 +116,14 @@ pub enum BinaryOperator { Div, Mod, + BitshiftRight, + BitshiftLeft, + And, + Or, + Xor, + BWAnd, + BWOr, LT, LE, GT, @@ -126,7 +133,7 @@ pub enum BinaryOperator { } impl BinaryOperator { - pub fn get_precedence(&self) -> i8 { + pub fn get_precedence(&self) -> u8 { use BinaryOperator::*; match &self { Minus => 5, @@ -134,13 +141,20 @@ impl BinaryOperator { Mult => 15, Div => 20, Mod => 20, - And => 100, - LT => 100, - LE => 100, - GT => 100, - GE => 100, - EQ => 100, - NE => 100, + BWAnd => 90, + BWOr => 90, + BWXor => 90, + BitshiftLeft => 100, + BitshiftRight => 100, + And => 150, + Or => 150, + Xor => 150, + LT => 150, + LE => 150, + GT => 150, + GE => 150, + EQ => 150, + NE => 150, } } } diff --git a/reid/src/ast/parse.rs b/reid/src/ast/parse.rs index 3484f5c..5f96e74 100644 --- a/reid/src/ast/parse.rs +++ b/reid/src/ast/parse.rs @@ -488,6 +488,10 @@ impl Parse for BinaryOperator { stream.next(); BinaryOperator::And } + (Some(Token::Pipe), Some(Token::Pipe)) => { + stream.next(); + BinaryOperator::Or + } (Some(Token::LessThan), Some(Token::Equals)) => { stream.next(); BinaryOperator::LE @@ -504,6 +508,18 @@ impl Parse for BinaryOperator { stream.next(); BinaryOperator::NE } + (Some(Token::GreaterThan), Some(Token::GreaterThan)) => { + stream.next(); + BinaryOperator::BitshiftRight + } + (Some(Token::LessThan), Some(Token::LessThan)) => { + stream.next(); + BinaryOperator::BitshiftLeft + } + + (Some(Token::Hat), _) => BinaryOperator::Xor, + (Some(Token::Et), _) => BinaryOperator::BWAnd, + (Some(Token::Pipe), _) => BinaryOperator::BWOr, (Some(Token::LessThan), _) => BinaryOperator::LT, (Some(Token::GreaterThan), _) => BinaryOperator::GT, diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs index 1b90f6a..8d57463 100644 --- a/reid/src/ast/process.rs +++ b/reid/src/ast/process.rs @@ -455,6 +455,12 @@ impl ast::BinaryOperator { ast::BinaryOperator::GE => mir::BinaryOperator::Cmp(mir::CmpOperator::GE), ast::BinaryOperator::EQ => mir::BinaryOperator::Cmp(mir::CmpOperator::EQ), ast::BinaryOperator::NE => mir::BinaryOperator::Cmp(mir::CmpOperator::NE), + ast::BinaryOperator::BitshiftRight => todo!(), + ast::BinaryOperator::BitshiftLeft => todo!(), + ast::BinaryOperator::Or => todo!(), + ast::BinaryOperator::Xor => todo!(), + ast::BinaryOperator::BWAnd => todo!(), + ast::BinaryOperator::BWOr => todo!(), } } } diff --git a/reid/src/mir/typecheck/mod.rs b/reid/src/mir/typecheck/mod.rs index b01cb10..bda12cc 100644 --- a/reid/src/mir/typecheck/mod.rs +++ b/reid/src/mir/typecheck/mod.rs @@ -135,7 +135,14 @@ impl TypeKind { | TypeKind::U16 | TypeKind::U32 | TypeKind::U64 - | TypeKind::U128 => Ok(other.clone()), + | TypeKind::U128 + | TypeKind::F16 + | TypeKind::F32B + | TypeKind::F32 + | TypeKind::F64 + | TypeKind::F80 + | TypeKind::F128 + | TypeKind::F128PPC => Ok(other.clone()), _ => Err(ErrorKind::TypesIncompatible(self.clone(), other.clone())), }, (TypeKind::Vague(Vague::Decimal), other) | (other, TypeKind::Vague(Vague::Decimal)) => match other {