runtime, macros: unify NaN-boxed value API under ValueVariant trait

This commit is contained in:
2026-07-15 00:01:34 +08:00
parent 7220b42024
commit a1a44a6652
28 changed files with 524 additions and 487 deletions
+16 -20
View File
@@ -28,7 +28,7 @@ pub(crate) fn op_add<'gc, M: Machine<'gc>>(
let combined = format!("{ls}{rs}");
let canon = canon_path_str(&combined);
let sid = ctx.intern_string(canon);
m.push(Value::new_inline(fix_runtime::Path(sid)));
m.push(Value::new(fix_runtime::Path(sid)));
return Step::Continue(());
}
if let (Some(ls), Some(rs)) = (ctx.get_string(lhs), ctx.get_string_or_path(rhs)) {
@@ -39,7 +39,7 @@ pub(crate) fn op_add<'gc, M: Machine<'gc>>(
mc,
crate::NixString::with_context(format!("{ls}{rs}"), merged),
);
m.push(Value::new_gc(ns));
m.push(Value::new(ns));
return Step::Continue(());
}
let res = numeric_binop(lhs, rhs, mc, i64::wrapping_add, |a, b| a + b);
@@ -200,7 +200,7 @@ pub(crate) fn op_concat<'gc, M: Machine<'gc>>(
let mut items = smallvec::SmallVec::new();
items.extend_from_slice(&l.inner.borrow());
items.extend_from_slice(&r.inner.borrow());
m.push(Value::new_gc(Gc::new(
m.push(Value::new(Gc::new(
mc,
crate::List {
inner: RefLock::new(items),
@@ -216,7 +216,7 @@ pub(crate) fn op_update<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
let (l, r) = m.force_and_retry::<(Gc<AttrSet>, Gc<AttrSet>)>(reader, mc)?;
m.push(Value::new_gc(l.merge(&r, mc)));
m.push(Value::new(l.merge(&r, mc)));
Step::Continue(())
}
@@ -229,7 +229,7 @@ pub(crate) fn op_neg<'gc, M: Machine<'gc>>(
let rhs = m.force_and_retry::<NixNum>(reader, mc)?;
match rhs {
NixNum::Int(int) => m.push(Value::make_int(-int, mc)),
NixNum::Float(float) => m.push(Value::new_float(-float)),
NixNum::Float(float) => m.push(Value::new(-float)),
}
Step::Continue(())
}
@@ -241,7 +241,7 @@ pub(crate) fn op_not<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
let rhs = m.force_and_retry::<bool>(reader, mc)?;
m.push(Value::new_inline(!rhs));
m.push(Value::new(!rhs));
Step::Continue(())
}
@@ -263,17 +263,17 @@ fn compare_values_inner<'gc, M: Machine<'gc>>(
a.partial_cmp(&(b as f64)).unwrap_or(Ordering::Less)
}
};
m.push(Value::new_inline(pred(ord)));
m.push(Value::new(pred(ord)));
return Ok(());
}
if let (Some(a), Some(b)) = (ctx.get_string(lhs), ctx.get_string(rhs)) {
m.push(Value::new_inline(pred(a.cmp(b))));
m.push(Value::new(pred(a.cmp(b))));
return Ok(());
}
if let (Some(a), Some(b)) = (lhs.as_inline::<Path>(), rhs.as_inline::<Path>()) {
if let (Some(a), Some(b)) = (lhs.downcast::<Path>(), rhs.downcast::<Path>()) {
let a = ctx.resolve_string(a.0);
let b = ctx.resolve_string(b.0);
m.push(Value::new_inline(pred(a.cmp(b))));
m.push(Value::new(pred(a.cmp(b))));
return Ok(());
}
// TODO: compare other types
@@ -285,12 +285,12 @@ fn compare_values_inner<'gc, M: Machine<'gc>>(
}
pub(crate) fn get_num(val: StrictValue<'_>) -> Option<NixNum> {
if let Some(i) = val.as_inline::<i32>() {
if let Some(i) = val.downcast::<i32>() {
Some(NixNum::Int(i64::from(i)))
} else if let Some(gc_i) = val.as_gc::<i64>() {
} else if let Some(gc_i) = val.downcast::<i64>() {
Some(NixNum::Int(*gc_i))
} else {
val.as_float().map(NixNum::Float)
val.downcast::<f64>().map(NixNum::Float)
}
}
@@ -304,13 +304,9 @@ fn numeric_binop<'gc>(
) -> crate::VmResult<Value<'gc>> {
match (get_num(lhs), get_num(rhs)) {
(Some(NixNum::Int(a)), Some(NixNum::Int(b))) => Ok(Value::make_int(int_op(a, b), mc)),
(Some(NixNum::Float(a)), Some(NixNum::Float(b))) => Ok(Value::new_float(float_op(a, b))),
(Some(NixNum::Int(a)), Some(NixNum::Float(b))) => {
Ok(Value::new_float(float_op(a as f64, b)))
}
(Some(NixNum::Float(a)), Some(NixNum::Int(b))) => {
Ok(Value::new_float(float_op(a, b as f64)))
}
(Some(NixNum::Float(a)), Some(NixNum::Float(b))) => Ok(Value::new(float_op(a, b))),
(Some(NixNum::Int(a)), Some(NixNum::Float(b))) => Ok(Value::new(float_op(a as f64, b))),
(Some(NixNum::Float(a)), Some(NixNum::Int(b))) => Ok(Value::new(float_op(a, b as f64))),
_ => Err(crate::vm_err(format!(
"cannot perform arithmetic on non-numbers: {:?}",
(lhs.ty(), rhs.ty())
+6 -6
View File
@@ -21,7 +21,7 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
return m.finish_err(Error::eval_error("stack overflow; max-call-depth exceeded"));
}
m.inc_call_depth();
if let Some(closure) = func.as_gc::<Closure>() {
if let Some(closure) = func.downcast::<Closure>() {
if closure.pattern.is_some() {
// FIXME: better DX...
m.push(func.relax());
@@ -46,7 +46,7 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
});
reader.set_pc(ip as usize);
m.set_env(new_env);
} else if let Some(primop) = func.as_inline::<PrimOp>() {
} else if let Some(primop) = func.downcast::<PrimOp>() {
if primop.arity == 1 {
m.push(arg);
m.push_call_frame(CallFrame {
@@ -61,9 +61,9 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
arity: primop.arity - 1,
args: [arg, Value::default(), Value::default()],
};
m.push(Value::new_gc(Gc::new(mc, app)));
m.push(Value::new(Gc::new(mc, app)));
}
} else if let Some(app) = func.as_gc::<PrimOpApp>() {
} else if let Some(app) = func.downcast::<PrimOpApp>() {
if app.arity == 1 {
for i in 0..app.primop.arity - 1 {
m.push(app.args[i as usize]);
@@ -82,9 +82,9 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
..*app
};
new_app.args[position] = arg;
m.push(Value::new_gc(Gc::new(mc, new_app)))
m.push(Value::new(Gc::new(mc, new_app)))
}
} else if let Some(attrs) = func.as_gc::<AttrSet>()
} else if let Some(attrs) = func.downcast::<AttrSet>()
&& let Some(functor) = attrs.lookup(m.functor_sym())
{
// f arg => (f.__functor f) arg
+3 -3
View File
@@ -17,7 +17,7 @@ pub(crate) fn op_make_thunk<'gc, M: Machine<'gc>>(
env: m.env(),
}),
);
m.push(Value::new_gc(thunk));
m.push(Value::new(thunk));
Step::Continue(())
}
@@ -38,7 +38,7 @@ pub(crate) fn op_make_closure<'gc, M: Machine<'gc>>(
pattern: None,
},
);
m.push(Value::new_gc(closure));
m.push(Value::new(closure));
Step::Continue(())
}
@@ -88,6 +88,6 @@ pub(crate) fn op_make_pattern_closure<'gc, M: Machine<'gc>>(
pattern: Some(pattern),
},
);
m.push(Value::new_gc(closure));
m.push(Value::new(closure));
Step::Continue(())
}
+9 -9
View File
@@ -57,7 +57,7 @@ pub(crate) fn op_make_attrs<'gc, M: Machine<'gc>>(
kv.sort_by_key(|(k, _)| *k);
let attrs = Gc::new(mc, AttrSet::from_sorted_unchecked(kv));
m.push(Value::new_gc(attrs));
m.push(Value::new(attrs));
Step::Continue(())
}
@@ -195,7 +195,7 @@ pub(crate) fn op_has_attr_path_static<'gc, M: Machine<'gc>>(
let current = m.force_and_retry::<StrictValue>(reader, mc)?;
match current
.as_gc::<AttrSet>()
.downcast::<AttrSet>()
.and_then(|attrs| attrs.lookup(key))
{
Some(v) => {
@@ -223,7 +223,7 @@ pub(crate) fn op_has_attr_path_dynamic<'gc, M: Machine<'gc>>(
};
match current
.as_gc::<AttrSet>()
.downcast::<AttrSet>()
.and_then(|attrs| attrs.lookup(key_sid))
{
Some(v) => {
@@ -263,9 +263,9 @@ pub(crate) fn op_has_attr_static<'gc, M: Machine<'gc>>(
let key = reader.read_string_id();
let current = m.force_and_retry::<StrictValue>(reader, mc)?;
m.push(Value::new_inline(
m.push(Value::new(
current
.as_gc::<AttrSet>()
.downcast::<AttrSet>()
.and_then(|attrs| attrs.lookup(key))
.is_some(),
));
@@ -289,9 +289,9 @@ pub(crate) fn op_has_attr_dynamic<'gc, M: MachineExt<'gc>>(
Err(got) => return m.finish_type_err(NixType::String, got),
};
m.push(Value::new_inline(
m.push(Value::new(
current
.as_gc::<AttrSet>()
.downcast::<AttrSet>()
.and_then(|attrs| attrs.lookup(key_sid))
.is_some(),
));
@@ -304,7 +304,7 @@ pub(crate) fn op_has_attr_dynamic<'gc, M: MachineExt<'gc>>(
#[inline(always)]
pub(crate) fn op_has_attr_resolve<'gc, M: Machine<'gc>>(m: &mut M) -> Step {
// If we reach here, has_attr check has failed, push false (AttrSet is already popped)
m.push(Value::new_inline(false));
m.push(Value::new(false));
Step::Continue(())
}
@@ -326,7 +326,7 @@ pub(crate) fn op_make_list<'gc, M: Machine<'gc>>(
inner: RefLock::new(items),
},
);
m.push(Value::new_gc(list));
m.push(Value::new(list));
Step::Continue(())
}
+2 -2
View File
@@ -12,7 +12,7 @@ pub(crate) fn op_jump_if_false<'gc, M: Machine<'gc>>(
) -> Step {
let offset = reader.read_i32();
let cond = m.force_and_retry::<StrictValue>(reader, mc)?;
if cond.as_inline::<bool>() == Some(false) {
if cond.downcast::<bool>() == Some(false) {
reader.set_pc(((reader.pc() as isize) + (offset as isize)) as usize);
}
Step::Continue(())
@@ -26,7 +26,7 @@ pub(crate) fn op_jump_if_true<'gc, M: Machine<'gc>>(
) -> Step {
let offset = reader.read_i32();
let cond = m.force_and_retry::<StrictValue>(reader, mc)?;
if cond.as_inline::<bool>() == Some(true) {
if cond.downcast::<bool>() == Some(true) {
reader.set_pc(((reader.pc() as isize) + (offset as isize)) as usize);
}
Step::Continue(())
+7 -7
View File
@@ -9,7 +9,7 @@ pub(crate) fn op_push_smi<'gc, M: Machine<'gc>>(
reader: &mut BytecodeReader<'_>,
) -> Step {
let val = reader.read_i32();
m.push(Value::new_inline(val));
m.push(Value::new(val));
Step::Continue(())
}
@@ -20,7 +20,7 @@ pub(crate) fn op_push_bigint<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
let val = reader.read_i64();
m.push(Value::new_gc(Gc::new(mc, val)));
m.push(Value::new(Gc::new(mc, val)));
Step::Continue(())
}
@@ -30,7 +30,7 @@ pub(crate) fn op_push_float<'gc, M: Machine<'gc>>(
reader: &mut BytecodeReader<'_>,
) -> Step {
let val = reader.read_f64();
m.push(Value::new_float(val));
m.push(Value::new(val));
Step::Continue(())
}
@@ -40,24 +40,24 @@ pub(crate) fn op_push_string<'gc, M: Machine<'gc>>(
reader: &mut BytecodeReader<'_>,
) -> Step {
let sid = reader.read_string_id();
m.push(Value::new_inline(sid));
m.push(Value::new(sid));
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_push_null<'gc, M: Machine<'gc>>(m: &mut M) -> Step {
m.push(Value::new_inline(crate::Null));
m.push(Value::new(crate::Null));
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_push_true<'gc, M: Machine<'gc>>(m: &mut M) -> Step {
m.push(Value::new_inline(true));
m.push(Value::new(true));
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_push_false<'gc, M: Machine<'gc>>(m: &mut M) -> Step {
m.push(Value::new_inline(false));
m.push(Value::new(false));
Step::Continue(())
}
+9 -9
View File
@@ -22,7 +22,7 @@ pub(crate) fn op_load_builtin<'gc, M: Machine<'gc>>(
) -> Step {
let Ok(id) = BuiltinId::try_from(reader.read_u8())
.map_err(|err| panic!("unknown builtin id: {}", err.number));
m.push(Value::new_inline(PrimOp {
m.push(Value::new(PrimOp {
id,
arity: BUILTINS[id as usize].1,
dispatch_ip: Continuation::entry_for_builtin(id).ip(),
@@ -49,7 +49,7 @@ pub(crate) fn op_load_scoped_binding<'gc, M: Machine<'gc>>(
let slot_id = reader.read_u32();
let name = reader.read_string_id();
let scope = m.scope_slot(slot_id);
let Some(attrs) = scope.as_gc::<AttrSet>() else {
let Some(attrs) = scope.downcast::<AttrSet>() else {
return m.finish_err(Error::eval_error("internal: scope slot is not an attrset"));
};
match attrs.lookup(name) {
@@ -73,10 +73,10 @@ pub(crate) fn op_coerce_to_string<'gc, M: Machine<'gc>>(
let val = m.force_and_retry::<StrictValue>(reader, mc)?;
if val.is::<StringId>() || val.is::<NixString>() {
m.push(val.relax());
} else if let Some(p) = val.as_inline::<Path>() {
} else if let Some(p) = val.downcast::<Path>() {
// Coercing a path to a string yields the canonical path text.
// FIXME: copy to store
m.push(Value::new_inline(p.0));
m.push(Value::new(p.0));
} else {
todo!("coerce other types to string: {:?}", val.ty());
}
@@ -122,10 +122,10 @@ pub(crate) fn op_concat_strings<'gc, M: Machine<'gc>>(
if merged.is_empty() {
let sid = ctx.intern_string(result);
m.push(Value::new_inline(sid));
m.push(Value::new(sid));
} else {
let ns = gc_arena::Gc::new(mc, NixString::with_context(result, merged));
m.push(Value::new_gc(ns));
m.push(Value::new(ns));
}
Step::Continue(())
}
@@ -140,8 +140,8 @@ pub(crate) fn op_resolve_path<'gc, M: MachineExt<'gc>>(
let path_val = m.force_and_retry::<StrictValue>(reader, mc)?;
let dir_id = reader.read_string_id();
// Already a path: keep as-is. ResolvePath is idempotent on paths.
if let Some(p) = path_val.as_inline::<Path>() {
m.push(Value::new_inline(p));
if let Some(p) = path_val.downcast::<Path>() {
m.push(Value::new(p));
return Step::Continue(());
}
let path = match ctx.get_string(path_val) {
@@ -158,7 +158,7 @@ pub(crate) fn op_resolve_path<'gc, M: MachineExt<'gc>>(
Err(e) => return m.finish_err(e),
};
let sid = ctx.intern_string(resolved);
m.push(Value::new_inline(Path(sid)));
m.push(Value::new(Path(sid)));
Step::Continue(())
}
+3 -3
View File
@@ -13,7 +13,7 @@ pub(crate) fn op_lookup_with<'gc, M: Machine<'gc>>(
mc: &gc_arena::Mutation<'gc>,
) -> Step {
#[allow(clippy::unwrap_used)]
let counter = m.peek_forced(0).as_inline::<i32>().unwrap();
let counter = m.peek_forced(0).downcast::<i32>().unwrap();
let name = reader.read_string_id();
let n = reader.read_u8();
@@ -57,7 +57,7 @@ pub(crate) fn op_lookup_with<'gc, M: Machine<'gc>>(
};
if let Some(val) = namespace
.as_gc::<AttrSet>()
.downcast::<AttrSet>()
.and_then(|attrs| attrs.lookup(name))
{
m.replace(0, val);
@@ -67,7 +67,7 @@ pub(crate) fn op_lookup_with<'gc, M: Machine<'gc>>(
Symbol::from(ctx.resolve_string(name))
)));
} else {
m.replace(0, Value::new_inline(counter + 1));
m.replace(0, Value::new(counter + 1));
reader.set_pc(resume_pc);
}
+15 -21
View File
@@ -7,7 +7,7 @@
use std::path::PathBuf;
use fix_bytecode::{InstructionPtr, Continuation};
use fix_bytecode::{Continuation, InstructionPtr};
use fix_error::{Error, Result, Source};
use fix_lang::{BUILTINS, BuiltinId, StringId};
use gc_arena::metrics::Pacing;
@@ -63,7 +63,7 @@ fn init_builtins<'gc>(mc: &Mutation<'gc>, ctx: &mut impl VmRuntimeCtx) -> Value<
let dispatch_ip = Continuation::entry_for_builtin(id).ip();
entries.push((
name,
Value::new_inline(PrimOp {
Value::new(PrimOp {
id,
arity,
dispatch_ip,
@@ -74,21 +74,15 @@ fn init_builtins<'gc>(mc: &Mutation<'gc>, ctx: &mut impl VmRuntimeCtx) -> Value<
let consts = [
(
"__currentSystem",
Value::new_inline(ctx.intern_string("x86_64-linux")),
Value::new(ctx.intern_string("x86_64-linux")),
),
("__langVersion", Value::new_inline(6i32)),
(
"__nixVersion",
Value::new_inline(ctx.intern_string("2.24.0")),
),
(
"__storeDir",
Value::new_inline(ctx.intern_string("/nix/store")),
),
("__nixPath", Value::new_gc(Gc::new(mc, List::default()))),
("null", Value::new_inline(Null)),
("true", Value::new_inline(true)),
("false", Value::new_inline(false)),
("__langVersion", Value::new(6i32)),
("__nixVersion", Value::new(ctx.intern_string("2.24.0"))),
("__storeDir", Value::new(ctx.intern_string("/nix/store"))),
("__nixPath", Value::new(Gc::new(mc, List::default()))),
("null", Value::new(Null)),
("true", Value::new(true)),
("false", Value::new(false)),
];
for (name, val) in consts {
@@ -99,12 +93,12 @@ fn init_builtins<'gc>(mc: &Mutation<'gc>, ctx: &mut impl VmRuntimeCtx) -> Value<
let self_ref_thunk = Gc::new(mc, RefLock::new(ThunkState::Blackhole));
let sym = ctx.intern_string("builtins");
entries.push((sym, Value::new_gc(self_ref_thunk)));
entries.push((sym, Value::new(self_ref_thunk)));
entries.sort_by_key(|(k, _)| *k);
let builtins_set = Gc::new(mc, AttrSet::from_sorted_unchecked(entries));
let builtins_value = Value::new_gc(builtins_set);
let builtins_value = Value::new(builtins_set);
*self_ref_thunk.borrow_mut(mc) =
ThunkState::Evaluated(builtins_value.restrict().expect("builtins is not a thunk"));
builtins_value
@@ -125,8 +119,8 @@ impl<'gc> Vm<'gc> {
scope_slots: Vec::new(),
builtins,
empty_list: Value::new_gc(Gc::new(mc, List::default())),
empty_attrs: Value::new_gc(Gc::new(mc, AttrSet::default())),
empty_list: Value::new(Gc::new(mc, List::default())),
empty_attrs: Value::new(Gc::new(mc, AttrSet::default())),
force_mode,
@@ -202,7 +196,7 @@ impl<'gc> Machine<'gc> for Vm<'gc> {
mc: &Mutation<'gc>,
resume_pc: usize,
) -> Step {
let Some(thunk) = self.peek(depth).as_gc::<Thunk>() else {
let Some(thunk) = self.peek(depth).downcast::<Thunk>() else {
return Step::Continue(());
};
let mut state = thunk.borrow_mut(mc);
+49 -49
View File
@@ -22,11 +22,11 @@ pub fn has_context<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
let val = m.force_and_retry::<StrictValue>(reader, mc)?;
if !val.is::<StringId>() && val.as_gc::<NixString>().is_none() {
if !val.is::<StringId>() && val.downcast::<NixString>().is_none() {
return m.finish_type_err(NixType::String, val.ty());
}
let has_ctx = !ctx.get_string_context(val).is_empty();
m.return_from_primop(Value::new_inline(has_ctx), reader)
m.return_from_primop(Value::new(has_ctx), reader)
}
pub fn unsafe_discard_string_context<'gc, M: Machine<'gc>>(
@@ -36,14 +36,14 @@ pub fn unsafe_discard_string_context<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
let val = m.force_and_retry::<StrictValue>(reader, mc)?;
if let Some(sid) = val.as_inline::<StringId>() {
return m.return_from_primop(Value::new_inline(sid), reader);
if let Some(sid) = val.downcast::<StringId>() {
return m.return_from_primop(Value::new(sid), reader);
}
let Some(ns) = val.as_gc::<NixString>() else {
let Some(ns) = val.downcast::<NixString>() else {
return m.finish_type_err(NixType::String, val.ty());
};
let sid = ctx.intern_string(ns.as_str());
m.return_from_primop(Value::new_inline(sid), reader)
m.return_from_primop(Value::new(sid), reader)
}
pub fn unsafe_discard_output_dependency<'gc, M: Machine<'gc>>(
@@ -53,15 +53,15 @@ pub fn unsafe_discard_output_dependency<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
let val = m.force_and_retry::<StrictValue>(reader, mc)?;
if let Some(sid) = val.as_inline::<StringId>() {
return m.return_from_primop(Value::new_inline(sid), reader);
if let Some(sid) = val.downcast::<StringId>() {
return m.return_from_primop(Value::new(sid), reader);
}
let Some(ns) = val.as_gc::<NixString>() else {
let Some(ns) = val.downcast::<NixString>() else {
return m.finish_type_err(NixType::String, val.ty());
};
if ns.context().is_empty() {
let sid = ctx.intern_string(ns.as_str());
return m.return_from_primop(Value::new_inline(sid), reader);
return m.return_from_primop(Value::new(sid), reader);
}
let mut new_ctx = StringContext::new();
@@ -77,7 +77,7 @@ pub fn unsafe_discard_output_dependency<'gc, M: Machine<'gc>>(
let s: Box<str> = ns.as_str().into();
let new_ns = Gc::new(mc, NixString::with_context(s, new_ctx));
m.return_from_primop(Value::new_gc(new_ns), reader)
m.return_from_primop(Value::new(new_ns), reader)
}
pub fn get_context<'gc, M: Machine<'gc>>(
@@ -87,7 +87,7 @@ pub fn get_context<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
let val = m.force_and_retry::<StrictValue>(reader, mc)?;
if !val.is::<StringId>() && val.as_gc::<NixString>().is_none() {
if !val.is::<StringId>() && val.downcast::<NixString>().is_none() {
return m.finish_type_err(NixType::String, val.ty());
}
let elems = ctx.get_string_context(val);
@@ -135,29 +135,29 @@ pub fn get_context<'gc, M: Machine<'gc>>(
let mut sub: SmallVec<[(StringId, Value<'gc>); 4]> = SmallVec::new();
if info.all_outputs {
sub.push((ctx.intern_string("allOutputs"), Value::new_inline(true)));
sub.push((ctx.intern_string("allOutputs"), Value::new(true)));
}
if !info.outputs.is_empty() {
let items: smallvec::SmallVec<[Value<'gc>; 4]> = info
.outputs
.iter()
.map(|o| Value::new_inline(ctx.intern_string(o)))
.map(|o| Value::new(ctx.intern_string(o)))
.collect();
let list = VmList::new(mc, items);
sub.push((ctx.intern_string("outputs"), Value::new_gc(list)));
sub.push((ctx.intern_string("outputs"), Value::new(list)));
}
if info.path {
sub.push((ctx.intern_string("path"), Value::new_inline(true)));
sub.push((ctx.intern_string("path"), Value::new(true)));
}
sub.sort_by_key(|(k, _)| *k);
let sub_attrs = Gc::new(mc, AttrSet::from_sorted_unchecked(sub));
outer_entries.push((ctx.intern_string(&path), Value::new_gc(sub_attrs)));
outer_entries.push((ctx.intern_string(&path), Value::new(sub_attrs)));
}
outer_entries.sort_by_key(|(k, _)| *k);
let outer = Gc::new(mc, AttrSet::from_sorted_unchecked(outer_entries));
m.return_from_primop(Value::new_gc(outer), reader)
m.return_from_primop(Value::new(outer), reader)
}
/// appendContext :: String -> AttrSet -> String
@@ -192,9 +192,9 @@ pub fn append_context<'gc, M: Machine<'gc>>(
let acc = Gc::new(mc, NixString::with_context("", initial_ctx));
m.push(str_val.relax());
m.push(Value::new_gc(attrs));
m.push(Value::new_inline(0i32));
m.push(Value::new_gc(acc));
m.push(Value::new(attrs));
m.push(Value::new(0i32));
m.push(Value::new(acc));
reader.set_pc(Continuation::PAppendContextLoop.ip() as usize);
Step::Continue(())
@@ -207,9 +207,9 @@ pub fn append_context_loop<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
#[allow(clippy::unwrap_used)]
let idx = m.peek(1).as_inline::<i32>().unwrap();
let idx = m.peek(1).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let attrs = m.peek_forced(2).as_gc::<AttrSet>().unwrap();
let attrs = m.peek_forced(2).downcast::<AttrSet>().unwrap();
if idx as usize >= attrs.entries.len() {
return append_context_finalize(m, ctx, reader, mc);
@@ -238,14 +238,14 @@ pub fn append_context_entry_forced<'gc, M: Machine<'gc>>(
// Evaluated value into the slot.
m.force_slot(0, reader, mc)?;
let entry_val = m.peek_forced(0);
let Some(entry_attrs) = entry_val.as_gc::<AttrSet>() else {
let Some(entry_attrs) = entry_val.downcast::<AttrSet>() else {
return m.finish_type_err(NixType::AttrSet, entry_val.ty());
};
#[allow(clippy::unwrap_used)]
let idx = m.peek(2).as_inline::<i32>().unwrap();
let idx = m.peek(2).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let outer = m.peek_forced(3).as_gc::<AttrSet>().unwrap();
let outer = m.peek_forced(3).downcast::<AttrSet>().unwrap();
let path_key = outer.entries[idx as usize].0;
let path_str_owned: Box<str> = ctx.resolve_string(path_key).into();
if !path_str_owned.starts_with("/nix/store/") {
@@ -263,11 +263,11 @@ pub fn append_context_entry_forced<'gc, M: Machine<'gc>>(
let outputs_id = ctx.intern_string("outputs");
#[allow(clippy::unwrap_used)]
let acc_gc = m.peek(1).as_gc::<NixString>().unwrap();
let acc_gc = m.peek(1).downcast::<NixString>().unwrap();
let mut new_acc: StringContext = acc_gc.context().iter().cloned().collect();
if let Some(v) = entry_attrs.lookup(path_id)
&& v.as_inline::<bool>() == Some(true)
&& v.downcast::<bool>() == Some(true)
{
new_acc.insert(StringContextElem::Opaque {
path: path_str_owned.clone(),
@@ -275,7 +275,7 @@ pub fn append_context_entry_forced<'gc, M: Machine<'gc>>(
}
if let Some(v) = entry_attrs.lookup(all_outputs_id)
&& v.as_inline::<bool>() == Some(true)
&& v.downcast::<bool>() == Some(true)
{
if !path_str_owned.ends_with(".drv") {
return m.finish_err(Error::eval_error(format!(
@@ -288,7 +288,7 @@ pub fn append_context_entry_forced<'gc, M: Machine<'gc>>(
}
let new_acc_gc = Gc::new(mc, NixString::with_context("", new_acc));
m.replace(1, Value::new_gc(new_acc_gc));
m.replace(1, Value::new(new_acc_gc));
if let Some(outputs_val) = entry_attrs.lookup(outputs_id) {
m.replace(0, outputs_val);
@@ -304,8 +304,8 @@ pub fn append_context_entry_forced<'gc, M: Machine<'gc>>(
let _ = m.pop();
#[allow(clippy::unwrap_used)]
let idx_back = m.peek(1).as_inline::<i32>().unwrap();
m.replace(1, Value::new_inline(idx_back + 1));
let idx_back = m.peek(1).downcast::<i32>().unwrap();
m.replace(1, Value::new(idx_back + 1));
reader.set_pc(Continuation::PAppendContextLoop.ip() as usize);
Step::Continue(())
}
@@ -318,20 +318,20 @@ pub fn append_context_outputs_forced<'gc, M: Machine<'gc>>(
) -> Step {
m.force_slot(0, reader, mc)?;
let list_val = m.peek_forced(0);
let Some(list) = list_val.as_gc::<VmList>() else {
let Some(list) = list_val.downcast::<VmList>() else {
return m.finish_type_err(NixType::List, list_val.ty());
};
if list.inner.borrow().is_empty() {
// Stack: [strVal, attrs, idx, acc, list] -> drop list, bump idx.
let _ = m.pop();
#[allow(clippy::unwrap_used)]
let idx_back = m.peek(1).as_inline::<i32>().unwrap();
m.replace(1, Value::new_inline(idx_back + 1));
let idx_back = m.peek(1).downcast::<i32>().unwrap();
m.replace(1, Value::new(idx_back + 1));
reader.set_pc(Continuation::PAppendContextLoop.ip() as usize);
return Step::Continue(());
}
m.push(Value::new_inline(0i32));
m.push(Value::new(0i32));
reader.set_pc(Continuation::PAppendContextOutputElementLoop.ip() as usize);
Step::Continue(())
}
@@ -343,9 +343,9 @@ pub fn append_context_output_element_loop<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
#[allow(clippy::unwrap_used)]
let oidx = m.peek(0).as_inline::<i32>().unwrap();
let oidx = m.peek(0).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let list = m.peek_forced(1).as_gc::<VmList>().unwrap();
let list = m.peek_forced(1).downcast::<VmList>().unwrap();
let len = list.inner.borrow().len();
if oidx as usize >= len {
// Stack: [strVal, attrs, idx, acc, list, oidx] -> drop oidx & list,
@@ -353,8 +353,8 @@ pub fn append_context_output_element_loop<'gc, M: Machine<'gc>>(
let _ = m.pop();
let _ = m.pop();
#[allow(clippy::unwrap_used)]
let idx_back = m.peek(1).as_inline::<i32>().unwrap();
m.replace(1, Value::new_inline(idx_back + 1));
let idx_back = m.peek(1).downcast::<i32>().unwrap();
m.replace(1, Value::new(idx_back + 1));
reader.set_pc(Continuation::PAppendContextLoop.ip() as usize);
return Step::Continue(());
}
@@ -385,9 +385,9 @@ pub fn append_context_output_element_forced<'gc, M: Machine<'gc>>(
let output_name: Box<str> = output_name.into();
#[allow(clippy::unwrap_used)]
let idx = m.peek(4).as_inline::<i32>().unwrap();
let idx = m.peek(4).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let outer = m.peek_forced(5).as_gc::<AttrSet>().unwrap();
let outer = m.peek_forced(5).downcast::<AttrSet>().unwrap();
let path_key = outer.entries[idx as usize].0;
let path_str: Box<str> = ctx.resolve_string(path_key).into();
if !path_str.ends_with(".drv") {
@@ -397,21 +397,21 @@ pub fn append_context_output_element_forced<'gc, M: Machine<'gc>>(
}
#[allow(clippy::unwrap_used)]
let acc_gc = m.peek(3).as_gc::<NixString>().unwrap();
let acc_gc = m.peek(3).downcast::<NixString>().unwrap();
let mut new_acc: StringContext = acc_gc.context().iter().cloned().collect();
new_acc.insert(StringContextElem::Built {
drv_path: path_str,
output: output_name,
});
let new_acc_gc = Gc::new(mc, NixString::with_context("", new_acc));
m.replace(3, Value::new_gc(new_acc_gc));
m.replace(3, Value::new(new_acc_gc));
// Stack: [strVal, attrs, idx, acc, list, oidx, outElem] -> drop outElem,
// bump oidx in place.
let _ = m.pop();
#[allow(clippy::unwrap_used)]
let oidx = m.peek(0).as_inline::<i32>().unwrap();
m.replace(0, Value::new_inline(oidx + 1));
let oidx = m.peek(0).downcast::<i32>().unwrap();
m.replace(0, Value::new(oidx + 1));
reader.set_pc(Continuation::PAppendContextOutputElementLoop.ip() as usize);
Step::Continue(())
}
@@ -424,7 +424,7 @@ fn append_context_finalize<'gc, M: Machine<'gc>>(
) -> Step {
// Stack: [strVal, attrs, idx, acc]
#[allow(clippy::unwrap_used)]
let acc_gc = m.pop().as_gc::<NixString>().unwrap();
let acc_gc = m.pop().downcast::<NixString>().unwrap();
let _ = m.pop(); // idx
let _ = m.pop(); // attrs
let str_val_raw = m.pop();
@@ -438,10 +438,10 @@ fn append_context_finalize<'gc, M: Machine<'gc>>(
let context: StringContext = acc_gc.context().iter().cloned().collect();
let result = if context.is_empty() {
let sid = ctx.intern_string(s_str);
Value::new_inline(sid)
Value::new(sid)
} else {
let ns = Gc::new(mc, NixString::with_context(s_str, context));
Value::new_gc(ns)
Value::new(ns)
};
m.return_from_primop(result, reader)
}
+28 -28
View File
@@ -44,14 +44,14 @@ pub fn deep_seq_force_top<'gc, M: Machine<'gc>>(
let e1 = m.peek_forced(1);
let children: SmallVec<_> = if let Some(attrs) = e1.as_gc::<AttrSet>() {
let children: SmallVec<_> = if let Some(attrs) = e1.downcast::<AttrSet>() {
let attrs = &attrs.entries;
if attrs.is_empty() {
SmallVec::new()
} else {
attrs.iter().map(|&(_, v)| v).collect()
}
} else if let Some(list) = e1.as_gc::<List<'gc>>() {
} else if let Some(list) = e1.downcast::<List>() {
let inner = list.inner.borrow();
if inner.is_empty() {
SmallVec::new()
@@ -69,15 +69,15 @@ pub fn deep_seq_force_top<'gc, M: Machine<'gc>>(
}
let count = children.len() as i32;
let seen: Gc<'gc, List<'gc>> = Gc::new(mc, List::default());
let worklist: Gc<'gc, List<'gc>> = List::new(mc, children);
let seen = Gc::new(mc, List::default());
let worklist = List::new(mc, children);
let e2 = m.pop();
let _ = m.pop();
m.push(e2);
m.push(Value::new_gc(seen));
m.push(Value::new_gc(worklist));
m.push(Value::new_inline(count));
m.push(Value::new(seen));
m.push(Value::new(worklist));
m.push(Value::new(count));
reader.set_pc(Continuation::PDeepSeqPush.ip() as usize);
Step::Continue(())
}
@@ -89,7 +89,7 @@ pub fn deep_seq_push<'gc, M: Machine<'gc>>(
) -> Step {
// stack: [e2, seen, worklist, counter]
#[allow(clippy::unwrap_used)]
let counter = m.peek(0).as_inline::<i32>().unwrap();
let counter = m.peek(0).downcast::<i32>().unwrap();
if counter == 0 {
let _ = m.pop(); // counter
let _ = m.pop(); // worklist
@@ -99,10 +99,10 @@ pub fn deep_seq_push<'gc, M: Machine<'gc>>(
}
#[allow(clippy::unwrap_used)]
let worklist = m.peek_forced(1).as_gc::<List<'gc>>().unwrap();
let worklist = m.peek_forced(1).downcast::<List>().unwrap();
#[allow(clippy::unwrap_used)]
let item = worklist.unlock(mc).borrow_mut().pop().unwrap();
m.replace(0, Value::new_inline(counter - 1));
m.replace(0, Value::new(counter - 1));
m.push(item);
// force item at TOS, resume at DeepSeqLoop after force
@@ -119,17 +119,17 @@ pub fn deep_seq_loop<'gc, M: Machine<'gc>>(
// stack after pop: [e2, seen, worklist, counter]
let item = m.pop();
#[allow(clippy::unwrap_used)]
let counter = m.peek(0).as_inline::<i32>().unwrap();
let counter = m.peek(0).downcast::<i32>().unwrap();
let mut added: usize = 0;
if let Some(attrs) = item.as_gc::<AttrSet>() {
if let Some(attrs) = item.downcast::<AttrSet>() {
let attrs = &attrs.entries;
#[allow(clippy::unwrap_used)]
let seen = m.peek_forced(2).as_gc::<List<'gc>>().unwrap();
let seen = m.peek_forced(2).downcast::<List>().unwrap();
if !is_value_in_seen(seen, item) {
add_value_to_seen(seen, mc, item);
#[allow(clippy::unwrap_used)]
let worklist = m.peek_forced(1).as_gc::<List<'gc>>().unwrap();
let worklist = m.peek_forced(1).downcast::<List>().unwrap();
{
let mut wl = worklist.unlock(mc).borrow_mut();
for &(_, v) in attrs.iter() {
@@ -138,13 +138,13 @@ pub fn deep_seq_loop<'gc, M: Machine<'gc>>(
added = attrs.len();
}
}
} else if let Some(list) = item.as_gc::<List<'gc>>() {
} else if let Some(list) = item.downcast::<List>() {
#[allow(clippy::unwrap_used)]
let seen = m.peek_forced(2).as_gc::<List<'gc>>().unwrap();
let seen = m.peek_forced(2).downcast::<List>().unwrap();
if !is_value_in_seen(seen, item) {
add_value_to_seen(seen, mc, item);
#[allow(clippy::unwrap_used)]
let worklist = m.peek_forced(1).as_gc::<List<'gc>>().unwrap();
let worklist = m.peek_forced(1).downcast::<List>().unwrap();
{
let inner = list.inner.borrow();
let mut wl = worklist.unlock(mc).borrow_mut();
@@ -156,7 +156,7 @@ pub fn deep_seq_loop<'gc, M: Machine<'gc>>(
}
}
m.replace(0, Value::new_inline(counter + added as i32));
m.replace(0, Value::new(counter + added as i32));
reader.set_pc(Continuation::PDeepSeqPush.ip() as usize);
Step::Continue(())
}
@@ -170,10 +170,10 @@ pub fn force_result_shallow<'gc, M: Machine<'gc>>(
m.force_slot(0, reader, mc)?;
let val = m.peek_forced(0);
let (count, has_children) = if let Some(attrs) = val.as_gc::<AttrSet>() {
let (count, has_children) = if let Some(attrs) = val.downcast::<AttrSet>() {
let len = attrs.entries.len();
(len, len > 0)
} else if let Some(list) = val.as_gc::<List<'gc>>() {
} else if let Some(list) = val.downcast::<List>() {
let len = list.inner.borrow().len();
(len, len > 0)
} else {
@@ -185,8 +185,8 @@ pub fn force_result_shallow<'gc, M: Machine<'gc>>(
return m.finish_ok(ctx.convert_value(val));
}
m.push(Value::new_inline(0i32));
m.push(Value::new_inline(count as i32));
m.push(Value::new(0i32));
m.push(Value::new(count as i32));
reader.set_pc(Continuation::ForceResultShallowPush.ip() as usize);
Step::Continue(())
}
@@ -198,9 +198,9 @@ pub fn force_result_shallow_push<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
#[allow(clippy::unwrap_used)]
let idx = m.peek(1).as_inline::<i32>().unwrap();
let idx = m.peek(1).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let len = m.peek(0).as_inline::<i32>().unwrap();
let len = m.peek(0).downcast::<i32>().unwrap();
if idx == len {
let _ = m.pop(); // len
@@ -210,16 +210,16 @@ pub fn force_result_shallow_push<'gc, M: Machine<'gc>>(
}
let val = m.peek_forced(2);
let child = if let Some(attrs) = val.as_gc::<AttrSet>() {
let child = if let Some(attrs) = val.downcast::<AttrSet>() {
attrs.entries.get(idx as usize).map(|&(_, v)| v)
} else if let Some(list) = val.as_gc::<List<'gc>>() {
} else if let Some(list) = val.downcast::<List>() {
list.inner.borrow().get(idx as usize).copied()
} else {
None
};
if let Some(child) = child {
m.replace(1, Value::new_inline(idx + 1));
m.replace(1, Value::new(idx + 1));
m.push(child);
m.force_slot_to_pc(
0,
@@ -349,7 +349,7 @@ pub fn call_pattern<'gc, M: Machine<'gc>>(
let new_env = Gc::new(
mc,
RefLock::new(Env::with_arg(Value::new_gc(attrset), n_locals, env)),
RefLock::new(Env::with_arg(Value::new(attrset), n_locals, env)),
);
reader.set_pc(ip as usize);
m.set_env(new_env);
+3 -3
View File
@@ -16,8 +16,8 @@ pub fn to_string<'gc, M: Machine<'gc>>(
if val.is::<StringId>() || val.is::<NixString>() {
return m.return_from_primop(val.relax(), reader);
}
if let Some(p) = val.as_inline::<Path>() {
return m.return_from_primop(Value::new_inline(p.0), reader);
if let Some(p) = val.downcast::<Path>() {
return m.return_from_primop(Value::new(p.0), reader);
}
// TODO: derivations / `__toString` / `outPath`,
// numbers, lists.
@@ -47,5 +47,5 @@ pub fn type_of<'gc, M: Machine<'gc>>(
NixType::Thunk => unreachable!("forced"),
};
let sid = ctx.intern_string(name);
m.return_from_primop(Value::new_inline(sid), reader)
m.return_from_primop(Value::new(sid), reader)
}
+23 -20
View File
@@ -17,11 +17,11 @@ pub fn start_eq<'gc, M: Machine<'gc>>(
) -> Step {
match shallow_eq(ctx, lhs, rhs) {
ShallowEq::True => {
m.push(Value::new_inline(!negate));
m.push(Value::new(!negate));
Step::Continue(())
}
ShallowEq::False => {
m.push(Value::new_inline(negate));
m.push(Value::new(negate));
Step::Continue(())
}
ShallowEq::RecurseList(la, lb) => {
@@ -44,15 +44,15 @@ pub fn eq_step<'gc, M: Machine<'gc>>(
) -> Step {
let rhs_q = m
.peek(0)
.as_gc::<List<'gc>>()
.downcast::<List>()
.expect("eq state corrupted: rhs_queue");
let lhs_q = m
.peek(1)
.as_gc::<List<'gc>>()
.downcast::<List>()
.expect("eq state corrupted: lhs_queue");
let result = m
.peek(2)
.as_inline::<bool>()
.downcast::<bool>()
.expect("eq state corrupted: result");
if !result || lhs_q.inner.borrow().is_empty() {
@@ -92,13 +92,13 @@ fn finalize<'gc, M: Machine<'gc>>(m: &mut M, reader: &mut BytecodeReader<'_>) ->
let _ = m.pop();
let result = m
.pop()
.as_inline::<bool>()
.downcast::<bool>()
.expect("eq state corrupted: result");
let negate = m
.pop()
.as_inline::<bool>()
.downcast::<bool>()
.expect("eq state corrupted: negate");
m.return_from_primop(Value::new_inline(result ^ negate), reader)
m.return_from_primop(Value::new(result ^ negate), reader)
}
fn apply_pair<'gc, M: Machine<'gc>>(
@@ -111,7 +111,7 @@ fn apply_pair<'gc, M: Machine<'gc>>(
match shallow_eq(ctx, lhs, rhs) {
ShallowEq::True => {}
ShallowEq::False => {
m.replace(2, Value::new_inline(false));
m.replace(2, Value::new(false));
}
ShallowEq::RecurseList(la, lb) => {
extend_queues(
@@ -140,11 +140,11 @@ where
{
let rhs_q = m
.peek(0)
.as_gc::<List<'gc>>()
.downcast::<List>()
.expect("eq state corrupted: rhs_queue");
let lhs_q = m
.peek(1)
.as_gc::<List<'gc>>()
.downcast::<List>()
.expect("eq state corrupted: lhs_queue");
let mut lq = lhs_q.unlock(mc).borrow_mut();
let mut rq = rhs_q.unlock(mc).borrow_mut();
@@ -169,10 +169,10 @@ fn enter_eq_machine<'gc, M: Machine<'gc>>(
env: m.env(),
});
m.inc_call_depth();
m.push(Value::new_inline(negate));
m.push(Value::new_inline(true));
m.push(Value::new_gc(List::new(mc, lhs_init)));
m.push(Value::new_gc(List::new(mc, rhs_init)));
m.push(Value::new(negate));
m.push(Value::new(true));
m.push(Value::new(List::new(mc, lhs_init)));
m.push(Value::new(List::new(mc, rhs_init)));
reader.set_pc(Continuation::EqStep.ip() as usize);
Step::Continue(())
}
@@ -189,7 +189,7 @@ fn shallow_eq<'gc>(
lhs: StrictValue<'gc>,
rhs: StrictValue<'gc>,
) -> ShallowEq<'gc> {
if let (Some(a), Some(b)) = (lhs.as_num(), rhs.as_num()) {
if let (Some(a), Some(b)) = (lhs.downcast_num(), rhs.downcast_num()) {
let eq = match (a, b) {
(NixNum::Int(a), NixNum::Int(b)) => a == b,
(NixNum::Float(a), NixNum::Float(b)) => a == b,
@@ -198,25 +198,28 @@ fn shallow_eq<'gc>(
};
return bool_outcome(eq);
}
if let (Some(a), Some(b)) = (lhs.as_inline::<bool>(), rhs.as_inline::<bool>()) {
if let (Some(a), Some(b)) = (lhs.downcast::<bool>(), rhs.downcast::<bool>()) {
return bool_outcome(a == b);
}
if lhs.is::<Null>() && rhs.is::<Null>() {
return ShallowEq::True;
}
if let (Some(a), Some(b)) = (lhs.as_inline::<Path>(), rhs.as_inline::<Path>()) {
if let (Some(a), Some(b)) = (lhs.downcast::<Path>(), rhs.downcast::<Path>()) {
return bool_outcome(a.0 == b.0);
}
if let (Some(a), Some(b)) = (ctx.get_string(lhs), ctx.get_string(rhs)) {
return bool_outcome(a == b);
}
if let (Some(a), Some(b)) = (lhs.as_gc::<List<'gc>>(), rhs.as_gc::<List<'gc>>()) {
if let (Some(a), Some(b)) = (lhs.downcast::<List>(), rhs.downcast::<List>()) {
if a.inner.borrow().len() != b.inner.borrow().len() {
return ShallowEq::False;
}
return ShallowEq::RecurseList(a, b);
}
if let (Some(a), Some(b)) = (lhs.as_gc::<AttrSet<'gc>>(), rhs.as_gc::<AttrSet<'gc>>()) {
if let (Some(a), Some(b)) = (
lhs.downcast::<AttrSet<'gc>>(),
rhs.downcast::<AttrSet<'gc>>(),
) {
let ae = &a.entries;
let be = &b.entries;
if ae.len() != be.len() {
+5 -5
View File
@@ -40,7 +40,7 @@ pub fn import<'gc, M: Machine<'gc>>(
// finalizer can use it as the cache key. The slot we pop here was
// freed by `force_and_retry`, so we simply push.
let path_sid = ctx.intern_string(abs.to_string_lossy());
m.push(Value::new_inline(path_sid));
m.push(Value::new(path_sid));
let env = m.env();
m.push_call_frame(CallFrame {
pc: Continuation::PImportFinalize.ip() as usize,
@@ -63,7 +63,7 @@ pub fn import_finalize<'gc, M: Machine<'gc>>(
// stack: [path_sid, return_value]
let val = m.pop();
#[allow(clippy::unwrap_used)]
let path_sid = m.pop().as_inline::<StringId>().unwrap();
let path_sid = m.pop().downcast::<StringId>().unwrap();
// The cache key is keyed by the absolute path string we interned in
// `import`. Resolve it back to the host PathBuf.
let path_str = ctx.resolve_string(path_sid).to_owned();
@@ -107,7 +107,7 @@ pub fn scoped_import<'gc, M: Machine<'gc>>(
};
let keys: HashSet<StringId> = scope_attrs.entries.iter().map(|&(k, _)| k).collect();
let slot_id = m.scope_slots_push(Value::new_gc(scope_attrs));
let slot_id = m.scope_slots_push(Value::new(scope_attrs));
let env = m.env();
m.push_call_frame(CallFrame {
@@ -146,7 +146,7 @@ pub fn path_exists<'gc, M: Machine<'gc>>(
let path_val = m.force_and_retry::<StrictValue>(reader, mc)?;
// pathExists requires an absolute path. A `Path` value is
// always absolute; a string is accepted only if it starts with `/`.
let (path, is_path_value) = if let Some(p) = path_val.as_inline::<Path>() {
let (path, is_path_value) = if let Some(p) = path_val.downcast::<Path>() {
(ctx.resolve_string(p.0).to_owned(), true)
} else if let Some(s) = ctx.get_string(path_val) {
(s.to_owned(), false)
@@ -171,7 +171,7 @@ pub fn path_exists<'gc, M: Machine<'gc>>(
} else {
std::fs::symlink_metadata(p).is_ok()
};
m.return_from_primop(Value::new_inline(exists), reader)
m.return_from_primop(Value::new(exists), reader)
}
/// Convert the user-supplied path string into an absolute, dotted-segment
+40 -35
View File
@@ -8,7 +8,7 @@ pub fn filter_force_list<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
m.force_slot(0, reader, mc)?;
let list = match m.peek_forced(0).expect_gc::<List>() {
let list = match m.peek_forced(0).expect::<List>() {
Ok(list) => list,
Err(got) => return m.finish_type_err(NixType::List, got),
};
@@ -18,8 +18,8 @@ pub fn filter_force_list<'gc, M: Machine<'gc>>(
return m.return_from_primop(val, reader);
}
// prepare stack layout: [ pred list idx acc ]
m.push(Value::new_inline(0));
m.push(Value::new_gc(List::new_gc(mc)));
m.push(Value::new(0));
m.push(Value::new(List::new_gc(mc)));
reader.set_pc(Continuation::PFilterCallPred.ip() as usize);
Step::Continue(())
}
@@ -32,9 +32,9 @@ pub fn filter_call_pred<'gc, M: Machine<'gc>>(
m.force_slot(3, reader, mc)?;
let pred = m.peek_forced(3);
#[allow(clippy::unwrap_used)]
let idx = m.peek(1).as_inline::<i32>().unwrap();
let idx = m.peek(1).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let elem = m.peek_forced(2).as_gc::<List>().unwrap().inner.borrow()[idx as usize];
let elem = m.peek_forced(2).downcast::<List>().unwrap().inner.borrow()[idx as usize];
m.push(pred.relax());
m.call(reader, mc, elem, Continuation::PFilterCheck.ip() as usize)
}
@@ -46,12 +46,12 @@ pub fn filter_check<'gc, M: Machine<'gc>>(
) -> Step {
let ret = m.force_and_retry::<bool>(reader, mc)?;
#[allow(clippy::unwrap_used)]
let idx = m.peek(1).as_inline::<i32>().unwrap();
let idx = m.peek(1).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let list = m.peek_forced(2).as_gc::<List>().unwrap();
let list = m.peek_forced(2).downcast::<List>().unwrap();
let list = list.inner.borrow();
#[allow(clippy::unwrap_used)]
let acc = m.peek_forced(0).as_gc::<List>().unwrap();
let acc = m.peek_forced(0).downcast::<List>().unwrap();
if ret {
let mut acc = acc.unlock(mc).borrow_mut();
acc.push(list[idx as usize]);
@@ -63,7 +63,7 @@ pub fn filter_check<'gc, M: Machine<'gc>>(
let _ = m.pop(); // pred
return m.return_from_primop(acc, reader);
}
m.replace(1, Value::new_inline(idx + 1));
m.replace(1, Value::new(idx + 1));
reader.set_pc(Continuation::PFilterCallPred.ip() as usize);
Step::Continue(())
}
@@ -83,7 +83,7 @@ pub fn foldl_strict_entry<'gc, M: Machine<'gc>>(
) -> Step {
m.force_slot(0, reader, mc)?;
let list_val = m.peek_forced(0);
let Some(list) = list_val.as_gc::<List>() else {
let Some(list) = list_val.downcast::<List>() else {
return m.finish_type_err(NixType::List, list_val.ty());
};
if list.inner.borrow().is_empty() {
@@ -94,7 +94,7 @@ pub fn foldl_strict_entry<'gc, M: Machine<'gc>>(
let list_val = m.pop();
let nul_val = m.pop();
m.push(list_val);
m.push(Value::new_inline(0i32));
m.push(Value::new(0i32));
m.push(nul_val);
reader.set_pc(Continuation::PFoldlStrictCall1.ip() as usize);
Step::Continue(())
@@ -119,7 +119,12 @@ pub fn foldl_strict_call1<'gc, M: Machine<'gc>>(
let op = m.peek_forced(3);
let acc = m.peek(0);
m.push(op.relax());
m.call(reader, mc, acc, Continuation::PFoldlStrictCall2.ip() as usize)
m.call(
reader,
mc,
acc,
Continuation::PFoldlStrictCall2.ip() as usize,
)
}
pub fn foldl_strict_call2<'gc, M: Machine<'gc>>(
@@ -128,9 +133,9 @@ pub fn foldl_strict_call2<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
#[allow(clippy::unwrap_used)]
let idx = m.peek(2).as_inline::<i32>().unwrap();
let idx = m.peek(2).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let list = m.peek_forced(3).as_gc::<List>().unwrap();
let list = m.peek_forced(3).downcast::<List>().unwrap();
let elem = list.inner.borrow()[idx as usize];
m.call(
reader,
@@ -148,9 +153,9 @@ pub fn foldl_strict_update<'gc, M: Machine<'gc>>(
let result = m.pop();
m.replace(0, result);
#[allow(clippy::unwrap_used)]
let idx = m.peek(1).as_inline::<i32>().unwrap();
let idx = m.peek(1).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let list = m.peek_forced(2).as_gc::<List>().unwrap();
let list = m.peek_forced(2).downcast::<List>().unwrap();
let len = list.inner.borrow().len();
if (idx as usize) + 1 == len {
let acc = m.pop();
@@ -159,7 +164,7 @@ pub fn foldl_strict_update<'gc, M: Machine<'gc>>(
let _ = m.pop(); // op
return m.return_from_primop(acc, reader);
}
m.replace(1, Value::new_inline(idx + 1));
m.replace(1, Value::new(idx + 1));
reader.set_pc(Continuation::PFoldlStrictCall1.ip() as usize);
Step::Continue(())
}
@@ -170,7 +175,7 @@ pub fn all_entry<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
m.force_slot(0, reader, mc)?;
let list = match m.peek_forced(0).expect_gc::<List>() {
let list = match m.peek_forced(0).expect::<List>() {
Ok(list) => list,
Err(got) => return m.finish_type_err(NixType::List, got),
};
@@ -179,10 +184,10 @@ pub fn all_entry<'gc, M: Machine<'gc>>(
if list.inner.borrow().is_empty() {
let _list = m.pop();
let _pred = m.pop();
return m.return_from_primop(Value::new_inline(true), reader);
return m.return_from_primop(Value::new(true), reader);
}
// prepare stack layout: [ pred list idx ]
m.push(Value::new_inline(0));
m.push(Value::new(0));
reader.set_pc(Continuation::PAllCallPred.ip() as usize);
Step::Continue(())
}
@@ -194,9 +199,9 @@ pub fn all_call_pred<'gc, M: Machine<'gc>>(
) -> Step {
let pred = m.peek_forced(2);
#[allow(clippy::unwrap_used)]
let idx = m.peek(0).as_inline::<i32>().unwrap();
let idx = m.peek(0).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let elem = m.peek_forced(1).as_gc::<List>().unwrap().inner.borrow()[idx as usize];
let elem = m.peek_forced(1).downcast::<List>().unwrap().inner.borrow()[idx as usize];
m.push(pred.relax());
m.call(reader, mc, elem, Continuation::PAllCheck.ip() as usize)
}
@@ -208,17 +213,17 @@ pub fn all_check<'gc, M: Machine<'gc>>(
) -> Step {
let ret = m.force_and_retry::<bool>(reader, mc)?;
#[allow(clippy::unwrap_used)]
let idx = m.peek(0).as_inline::<i32>().unwrap();
let idx = m.peek(0).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let list = m.peek_forced(1).as_gc::<List>().unwrap();
let list = m.peek_forced(1).downcast::<List>().unwrap();
let list = list.inner.borrow();
if idx as usize == list.len() - 1 || !ret {
let _ = m.pop(); // idx
let _ = m.pop(); // list
let _ = m.pop(); // pred
return m.return_from_primop(Value::new_inline(ret), reader);
return m.return_from_primop(Value::new(ret), reader);
}
m.replace(0, Value::new_inline(idx + 1));
m.replace(0, Value::new(idx + 1));
reader.set_pc(Continuation::PAllCallPred.ip() as usize);
Step::Continue(())
}
@@ -229,7 +234,7 @@ pub fn any_entry<'gc, M: Machine<'gc>>(
mc: &Mutation<'gc>,
) -> Step {
m.force_slot(0, reader, mc)?;
let list = match m.peek_forced(0).expect_gc::<List>() {
let list = match m.peek_forced(0).expect::<List>() {
Ok(list) => list,
Err(got) => return m.finish_type_err(NixType::List, got),
};
@@ -238,10 +243,10 @@ pub fn any_entry<'gc, M: Machine<'gc>>(
if list.inner.borrow().is_empty() {
let _list = m.pop();
let _pred = m.pop();
return m.return_from_primop(Value::new_inline(false), reader);
return m.return_from_primop(Value::new(false), reader);
}
// prepare stack layout: [ pred list idx ]
m.push(Value::new_inline(0));
m.push(Value::new(0));
reader.set_pc(Continuation::PAnyCallPred.ip() as usize);
Step::Continue(())
}
@@ -253,9 +258,9 @@ pub fn any_call_pred<'gc, M: Machine<'gc>>(
) -> Step {
let pred = m.peek_forced(2);
#[allow(clippy::unwrap_used)]
let idx = m.peek(0).as_inline::<i32>().unwrap();
let idx = m.peek(0).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let elem = m.peek_forced(1).as_gc::<List>().unwrap().inner.borrow()[idx as usize];
let elem = m.peek_forced(1).downcast::<List>().unwrap().inner.borrow()[idx as usize];
m.push(pred.relax());
m.call(reader, mc, elem, Continuation::PAnyCheck.ip() as usize)
}
@@ -267,17 +272,17 @@ pub fn any_check<'gc, M: Machine<'gc>>(
) -> Step {
let ret = m.force_and_retry::<bool>(reader, mc)?;
#[allow(clippy::unwrap_used)]
let idx = m.peek(0).as_inline::<i32>().unwrap();
let idx = m.peek(0).downcast::<i32>().unwrap();
#[allow(clippy::unwrap_used)]
let list = m.peek_forced(1).as_gc::<List>().unwrap();
let list = m.peek_forced(1).downcast::<List>().unwrap();
let list = list.inner.borrow();
if idx as usize == list.len() - 1 || ret {
let _ = m.pop(); // idx
let _ = m.pop(); // list
let _ = m.pop(); // pred
return m.return_from_primop(Value::new_inline(ret), reader);
return m.return_from_primop(Value::new(ret), reader);
}
m.replace(0, Value::new_inline(idx + 1));
m.replace(0, Value::new(idx + 1));
reader.set_pc(Continuation::PAnyCallPred.ip() as usize);
Step::Continue(())
}
+4 -4
View File
@@ -13,8 +13,8 @@ pub fn to_path<'gc, M: Machine<'gc>>(
) -> Step {
// coerce to path THEN TO STRING
let val = m.force_and_retry::<StrictValue>(reader, mc)?;
if let Some(Path(s)) = val.as_inline::<Path>() {
return m.return_from_primop(Value::new_inline(s), reader);
if let Some(Path(s)) = val.downcast::<Path>() {
return m.return_from_primop(Value::new(s), reader);
}
let Some(s) = ctx.get_string(val) else {
return m.finish_err(Error::eval_error(format!(
@@ -29,7 +29,7 @@ pub fn to_path<'gc, M: Machine<'gc>>(
}
let canon = canon_path_str(s);
let sid = ctx.intern_string(canon);
m.return_from_primop(Value::new_inline(sid), reader)
m.return_from_primop(Value::new(sid), reader)
}
pub fn is_path<'gc, M: Machine<'gc>>(
@@ -39,5 +39,5 @@ pub fn is_path<'gc, M: Machine<'gc>>(
) -> Step {
let val = m.force_and_retry::<StrictValue>(reader, mc)?;
let is_path = val.is::<Path>();
m.return_from_primop(Value::new_inline(is_path), reader)
m.return_from_primop(Value::new(is_path), reader)
}