optimize(value): less clone
This commit is contained in:
@@ -112,14 +112,9 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
OpCode::LoadThunk { idx } => {
|
||||
stack.push(Value::Thunk(Thunk::new(self.get_thunk(idx)).into()))?
|
||||
}
|
||||
OpCode::CaptureEnv => stack
|
||||
.tos()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.unwrap_thunk()
|
||||
.capture(env.clone()),
|
||||
OpCode::CaptureEnv => stack.tos().as_ref().unwrap_thunk().capture(env.clone()),
|
||||
OpCode::ForceValue => {
|
||||
stack.tos_mut()?.force(self)?;
|
||||
stack.tos_mut().force(self)?;
|
||||
}
|
||||
OpCode::Jmp { step } => return Ok(step),
|
||||
OpCode::JmpIfFalse { step } => {
|
||||
@@ -154,26 +149,26 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
OpCode::BinOp { op } => {
|
||||
use BinOp::*;
|
||||
let mut rhs = stack.pop();
|
||||
let mut lhs = stack.pop();
|
||||
let lhs = stack.tos_mut();
|
||||
lhs.force(self)?;
|
||||
rhs.force(self)?;
|
||||
stack.push(match op {
|
||||
match op {
|
||||
Add => lhs.add(rhs),
|
||||
Sub => lhs.add(rhs.neg()),
|
||||
Mul => lhs.mul(rhs),
|
||||
Div => lhs.div(rhs)?,
|
||||
And => lhs.and(rhs),
|
||||
Or => lhs.or(rhs),
|
||||
Eq => lhs.eq(rhs, self),
|
||||
Eq => Value::eq(lhs, rhs),
|
||||
Lt => lhs.lt(rhs),
|
||||
Con => lhs.concat(rhs),
|
||||
Upd => lhs.update(rhs),
|
||||
})?;
|
||||
}
|
||||
}
|
||||
OpCode::ConcatString => {
|
||||
let mut rhs = stack.pop();
|
||||
rhs.force(self)?;
|
||||
stack.tos_mut()?.concat_string(rhs);
|
||||
stack.tos_mut().concat_string(rhs);
|
||||
}
|
||||
OpCode::Path => {
|
||||
todo!()
|
||||
@@ -183,33 +178,33 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
}
|
||||
OpCode::PushElem => {
|
||||
let elem = stack.pop();
|
||||
stack.tos_mut()?.push(elem);
|
||||
stack.tos_mut().push(elem);
|
||||
}
|
||||
OpCode::AttrSet { cap } => {
|
||||
stack.push(Value::AttrSet(AttrSet::with_capacity(cap).into()))?;
|
||||
}
|
||||
OpCode::FinalizeRec => {
|
||||
env.enter_let(stack.tos()?.clone().unwrap_attr_set().into_inner());
|
||||
stack.tos_mut()?.as_mut().unwrap_attr_set().capture(env);
|
||||
env.enter_let(stack.tos().clone().unwrap_attr_set().into_inner());
|
||||
stack.tos_mut().as_mut().unwrap_attr_set().capture(env);
|
||||
}
|
||||
OpCode::PushStaticAttr { name } => {
|
||||
let val = stack.pop();
|
||||
stack.tos_mut()?.push_attr(name, val);
|
||||
stack.tos_mut().push_attr(name, val);
|
||||
}
|
||||
OpCode::PushDynamicAttr => {
|
||||
let val = stack.pop();
|
||||
let mut sym = stack.pop();
|
||||
sym.force(self)?.coerce_to_string();
|
||||
let sym = self.new_sym(sym.unwrap_const().unwrap_string());
|
||||
stack.tos_mut()?.push_attr(sym, val);
|
||||
stack.tos_mut().push_attr(sym, val);
|
||||
}
|
||||
OpCode::Select { sym } => {
|
||||
stack.tos_mut()?.force(self)?.select(sym, self)?;
|
||||
stack.tos_mut().force(self)?.select(sym, self)?;
|
||||
}
|
||||
OpCode::SelectOrDefault { sym } => {
|
||||
let default = stack.pop();
|
||||
stack
|
||||
.tos_mut()?
|
||||
.tos_mut()
|
||||
.force(self)?
|
||||
.select_with_default(sym, default)?;
|
||||
}
|
||||
@@ -218,7 +213,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
val.force(self)?;
|
||||
val.coerce_to_string();
|
||||
let sym = self.new_sym(val.unwrap_const().unwrap_string());
|
||||
stack.tos_mut()?.force(self)?.select(sym, self)?;
|
||||
stack.tos_mut().force(self)?.select(sym, self)?;
|
||||
}
|
||||
OpCode::SelectDynamicOrDefault => {
|
||||
let default = stack.pop();
|
||||
@@ -227,18 +222,18 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
val.coerce_to_string();
|
||||
let sym = self.new_sym(val.unwrap_const().unwrap_string());
|
||||
stack
|
||||
.tos_mut()?
|
||||
.tos_mut()
|
||||
.force(self)?
|
||||
.select_with_default(sym, default)?;
|
||||
}
|
||||
OpCode::HasAttr { sym } => {
|
||||
stack.tos_mut()?.force(self)?.has_attr(sym);
|
||||
stack.tos_mut().force(self)?.has_attr(sym);
|
||||
}
|
||||
OpCode::HasDynamicAttr => {
|
||||
let mut val = stack.pop();
|
||||
val.coerce_to_string();
|
||||
let sym = self.new_sym(val.unwrap_const().unwrap_string());
|
||||
stack.tos_mut()?.force(self)?.has_attr(sym);
|
||||
stack.tos_mut().force(self)?.has_attr(sym);
|
||||
}
|
||||
OpCode::LookUp { sym } => {
|
||||
stack.push(
|
||||
@@ -249,17 +244,9 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
.clone(),
|
||||
)?;
|
||||
}
|
||||
OpCode::EnterLetEnv => match stack.pop() {
|
||||
Value::AttrSet(attrs) => env.enter_let(attrs.into_inner()),
|
||||
|
||||
_ => unreachable!(),
|
||||
},
|
||||
OpCode::EnterLetEnv => env.enter_let(stack.pop().unwrap_attr_set().into_inner()),
|
||||
OpCode::LeaveLetEnv => env.leave_let(),
|
||||
OpCode::EnterWithEnv => match stack.pop() {
|
||||
Value::AttrSet(attrs) => env.enter_with(attrs.into_inner()),
|
||||
|
||||
_ => unreachable!(),
|
||||
},
|
||||
OpCode::EnterWithEnv => env.enter_with(stack.pop().unwrap_attr_set().into_inner()),
|
||||
OpCode::LeaveWithEnv => env.leave_with(),
|
||||
OpCode::Assert => {
|
||||
if !stack.pop().unwrap_const().unwrap_bool() {
|
||||
|
||||
Reference in New Issue
Block a user