Refactored lvalues into just another expr

This commit is contained in:
2023-08-13 23:55:49 -05:00
parent 1de091f269
commit c6aea2f78f
4 changed files with 70 additions and 48 deletions
+19 -6
View File
@@ -78,21 +78,28 @@ pub struct Assignment {
pub rvalue: Rvalue,
}
// An lvalue is just a tag on an expr. Any expr parses just fine as an lvalue... not all exprs
// will compile as lvalues. But this saves us essentially having to define the expr grammar twice:
// in the compiler we can tell whether it makes sense for a given lvalue to compile into code that
// yields an address or if it can only yield a value.
#[derive(PartialEq, Clone, Debug)]
pub enum Lvalue {
Expr(BoxExpr),
Name(String, Vec<Suffix>)
}
pub struct Lvalue(pub BoxExpr);
impl From<&str> for Lvalue {
fn from(name: &str) -> Self {
Self::Name(String::from(name), vec![])
Self(name.into())
}
}
impl From<String> for Lvalue {
fn from(name: String) -> Self {
Self::Name(name, vec![])
Self(name.into())
}
}
impl From<Expr> for Lvalue {
fn from(value: Expr) -> Self {
Self(value.into())
}
}
@@ -195,6 +202,12 @@ impl From<&str> for BoxExpr {
}
}
impl From<String> for BoxExpr {
fn from(value: String) -> Self {
Expr::Name(value).into()
}
}
impl From<BoxExpr> for Expr {
fn from(expr: BoxExpr) -> Self {
*(expr.0)