optimize: dedup consts
This commit is contained in:
@@ -29,10 +29,11 @@ pub fn run(prog: Program, jit: JITContext<'_>) -> Result<p::Value> {
|
||||
prog.funcs,
|
||||
RefCell::new(prog.symbols),
|
||||
RefCell::new(prog.symmap),
|
||||
prog.consts,
|
||||
jit
|
||||
);
|
||||
let env = env(&vm);
|
||||
let temp = vm.eval(prog.top_level, env)?;
|
||||
let temp = vm.eval(prog.top_level.into_iter(), env)?;
|
||||
let temp = temp.to_public(&vm);
|
||||
Ok(temp)
|
||||
}
|
||||
@@ -43,6 +44,7 @@ pub struct VM<'jit> {
|
||||
funcs: Box<[F]>,
|
||||
symbols: RefCell<Vec<EcoString>>,
|
||||
symmap: RefCell<HashMap<EcoString, usize>>,
|
||||
consts: Box<[Const]>,
|
||||
jit: JITContext<'jit>,
|
||||
}
|
||||
|
||||
@@ -70,7 +72,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval(&'vm self, opcodes: OpCodes, env: Rc<Env<'vm>>) -> Result<Value<'vm>> {
|
||||
pub fn eval(&'vm self, opcodes: impl Iterator<Item = OpCode>, env: Rc<Env<'vm>>) -> Result<Value<'vm>> {
|
||||
let mut stack = Stack::<_, STACK_SIZE>::new();
|
||||
let mut iter = opcodes.into_iter();
|
||||
while let Some(opcode) = iter.next() {
|
||||
@@ -94,7 +96,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
) -> Result<usize> {
|
||||
match opcode {
|
||||
OpCode::Illegal => panic!("illegal opcode"),
|
||||
OpCode::Const { value } => stack.push(Value::Const(value))?,
|
||||
OpCode::Const { idx } => stack.push(Value::Const(self.consts[idx].clone()))?,
|
||||
OpCode::LoadThunk { idx } => {
|
||||
stack.push(Value::Thunk(Thunk::new(self.get_thunk(idx))))?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user