minor changes
This commit is contained in:
+29
-30
@@ -122,6 +122,7 @@ pub struct Vm<C: VmContext> {
|
||||
struct GcRoot<'gc> {
|
||||
stack: Vec<Value<'gc>>,
|
||||
call_stack: Vec<CallFrame<'gc>>,
|
||||
call_depth: usize,
|
||||
with_env: Option<Gc<'gc, WithEnv<'gc>>>,
|
||||
builtins: Value<'gc>,
|
||||
empty_list: Value<'gc>,
|
||||
@@ -143,16 +144,16 @@ fn init_builtins<'gc>(mc: &Mutation<'gc>, ctx: &mut impl VmContext) -> Value<'gc
|
||||
let consts = [
|
||||
(
|
||||
"__currentSystem",
|
||||
Value::new_gc(Gc::new(mc, NixString::new("x86_64-linux"))),
|
||||
Value::new_inline(ctx.intern_string("x86_64-linux")),
|
||||
),
|
||||
("__langVersion", Value::new_inline(6i32)),
|
||||
(
|
||||
"__nixVersion",
|
||||
Value::new_gc(Gc::new(mc, NixString::new("2.24.0"))),
|
||||
Value::new_inline(ctx.intern_string("2.24.0")),
|
||||
),
|
||||
(
|
||||
"__storeDir",
|
||||
Value::new_gc(Gc::new(mc, NixString::new("/nix/store"))),
|
||||
Value::new_inline(ctx.intern_string("/nix/store")),
|
||||
),
|
||||
(
|
||||
"__nixPath",
|
||||
@@ -190,6 +191,7 @@ impl<'gc> GcRoot<'gc> {
|
||||
GcRoot {
|
||||
stack: Vec::with_capacity(8192),
|
||||
call_stack: Vec::with_capacity(1024),
|
||||
call_depth: 0,
|
||||
with_env: None,
|
||||
builtins,
|
||||
empty_list: Value::new_gc(Gc::new(mc, List::default())),
|
||||
@@ -404,6 +406,21 @@ impl<'gc> GcRoot<'gc> {
|
||||
}
|
||||
}
|
||||
}};
|
||||
(SelectKeyData, $n:expr) => {{
|
||||
let mut keys = SmallVec::<[SelectKeyData; 4]>::with_capacity($n as usize);
|
||||
for _ in 0..$n {
|
||||
let tag = read!(u8);
|
||||
let Ok(ty) = AttrKeyType::try_from_primitive(tag)
|
||||
.map_err(|err| panic!("unknown key tag: {:#04x}", err.number));
|
||||
match ty {
|
||||
AttrKeyType::Static => {
|
||||
keys.push(SelectKeyData::Static(read!(StringId)))
|
||||
}
|
||||
AttrKeyType::Dynamic => keys.push(SelectKeyData::Dynamic),
|
||||
};
|
||||
}
|
||||
keys
|
||||
}};
|
||||
($type:ty) => {
|
||||
<$type>::from_le_bytes(read_array(ctx.bytecode(), pc))
|
||||
};
|
||||
@@ -436,12 +453,12 @@ impl<'gc> GcRoot<'gc> {
|
||||
ThunkState::Evaluated(v) => {
|
||||
self.replace_stack($depth, v.relax());
|
||||
}
|
||||
ThunkState::Apply { .. } => todo!("force apply"),
|
||||
ThunkState::Blackhole => {
|
||||
return Action::Done(Err(Error::eval_error(
|
||||
"infinite recursion encountered",
|
||||
)));
|
||||
}
|
||||
ThunkState::Apply { .. } => todo!("force apply"),
|
||||
}
|
||||
}
|
||||
}};
|
||||
@@ -583,6 +600,10 @@ impl<'gc> GcRoot<'gc> {
|
||||
Call => {
|
||||
// force func
|
||||
try_force!(0, inst_start_pc);
|
||||
if self.call_depth > 10000 {
|
||||
return Action::Done(Err(Error::eval_error("stack overflow; max-call-depth exceeded")))
|
||||
}
|
||||
self.call_depth += 1;
|
||||
let func = self.pop_stack();
|
||||
let arg = self.pop_stack();
|
||||
if let Some(closure) = func.as_gc::<Closure>() {
|
||||
@@ -649,19 +670,7 @@ impl<'gc> GcRoot<'gc> {
|
||||
let n = read!(u16) as usize;
|
||||
let _span_id = read!(u32);
|
||||
|
||||
let mut keys = SmallVec::<[SelectKeyData; 4]>::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
let tag = read!(u8);
|
||||
let Ok(ty) = AttrKeyType::try_from_primitive(tag)
|
||||
.map_err(|err| panic!("unknown key tag: {:#04x}", err.number));
|
||||
match ty {
|
||||
AttrKeyType::Static => {
|
||||
keys.push(SelectKeyData::Static(read!(StringId)))
|
||||
}
|
||||
AttrKeyType::Dynamic => keys.push(SelectKeyData::Dynamic),
|
||||
};
|
||||
}
|
||||
|
||||
let keys = read!(SelectKeyData, n);
|
||||
let dyn_count = keys
|
||||
.iter()
|
||||
.filter(|k| matches!(k, SelectKeyData::Dynamic))
|
||||
@@ -736,19 +745,7 @@ impl<'gc> GcRoot<'gc> {
|
||||
let n = read!(u16) as usize;
|
||||
let _span_id = read!(u32);
|
||||
|
||||
let mut keys = SmallVec::<[SelectKeyData; 4]>::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
let tag = read!(u8);
|
||||
let Ok(ty) = AttrKeyType::try_from_primitive(tag)
|
||||
.map_err(|err| panic!("unknown key tag: {:#04x}", err.number));
|
||||
match ty {
|
||||
AttrKeyType::Static => {
|
||||
keys.push(SelectKeyData::Static(read!(StringId)))
|
||||
}
|
||||
AttrKeyType::Dynamic => keys.push(SelectKeyData::Dynamic),
|
||||
};
|
||||
}
|
||||
|
||||
let keys = read!(SelectKeyData, n);
|
||||
let dyn_count = keys
|
||||
.iter()
|
||||
.filter(|k| matches!(k, SelectKeyData::Dynamic))
|
||||
@@ -1253,6 +1250,8 @@ impl<'gc> GcRoot<'gc> {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.call_depth -= 1;
|
||||
}
|
||||
self.current_env = Some(env);
|
||||
self.with_env = with_env;
|
||||
|
||||
Reference in New Issue
Block a user