mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Box the largest Statement variants to save memory
Statement: 664 to 256
This commit is contained in:
parent
c939a1f65f
commit
e33ebabd3f
3 changed files with 15 additions and 15 deletions
|
|
@ -1425,7 +1425,7 @@ impl<'o, 's> AnalyzeProc<'o, 's> {
|
|||
let mut state = self.visit_block(block, &mut scoped_locals);
|
||||
if let Some(startterm) = start.as_term() {
|
||||
if let Some(endterm) = end.as_term() {
|
||||
if let Some(validity) = startterm.valid_for_range(endterm, step) {
|
||||
if let Some(validity) = startterm.valid_for_range(endterm, step.as_deref()) {
|
||||
if !validity {
|
||||
error(location,"for range loop body is never reached due to invalid range")
|
||||
.register(self.context);
|
||||
|
|
|
|||
|
|
@ -594,7 +594,7 @@ impl Term {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn valid_for_range(&self, other: &Term, step: &Option<Expression>) -> Option<bool> {
|
||||
pub fn valid_for_range(&self, other: &Term, step: Option<&Expression>) -> Option<bool> {
|
||||
if let Term::Int(i) = *self {
|
||||
if let Term::Int(o) = *other {
|
||||
// edge case
|
||||
|
|
@ -1039,15 +1039,15 @@ pub enum Statement {
|
|||
/// If zero, uses the declared type of the variable.
|
||||
input_type: Option<InputType>,
|
||||
/// Defaults to 'world'.
|
||||
in_list: Option<Expression>,
|
||||
in_list: Option<Box<Expression>>,
|
||||
block: Block,
|
||||
},
|
||||
ForRange {
|
||||
var_type: Option<VarType>,
|
||||
name: Ident,
|
||||
start: Expression,
|
||||
end: Expression,
|
||||
step: Option<Expression>,
|
||||
start: Box<Expression>,
|
||||
end: Box<Expression>,
|
||||
step: Option<Box<Expression>>,
|
||||
block: Block,
|
||||
},
|
||||
Var(VarStatement),
|
||||
|
|
|
|||
|
|
@ -1270,7 +1270,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
// for(var/a = 1 to
|
||||
require!(self.exact_ident("to"));
|
||||
let rhs = require!(self.expression());
|
||||
return spanned(require!(self.for_range(Some(var_type), name, value, rhs)));
|
||||
return spanned(require!(self.for_range(Some(var_type), name, Box::new(value), Box::new(rhs))));
|
||||
}
|
||||
Statement::Expr(Expression::AssignOp {
|
||||
op: AssignOp::Assign,
|
||||
|
|
@ -1284,7 +1284,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
};
|
||||
require!(self.exact_ident("to"));
|
||||
let to_rhs = require!(self.expression());
|
||||
return spanned(require!(self.for_range(None, name, *rhs, to_rhs)));
|
||||
return spanned(require!(self.for_range(None, name, rhs, Box::new(to_rhs))));
|
||||
}
|
||||
Statement::Var(VarStatement {
|
||||
var_type,
|
||||
|
|
@ -1307,7 +1307,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
// let (b, c) = *a;
|
||||
match {*rhs} {
|
||||
Expression::BinaryOp { op: BinaryOp::To, lhs, rhs } => {
|
||||
return spanned(require!(self.for_range(None, name, *lhs, *rhs)));
|
||||
return spanned(require!(self.for_range(None, name, lhs, rhs)));
|
||||
},
|
||||
rhs => {
|
||||
// I love code duplication, don't you?
|
||||
|
|
@ -1316,7 +1316,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
var_type: None,
|
||||
name,
|
||||
input_type: None,
|
||||
in_list: Some(rhs),
|
||||
in_list: Some(Box::new(rhs)),
|
||||
block: require!(self.block(&LoopContext::ForList)),
|
||||
});
|
||||
}
|
||||
|
|
@ -1340,7 +1340,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
let value = require!(self.expression());
|
||||
if let Some(()) = self.exact_ident("to")? {
|
||||
let rhs = require!(self.expression());
|
||||
return spanned(require!(self.for_range(var_type, name, value, rhs)));
|
||||
return spanned(require!(self.for_range(var_type, name, Box::new(value), Box::new(rhs))));
|
||||
}
|
||||
Some(value)
|
||||
} else {
|
||||
|
|
@ -1352,7 +1352,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
var_type,
|
||||
name,
|
||||
input_type,
|
||||
in_list,
|
||||
in_list: in_list.map(Box::new),
|
||||
block: require!(self.block(&LoopContext::ForList)),
|
||||
})
|
||||
} else {
|
||||
|
|
@ -1591,8 +1591,8 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
&mut self,
|
||||
var_type: Option<VarType>,
|
||||
name: Ident,
|
||||
start: Expression,
|
||||
end: Expression,
|
||||
start: Box<Expression>,
|
||||
end: Box<Expression>,
|
||||
) -> Status<Statement> {
|
||||
// step 2
|
||||
let step = if let Some(()) = self.exact_ident("step")? {
|
||||
|
|
@ -1608,7 +1608,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
|
|||
name,
|
||||
start,
|
||||
end,
|
||||
step,
|
||||
step: step.map(Box::new),
|
||||
block: require!(self.block(&LoopContext::ForRange)),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue