runtime, macros: unify NaN-boxed value API under ValueVariant trait
This commit is contained in:
+15
-21
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user