-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
2,801 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use derive_more::derive::Display; | ||
|
||
/// An operator used in the intermediate representaion | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)] | ||
pub enum Operator { | ||
// Arithmetic | ||
/// Add (+) operator | ||
Add, | ||
/// Sub (-) operator | ||
Sub, | ||
/// Mul (*) operator | ||
Mul, | ||
/// Div (/) operator | ||
Div, | ||
/// Rem (%) operator | ||
Rem, | ||
|
||
// Arithmetic Assign | ||
/// Add assign (+=) operator | ||
AddAssign, | ||
/// Sub assign (-=) operator | ||
SubAssign, | ||
/// Mul assing (*=) operator | ||
MulAssign, | ||
/// Div assign (/=) operator | ||
DivAssign, | ||
/// Rem assign (%=) operator | ||
RemAssign, | ||
|
||
// Comparison | ||
/// Equals (==) operator | ||
Eq, | ||
/// Not equal (!=) operator | ||
Ne, | ||
/// Less than (<) operator | ||
Lt, | ||
/// Less than equals (<=) operator | ||
Le, | ||
/// Greater than equal (>=) operator | ||
Ge, | ||
/// Greater than (>) operator | ||
Gt, | ||
|
||
// Boolean | ||
/// And (&&) operator | ||
And, | ||
/// Or (||) operator | ||
Or, | ||
/// Bitwise XOR (^) operator | ||
BitXor, | ||
/// Bitwise And (&) operator | ||
BitAnd, | ||
/// Bitwise Or (|) operator | ||
BitOr, | ||
|
||
// Boolean assign | ||
/// Bitwise xor assign (^=) operator | ||
BitXorAssign, | ||
/// Bitwise and assign (&=) operator | ||
BitAndAssign, | ||
/// Bitwise or assign (|=) operator | ||
BitOrAssign, | ||
|
||
/// Shift left (<<) operator | ||
Shl, | ||
/// Shift right (>>) operator | ||
Shr, | ||
/// Shift left assign (<<=) operator | ||
ShlAssign, | ||
/// Shift right assign (>>= operator) | ||
ShrAssign, | ||
|
||
// Unary | ||
/// Dereference operator (*) | ||
Deref, | ||
/// Not operator (!) | ||
Not, | ||
/// Negation unary operator (-) | ||
Neg, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use super::{Block, Expr, Expression, SquareType, Variable}; | ||
|
||
pub struct Break; | ||
|
||
impl Expr for Break { | ||
type Output = (); | ||
|
||
fn expression_untyped(&self) -> super::Expression { | ||
Expression::Break | ||
} | ||
} | ||
|
||
pub struct Continue; | ||
|
||
impl Expr for Continue { | ||
type Output = (); | ||
|
||
fn expression_untyped(&self) -> Expression { | ||
Expression::Continue | ||
} | ||
} | ||
|
||
pub struct ForLoop<TNum: SquareType> { | ||
pub from: Box<dyn Expr<Output = TNum>>, | ||
pub to: Box<dyn Expr<Output = TNum>>, | ||
pub step: Option<Box<dyn Expr<Output = TNum>>>, | ||
pub unroll: bool, | ||
pub variable: Variable<TNum>, | ||
|
||
pub block: Block<()>, | ||
} | ||
|
||
impl<TNum: SquareType> Expr for ForLoop<TNum> { | ||
type Output = (); | ||
|
||
fn expression_untyped(&self) -> Expression { | ||
Expression::ForLoop { | ||
from: Box::new(self.from.expression_untyped()), | ||
to: Box::new(self.to.expression_untyped()), | ||
step: self | ||
.step | ||
.as_ref() | ||
.map(|step| Box::new(step.expression_untyped())), | ||
unroll: self.unroll, | ||
variable: Box::new(self.variable.expression_untyped()), | ||
block: self.block.statements.iter().cloned().collect(), | ||
} | ||
} | ||
} |
Oops, something went wrong.