summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 19:06:26 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 19:06:26 +0200
commita4463b431904c0307135cc311674f0698b3d0946 (patch)
treeec7c599d2e71304ef3f7e52f4a0d1b8b46e01c8b /crates
parent384878703dd1fb97a3d3d60e56e12edb5234ad95 (diff)
downloadrebel-a4463b431904c0307135cc311674f0698b3d0946.tar
rebel-a4463b431904c0307135cc311674f0698b3d0946.zip
rebel-parse: box expressions in statements
The size of the statement type has a noticeable effect on performance.
Diffstat (limited to 'crates')
-rw-r--r--crates/rebel-lang/src/scope.rs6
-rw-r--r--crates/rebel-parse/src/ast.rs22
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs2
3 files changed, 19 insertions, 11 deletions
diff --git a/crates/rebel-lang/src/scope.rs b/crates/rebel-lang/src/scope.rs
index 7542a1e..d57a1f4 100644
--- a/crates/rebel-lang/src/scope.rs
+++ b/crates/rebel-lang/src/scope.rs
@@ -1,4 +1,4 @@
-use std::collections::HashMap;
+use std::{collections::HashMap, ops::Deref};
use rebel_parse::ast;
@@ -24,7 +24,7 @@ impl Context {
let ast::TypedExpr {
expr: dest_expr,
typ: _,
- } = dest;
+ } = dest.deref();
// TODO: Handle other assignable expressions
let dest_path = match dest_expr {
@@ -58,7 +58,7 @@ impl Context {
let ast::TypedExpr {
expr: dest_expr,
typ: _,
- } = dest;
+ } = dest.deref();
// TODO: Handle other assignable expressions
let dest_path = match dest_expr {
diff --git a/crates/rebel-parse/src/ast.rs b/crates/rebel-parse/src/ast.rs
index 490c2f1..8be015b 100644
--- a/crates/rebel-parse/src/ast.rs
+++ b/crates/rebel-parse/src/ast.rs
@@ -49,8 +49,13 @@ impl<'a> Body<'a> {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BodyStmt<'a> {
- Assign { dest: TypedExpr<'a>, expr: Expr<'a> },
- Expr { expr: Expr<'a> },
+ Assign {
+ dest: Box<TypedExpr<'a>>,
+ expr: Box<Expr<'a>>,
+ },
+ Expr {
+ expr: Box<Expr<'a>>,
+ },
Empty,
}
@@ -61,17 +66,20 @@ impl<'a> BodyStmt<'a> {
swapped: bool,
expr: Expr<'a>,
) -> Self {
- match op {
+ let expr = match op {
Some(op) => {
let dest_expr = dest.expr.clone();
- let expr = if swapped {
+ if swapped {
Expr::binary(expr, op, dest_expr)
} else {
Expr::binary(dest_expr, op, expr)
- };
- BodyStmt::Assign { dest, expr }
+ }
}
- None => BodyStmt::Assign { dest, expr },
+ None => expr,
+ };
+ BodyStmt::Assign {
+ dest: Box::new(dest),
+ expr: Box::new(expr),
}
}
diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs
index c23786b..fedc8a8 100644
--- a/crates/rebel-parse/src/grammar/recipe.rs
+++ b/crates/rebel-parse/src/grammar/recipe.rs
@@ -34,7 +34,7 @@ peg::parser! {
ast::BodyStmt::assign(dest, op, false, expr)
}
/ expr:expr() {
- ast::BodyStmt::Expr { expr }
+ ast::BodyStmt::Expr { expr: Box::new(expr) }
}
/ { ast::BodyStmt::Empty }