optimize(value): less clone
This commit is contained in:
@@ -12,24 +12,29 @@ pub fn env<'jit, 'vm>(vm: &'vm VM<'jit>) -> VmEnv<'jit, 'vm> {
|
|||||||
|
|
||||||
let primops = [
|
let primops = [
|
||||||
PrimOp::new("add", 2, |_, args| {
|
PrimOp::new("add", 2, |_, args| {
|
||||||
let [first, second]: [Value; 2] = args.try_into().unwrap();
|
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
|
||||||
first.add(second).ok()
|
first.add(second);
|
||||||
|
first.ok()
|
||||||
}),
|
}),
|
||||||
PrimOp::new("sub", 2, |_, args| {
|
PrimOp::new("sub", 2, |_, args| {
|
||||||
let [first, second]: [Value; 2] = args.try_into().unwrap();
|
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
|
||||||
first.add(second.neg()).ok()
|
first.add(second.neg());
|
||||||
|
first.ok()
|
||||||
}),
|
}),
|
||||||
PrimOp::new("mul", 2, |_, args| {
|
PrimOp::new("mul", 2, |_, args| {
|
||||||
let [first, second]: [Value; 2] = args.try_into().unwrap();
|
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
|
||||||
first.mul(second).ok()
|
first.mul(second);
|
||||||
|
first.ok()
|
||||||
}),
|
}),
|
||||||
PrimOp::new("div", 2, |_, args| {
|
PrimOp::new("div", 2, |_, args| {
|
||||||
let [first, second]: [Value; 2] = args.try_into().unwrap();
|
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
|
||||||
first.div(second)
|
first.div(second)?;
|
||||||
|
first.ok()
|
||||||
}),
|
}),
|
||||||
PrimOp::new("lessThan", 2, |_, args| {
|
PrimOp::new("lessThan", 2, |_, args| {
|
||||||
let [first, second]: [Value; 2] = args.try_into().unwrap();
|
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
|
||||||
first.lt(second).ok()
|
first.lt(second);
|
||||||
|
first.ok()
|
||||||
}),
|
}),
|
||||||
PrimOp::new("seq", 2, |vm, args| {
|
PrimOp::new("seq", 2, |vm, args| {
|
||||||
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
|
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ impl<'vm, 'ctx: 'vm> JITContext<'ctx> {
|
|||||||
.new_thunk(Rc::into_raw(Rc::new(Thunk::new(vm.get_thunk(idx))))),
|
.new_thunk(Rc::into_raw(Rc::new(Thunk::new(vm.get_thunk(idx))))),
|
||||||
)?,
|
)?,
|
||||||
OpCode::CaptureEnv => {
|
OpCode::CaptureEnv => {
|
||||||
let thunk = *stack.tos()?;
|
let thunk = *stack.tos();
|
||||||
self.builder.build_direct_call(
|
self.builder.build_direct_call(
|
||||||
self.helpers.capture_env,
|
self.helpers.capture_env,
|
||||||
&[thunk.into(), env.into()],
|
&[thunk.into(), env.into()],
|
||||||
|
|||||||
16
src/stack.rs
16
src/stack.rs
@@ -51,20 +51,12 @@ impl<T, const CAP: usize> Stack<T, CAP> {
|
|||||||
unsafe { replace(item, MaybeUninit::uninit()).assume_init() }
|
unsafe { replace(item, MaybeUninit::uninit()).assume_init() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tos(&self) -> Result<&T> {
|
pub fn tos(&self) -> &T {
|
||||||
if self.top == 0 {
|
into!(&self.items[self.top - 1])
|
||||||
panic!("stack empty")
|
|
||||||
} else {
|
|
||||||
Ok(into!(&self.items[self.top - 1]))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tos_mut(&mut self) -> Result<&mut T> {
|
pub fn tos_mut(&mut self) -> &mut T {
|
||||||
if self.top == 0 {
|
into!(&mut self.items[self.top - 1])
|
||||||
panic!("stack empty")
|
|
||||||
} else {
|
|
||||||
Ok(into!(&mut self.items[self.top - 1]))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,13 +87,13 @@ impl<'jit: 'vm, 'vm> AttrSet<'jit, 'vm> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eq_impl(&self, other: &AttrSet<'jit, 'vm>, vm: &'vm VM<'jit>) -> bool {
|
pub fn eq_impl(&self, other: &AttrSet<'jit, 'vm>) -> bool {
|
||||||
self.data.iter().len() == other.data.iter().len()
|
self.data.iter().len() == other.data.iter().len()
|
||||||
&& std::iter::zip(
|
&& std::iter::zip(
|
||||||
self.data.iter().sorted_by_key(|(k, _)| **k),
|
self.data.iter().sorted_by_key(|(k, _)| **k),
|
||||||
self.data.iter().sorted_by_key(|(k, _)| **k),
|
self.data.iter().sorted_by_key(|(k, _)| **k),
|
||||||
)
|
)
|
||||||
.all(|((_, v1), (_, v2))| v1.eq_impl(v2, vm))
|
.all(|((_, v1), (_, v2))| v1.eq_impl(v2))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_public(&self, vm: &'vm VM, seen: &mut HashSet<Value<'jit, 'vm>>) -> p::Value {
|
pub fn to_public(&self, vm: &'vm VM, seen: &mut HashSet<Value<'jit, 'vm>>) -> p::Value {
|
||||||
|
|||||||
@@ -56,14 +56,12 @@ impl Hash for Value<'_, '_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'jit: 'vm, 'vm> Value<'jit, 'vm> {
|
impl<'jit: 'vm, 'vm> Value<'jit, 'vm> {
|
||||||
fn eq_impl(&self, other: &Self, vm: &'vm VM<'jit>) -> bool {
|
fn eq_impl(&self, other: &Self) -> bool {
|
||||||
use Value::*;
|
use Value::*;
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(Const(a), Const(b)) => a.eq(b),
|
(Const(a), Const(b)) => a.eq(b),
|
||||||
(AttrSet(a), AttrSet(b)) => a.eq_impl(b, vm),
|
(AttrSet(a), AttrSet(b)) => a.eq_impl(b),
|
||||||
(List(a), List(b)) => a.eq(b),
|
(List(a), List(b)) => a.eq(b),
|
||||||
(Builtins(_), AttrSet(attrs)) => attrs.has_attr(vm.new_sym("builtins")),
|
|
||||||
(AttrSet(attrs), Builtins(_)) => attrs.has_attr(vm.new_sym("builtins")),
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,41 +211,48 @@ impl<'jit, 'vm> Value<'jit, 'vm> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn and(self, other: Self) -> Self {
|
pub fn and(&mut self, other: Self) {
|
||||||
use Const::*;
|
use Const::*;
|
||||||
match (self, other) {
|
*self = match (&*self, other) {
|
||||||
(VmConst(Bool(a)), VmConst(Bool(b))) => VmConst(Bool(a && b)),
|
(VmConst(Bool(a)), VmConst(Bool(b))) => VmConst(Bool(*a && b)),
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
(Value::Catchable(_), _) => return,
|
||||||
|
(_, x @ Value::Catchable(_)) => x,
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn or(self, other: Self) -> Self {
|
pub fn or(&mut self, other: Self) {
|
||||||
use Const::*;
|
use Const::*;
|
||||||
match (self, other) {
|
*self = match (&*self, other) {
|
||||||
(VmConst(Bool(a)), VmConst(Bool(b))) => VmConst(Bool(a || b)),
|
(VmConst(Bool(a)), VmConst(Bool(b))) => VmConst(Bool(*a || b)),
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
(Value::Catchable(_), _) => return,
|
||||||
|
(_, x @ Value::Catchable(_)) => x,
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eq(self, other: Self, vm: &'vm VM<'jit>) -> Self {
|
pub fn eq(&mut self, other: Self) {
|
||||||
use Const::Bool;
|
use Const::Bool;
|
||||||
match (self, other) {
|
*self = match (&*self, other) {
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
(Value::Catchable(_), _) => return,
|
||||||
(s, other) => VmConst(Bool(s.eq_impl(&other, vm))),
|
(_, x @ Value::Catchable(_)) => x,
|
||||||
}
|
(s, other) => VmConst(Bool(s.eq_impl(&other))),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lt(self, other: Self) -> Self {
|
pub fn lt(&mut self, other: Self) {
|
||||||
use Const::*;
|
use Const::*;
|
||||||
VmConst(Bool(match (self, other) {
|
*self = VmConst(Bool(match (&*self, other) {
|
||||||
(VmConst(Int(a)), VmConst(Int(b))) => a < b,
|
(VmConst(Int(a)), VmConst(Int(b))) => *a < b,
|
||||||
(VmConst(Int(a)), VmConst(Float(b))) => (a as f64) < b,
|
(VmConst(Int(a)), VmConst(Float(b))) => (*a as f64) < b,
|
||||||
(VmConst(Float(a)), VmConst(Int(b))) => a < b as f64,
|
(VmConst(Float(a)), VmConst(Int(b))) => *a < b as f64,
|
||||||
(VmConst(Float(a)), VmConst(Float(b))) => a < b,
|
(VmConst(Float(a)), VmConst(Float(b))) => *a < b,
|
||||||
(VmConst(String(a)), VmConst(String(b))) => a < b,
|
(VmConst(String(a)), VmConst(String(b))) => a < &b,
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => return x,
|
(Value::Catchable(_), _) => return,
|
||||||
|
(_, x @ Value::Catchable(_)) => {
|
||||||
|
*self = x;
|
||||||
|
return;
|
||||||
|
},
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -262,11 +267,11 @@ impl<'jit, 'vm> Value<'jit, 'vm> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(self, other: Self) -> Self {
|
pub fn add(&mut self, other: Self) {
|
||||||
use Const::*;
|
use Const::*;
|
||||||
match (self, other) {
|
*self = match (&*self, other) {
|
||||||
(VmConst(Int(a)), VmConst(Int(b))) => VmConst(Int(a + b)),
|
(VmConst(Int(a)), VmConst(Int(b))) => VmConst(Int(a + b)),
|
||||||
(VmConst(Int(a)), VmConst(Float(b))) => VmConst(Float(a as f64 + b)),
|
(VmConst(Int(a)), VmConst(Float(b))) => VmConst(Float(*a as f64 + b)),
|
||||||
(VmConst(Float(a)), VmConst(Int(b))) => VmConst(Float(a + b as f64)),
|
(VmConst(Float(a)), VmConst(Int(b))) => VmConst(Float(a + b as f64)),
|
||||||
(VmConst(Float(a)), VmConst(Float(b))) => VmConst(Float(a + b)),
|
(VmConst(Float(a)), VmConst(Float(b))) => VmConst(Float(a + b)),
|
||||||
(VmConst(String(a)), VmConst(String(b))) => {
|
(VmConst(String(a)), VmConst(String(b))) => {
|
||||||
@@ -274,37 +279,41 @@ impl<'jit, 'vm> Value<'jit, 'vm> {
|
|||||||
string.push_str(b.as_str());
|
string.push_str(b.as_str());
|
||||||
VmConst(String(string))
|
VmConst(String(string))
|
||||||
}
|
}
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
(Value::Catchable(_), _) => return,
|
||||||
|
(_, x @ Value::Catchable(_)) => x,
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mul(self, other: Self) -> Self {
|
pub fn mul(&mut self, other: Self) {
|
||||||
use Const::*;
|
use Const::*;
|
||||||
match (self, other) {
|
*self = match (&*self, other) {
|
||||||
(VmConst(Int(a)), VmConst(Int(b))) => VmConst(Int(a * b)),
|
(VmConst(Int(a)), VmConst(Int(b))) => VmConst(Int(a * b)),
|
||||||
(VmConst(Int(a)), VmConst(Float(b))) => VmConst(Float(a as f64 * b)),
|
(VmConst(Int(a)), VmConst(Float(b))) => VmConst(Float(*a as f64 * b)),
|
||||||
(VmConst(Float(a)), VmConst(Int(b))) => VmConst(Float(a * b as f64)),
|
(VmConst(Float(a)), VmConst(Int(b))) => VmConst(Float(a * b as f64)),
|
||||||
(VmConst(Float(a)), VmConst(Float(b))) => VmConst(Float(a * b)),
|
(VmConst(Float(a)), VmConst(Float(b))) => VmConst(Float(a * b)),
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
(Value::Catchable(_), _) => return,
|
||||||
|
(_, x @ Value::Catchable(_)) => x,
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn div(self, other: Self) -> Result<Self> {
|
pub fn div(&mut self, other: Self) -> Result<()> {
|
||||||
use Const::*;
|
use Const::*;
|
||||||
Ok(match (self, other) {
|
*self = match (&*self, other) {
|
||||||
(_, VmConst(Int(0))) => return Err(Error::EvalError("division by zero".to_string())),
|
(_, VmConst(Int(0))) => return Err(Error::EvalError("division by zero".to_string())),
|
||||||
(_, VmConst(Float(0.))) => {
|
(_, VmConst(Float(0.))) => {
|
||||||
return Err(Error::EvalError("division by zero".to_string()));
|
return Err(Error::EvalError("division by zero".to_string()));
|
||||||
}
|
}
|
||||||
(VmConst(Int(a)), VmConst(Int(b))) => VmConst(Int(a / b)),
|
(VmConst(Int(a)), VmConst(Int(b))) => VmConst(Int(a / b)),
|
||||||
(VmConst(Int(a)), VmConst(Float(b))) => VmConst(Float(a as f64 / b)),
|
(VmConst(Int(a)), VmConst(Float(b))) => VmConst(Float(*a as f64 / b)),
|
||||||
(VmConst(Float(a)), VmConst(Int(b))) => VmConst(Float(a / b as f64)),
|
(VmConst(Float(a)), VmConst(Int(b))) => VmConst(Float(a / b as f64)),
|
||||||
(VmConst(Float(a)), VmConst(Float(b))) => VmConst(Float(a / b)),
|
(VmConst(Float(a)), VmConst(Float(b))) => VmConst(Float(a / b)),
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
(Value::Catchable(_), _) => return Ok(()),
|
||||||
|
(_, x @ Value::Catchable(_)) => x,
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
})
|
};
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn concat_string(&mut self, mut other: Self) -> &mut Self {
|
pub fn concat_string(&mut self, mut other: Self) -> &mut Self {
|
||||||
@@ -329,13 +338,16 @@ impl<'jit, 'vm> Value<'jit, 'vm> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn concat(self, other: Self) -> Self {
|
pub fn concat(&mut self, other: Self) {
|
||||||
match (self, other) {
|
if let x @ Value::Catchable(_) = other {
|
||||||
(Value::List(mut a), Value::List(b)) => {
|
*self = x;
|
||||||
Rc::make_mut(&mut a).concat(b.as_ref());
|
return;
|
||||||
Value::List(a)
|
|
||||||
}
|
}
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
match (self, other) {
|
||||||
|
(Value::List(a), Value::List(b)) => {
|
||||||
|
Rc::make_mut(a).concat(b.as_ref());
|
||||||
|
}
|
||||||
|
(Value::Catchable(_), _) => (),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,13 +364,16 @@ impl<'jit, 'vm> Value<'jit, 'vm> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(self, other: Self) -> Self {
|
pub fn update(&mut self, other: Self) {
|
||||||
match (self, other) {
|
if let x @ Value::Catchable(_) = other {
|
||||||
(Value::AttrSet(mut a), Value::AttrSet(b)) => {
|
*self = x;
|
||||||
Rc::make_mut(&mut a).update(b.as_ref());
|
return;
|
||||||
Value::AttrSet(a)
|
|
||||||
}
|
}
|
||||||
(x @ Value::Catchable(_), _) | (_, x @ Value::Catchable(_)) => x,
|
match (self, other) {
|
||||||
|
(Value::AttrSet(a), Value::AttrSet(b)) => {
|
||||||
|
Rc::make_mut(a).update(b.as_ref());
|
||||||
|
}
|
||||||
|
(Value::Catchable(_), _) => (),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,14 +112,9 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
|||||||
OpCode::LoadThunk { idx } => {
|
OpCode::LoadThunk { idx } => {
|
||||||
stack.push(Value::Thunk(Thunk::new(self.get_thunk(idx)).into()))?
|
stack.push(Value::Thunk(Thunk::new(self.get_thunk(idx)).into()))?
|
||||||
}
|
}
|
||||||
OpCode::CaptureEnv => stack
|
OpCode::CaptureEnv => stack.tos().as_ref().unwrap_thunk().capture(env.clone()),
|
||||||
.tos()
|
|
||||||
.unwrap()
|
|
||||||
.as_ref()
|
|
||||||
.unwrap_thunk()
|
|
||||||
.capture(env.clone()),
|
|
||||||
OpCode::ForceValue => {
|
OpCode::ForceValue => {
|
||||||
stack.tos_mut()?.force(self)?;
|
stack.tos_mut().force(self)?;
|
||||||
}
|
}
|
||||||
OpCode::Jmp { step } => return Ok(step),
|
OpCode::Jmp { step } => return Ok(step),
|
||||||
OpCode::JmpIfFalse { step } => {
|
OpCode::JmpIfFalse { step } => {
|
||||||
@@ -154,26 +149,26 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
|||||||
OpCode::BinOp { op } => {
|
OpCode::BinOp { op } => {
|
||||||
use BinOp::*;
|
use BinOp::*;
|
||||||
let mut rhs = stack.pop();
|
let mut rhs = stack.pop();
|
||||||
let mut lhs = stack.pop();
|
let lhs = stack.tos_mut();
|
||||||
lhs.force(self)?;
|
lhs.force(self)?;
|
||||||
rhs.force(self)?;
|
rhs.force(self)?;
|
||||||
stack.push(match op {
|
match op {
|
||||||
Add => lhs.add(rhs),
|
Add => lhs.add(rhs),
|
||||||
Sub => lhs.add(rhs.neg()),
|
Sub => lhs.add(rhs.neg()),
|
||||||
Mul => lhs.mul(rhs),
|
Mul => lhs.mul(rhs),
|
||||||
Div => lhs.div(rhs)?,
|
Div => lhs.div(rhs)?,
|
||||||
And => lhs.and(rhs),
|
And => lhs.and(rhs),
|
||||||
Or => lhs.or(rhs),
|
Or => lhs.or(rhs),
|
||||||
Eq => lhs.eq(rhs, self),
|
Eq => Value::eq(lhs, rhs),
|
||||||
Lt => lhs.lt(rhs),
|
Lt => lhs.lt(rhs),
|
||||||
Con => lhs.concat(rhs),
|
Con => lhs.concat(rhs),
|
||||||
Upd => lhs.update(rhs),
|
Upd => lhs.update(rhs),
|
||||||
})?;
|
}
|
||||||
}
|
}
|
||||||
OpCode::ConcatString => {
|
OpCode::ConcatString => {
|
||||||
let mut rhs = stack.pop();
|
let mut rhs = stack.pop();
|
||||||
rhs.force(self)?;
|
rhs.force(self)?;
|
||||||
stack.tos_mut()?.concat_string(rhs);
|
stack.tos_mut().concat_string(rhs);
|
||||||
}
|
}
|
||||||
OpCode::Path => {
|
OpCode::Path => {
|
||||||
todo!()
|
todo!()
|
||||||
@@ -183,33 +178,33 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
|||||||
}
|
}
|
||||||
OpCode::PushElem => {
|
OpCode::PushElem => {
|
||||||
let elem = stack.pop();
|
let elem = stack.pop();
|
||||||
stack.tos_mut()?.push(elem);
|
stack.tos_mut().push(elem);
|
||||||
}
|
}
|
||||||
OpCode::AttrSet { cap } => {
|
OpCode::AttrSet { cap } => {
|
||||||
stack.push(Value::AttrSet(AttrSet::with_capacity(cap).into()))?;
|
stack.push(Value::AttrSet(AttrSet::with_capacity(cap).into()))?;
|
||||||
}
|
}
|
||||||
OpCode::FinalizeRec => {
|
OpCode::FinalizeRec => {
|
||||||
env.enter_let(stack.tos()?.clone().unwrap_attr_set().into_inner());
|
env.enter_let(stack.tos().clone().unwrap_attr_set().into_inner());
|
||||||
stack.tos_mut()?.as_mut().unwrap_attr_set().capture(env);
|
stack.tos_mut().as_mut().unwrap_attr_set().capture(env);
|
||||||
}
|
}
|
||||||
OpCode::PushStaticAttr { name } => {
|
OpCode::PushStaticAttr { name } => {
|
||||||
let val = stack.pop();
|
let val = stack.pop();
|
||||||
stack.tos_mut()?.push_attr(name, val);
|
stack.tos_mut().push_attr(name, val);
|
||||||
}
|
}
|
||||||
OpCode::PushDynamicAttr => {
|
OpCode::PushDynamicAttr => {
|
||||||
let val = stack.pop();
|
let val = stack.pop();
|
||||||
let mut sym = stack.pop();
|
let mut sym = stack.pop();
|
||||||
sym.force(self)?.coerce_to_string();
|
sym.force(self)?.coerce_to_string();
|
||||||
let sym = self.new_sym(sym.unwrap_const().unwrap_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 } => {
|
OpCode::Select { sym } => {
|
||||||
stack.tos_mut()?.force(self)?.select(sym, self)?;
|
stack.tos_mut().force(self)?.select(sym, self)?;
|
||||||
}
|
}
|
||||||
OpCode::SelectOrDefault { sym } => {
|
OpCode::SelectOrDefault { sym } => {
|
||||||
let default = stack.pop();
|
let default = stack.pop();
|
||||||
stack
|
stack
|
||||||
.tos_mut()?
|
.tos_mut()
|
||||||
.force(self)?
|
.force(self)?
|
||||||
.select_with_default(sym, default)?;
|
.select_with_default(sym, default)?;
|
||||||
}
|
}
|
||||||
@@ -218,7 +213,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
|||||||
val.force(self)?;
|
val.force(self)?;
|
||||||
val.coerce_to_string();
|
val.coerce_to_string();
|
||||||
let sym = self.new_sym(val.unwrap_const().unwrap_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 => {
|
OpCode::SelectDynamicOrDefault => {
|
||||||
let default = stack.pop();
|
let default = stack.pop();
|
||||||
@@ -227,18 +222,18 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
|||||||
val.coerce_to_string();
|
val.coerce_to_string();
|
||||||
let sym = self.new_sym(val.unwrap_const().unwrap_string());
|
let sym = self.new_sym(val.unwrap_const().unwrap_string());
|
||||||
stack
|
stack
|
||||||
.tos_mut()?
|
.tos_mut()
|
||||||
.force(self)?
|
.force(self)?
|
||||||
.select_with_default(sym, default)?;
|
.select_with_default(sym, default)?;
|
||||||
}
|
}
|
||||||
OpCode::HasAttr { sym } => {
|
OpCode::HasAttr { sym } => {
|
||||||
stack.tos_mut()?.force(self)?.has_attr(sym);
|
stack.tos_mut().force(self)?.has_attr(sym);
|
||||||
}
|
}
|
||||||
OpCode::HasDynamicAttr => {
|
OpCode::HasDynamicAttr => {
|
||||||
let mut val = stack.pop();
|
let mut val = stack.pop();
|
||||||
val.coerce_to_string();
|
val.coerce_to_string();
|
||||||
let sym = self.new_sym(val.unwrap_const().unwrap_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 } => {
|
OpCode::LookUp { sym } => {
|
||||||
stack.push(
|
stack.push(
|
||||||
@@ -249,17 +244,9 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
|||||||
.clone(),
|
.clone(),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
OpCode::EnterLetEnv => match stack.pop() {
|
OpCode::EnterLetEnv => env.enter_let(stack.pop().unwrap_attr_set().into_inner()),
|
||||||
Value::AttrSet(attrs) => env.enter_let(attrs.into_inner()),
|
|
||||||
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
OpCode::LeaveLetEnv => env.leave_let(),
|
OpCode::LeaveLetEnv => env.leave_let(),
|
||||||
OpCode::EnterWithEnv => match stack.pop() {
|
OpCode::EnterWithEnv => env.enter_with(stack.pop().unwrap_attr_set().into_inner()),
|
||||||
Value::AttrSet(attrs) => env.enter_with(attrs.into_inner()),
|
|
||||||
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
OpCode::LeaveWithEnv => env.leave_with(),
|
OpCode::LeaveWithEnv => env.leave_with(),
|
||||||
OpCode::Assert => {
|
OpCode::Assert => {
|
||||||
if !stack.pop().unwrap_const().unwrap_bool() {
|
if !stack.pop().unwrap_const().unwrap_bool() {
|
||||||
|
|||||||
Reference in New Issue
Block a user