refactor: use GAT in enum Ir
This commit is contained in:
@@ -103,15 +103,27 @@ impl<'a> BytecodeReader<'a> {
|
||||
let id = self.read_u32();
|
||||
OperandData::Const(ctx.get_const(id))
|
||||
}
|
||||
OperandType::BigInt => {
|
||||
let val = self.read_i64();
|
||||
OperandData::BigInt(val)
|
||||
}
|
||||
OperandType::Local => {
|
||||
let layer = self.read_u8();
|
||||
let idx = self.read_u32();
|
||||
OperandData::Local { layer, idx }
|
||||
}
|
||||
OperandType::Builtins => OperandData::Builtins,
|
||||
OperandType::BigInt => {
|
||||
let val = self.read_i64();
|
||||
OperandData::BigInt(val)
|
||||
OperandType::ReplBinding => {
|
||||
let id = self.read_string_id();
|
||||
OperandData::ReplBinding(id)
|
||||
}
|
||||
OperandType::ScopedImportBinding => {
|
||||
let id = self.read_string_id();
|
||||
OperandData::ScopedImportBinding(id)
|
||||
}
|
||||
OperandType::WithLookup => {
|
||||
let id = self.read_string_id();
|
||||
OperandData::WithLookup(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -227,16 +227,21 @@ pub struct Vm<'gc> {
|
||||
|
||||
pub(crate) enum OperandData {
|
||||
Const(StaticValue),
|
||||
BigInt(i64),
|
||||
Local { layer: u8, idx: u32 },
|
||||
Builtins,
|
||||
BigInt(i64),
|
||||
ReplBinding(StringId),
|
||||
ScopedImportBinding(StringId),
|
||||
WithLookup(StringId),
|
||||
}
|
||||
|
||||
impl OperandData {
|
||||
pub(crate) fn resolve<'gc>(&self, mc: &Mutation<'gc>, root: &Vm<'gc>) -> Value<'gc> {
|
||||
use OperandData::*;
|
||||
match *self {
|
||||
OperandData::Const(sv) => sv.into(),
|
||||
OperandData::Local { layer, idx } => {
|
||||
Const(sv) => sv.into(),
|
||||
BigInt(val) => Value::new_gc(Gc::new(mc, val)),
|
||||
Local { layer, idx } => {
|
||||
let mut cur = root.env;
|
||||
for _ in 0..layer {
|
||||
let prev = cur.borrow().prev.expect("env chain too short");
|
||||
@@ -244,8 +249,10 @@ impl OperandData {
|
||||
}
|
||||
cur.borrow().locals[idx as usize]
|
||||
}
|
||||
OperandData::Builtins => root.builtins,
|
||||
OperandData::BigInt(val) => Value::new_gc(Gc::new(mc, val)),
|
||||
Builtins => root.builtins,
|
||||
ReplBinding(_id) => todo!(),
|
||||
ScopedImportBinding(_id) => todo!(),
|
||||
WithLookup(_id) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user