This commit is contained in:
2026-06-30 18:41:42 +08:00
parent f0e3f1eeca
commit dde3052e2d
13 changed files with 79 additions and 106 deletions
-4
View File
@@ -6,11 +6,7 @@ edition = "2024"
[dependencies]
gc-arena = { workspace = true }
hashbrown = { workspace = true }
likely_stable = { workspace = true }
num_enum = { workspace = true }
smallvec = { workspace = true }
sptr = "0.3"
string-interner = { workspace = true }
sysinfo = { version = "0.38", default-features = false, features = ["system"] }
fix-bytecode = { path = "../fix-bytecode" }
+1 -2
View File
@@ -6,7 +6,6 @@ use fix_lang::{BUILTINS, BuiltinId, StringId};
use fix_runtime::{
AttrSet, Machine, MachineExt, NixString, Path, StrictValue, StringContext, canon_path_str,
};
use num_enum::TryFromPrimitive;
use crate::{BytecodeReader, PrimOp, Step, Value, VmRuntimeCtx, VmRuntimeCtxExt};
@@ -21,7 +20,7 @@ pub(crate) fn op_load_builtin<'gc, M: Machine<'gc>>(
m: &mut M,
reader: &mut BytecodeReader<'_>,
) -> Step {
let Ok(id) = BuiltinId::try_from_primitive(reader.read_u8())
let Ok(id) = BuiltinId::try_from(reader.read_u8())
.map_err(|err| panic!("unknown builtin id: {}", err.number));
m.push(Value::new_inline(PrimOp {
id,
+48 -40
View File
@@ -2,47 +2,55 @@ use fix_runtime::Machine;
use crate::{BytecodeReader, Mutation, Step, Value};
#[inline(always)]
pub(crate) fn op_load_local<'gc, M: Machine<'gc>>(m: &mut M, reader: &mut BytecodeReader<'_>) -> Step {
let idx = reader.read_u32() as usize;
m.push(m.env().borrow().locals[idx]);
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_load_local<'gc, M: Machine<'gc>>(
m: &mut M,
reader: &mut BytecodeReader<'_>,
) -> Step {
let idx = reader.read_u32() as usize;
m.push(m.env().borrow().locals[idx]);
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_load_outer<'gc, M: Machine<'gc>>(m: &mut M, reader: &mut BytecodeReader<'_>) -> Step {
let layer = reader.read_u8();
let idx = reader.read_u32() as usize;
let mut cur = m.env();
for _ in 0..layer {
let prev = cur.borrow().prev.expect("LoadOuter: env chain too short");
cur = prev;
}
let val = cur.borrow().locals[idx];
m.push(val);
Step::Continue(())
#[inline(always)]
pub(crate) fn op_load_outer<'gc, M: Machine<'gc>>(
m: &mut M,
reader: &mut BytecodeReader<'_>,
) -> Step {
let layer = reader.read_u8();
let idx = reader.read_u32() as usize;
let mut cur = m.env();
for _ in 0..layer {
let prev = cur.borrow().prev.expect("LoadOuter: env chain too short");
cur = prev;
}
let val = cur.borrow().locals[idx];
m.push(val);
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_store_local<'gc, M: Machine<'gc>>(m: &mut M,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
let idx = reader.read_u32() as usize;
let val = m.pop();
m.env().borrow_mut(mc).locals[idx] = val;
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_store_local<'gc, M: Machine<'gc>>(
m: &mut M,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
let idx = reader.read_u32() as usize;
let val = m.pop();
m.env().borrow_mut(mc).locals[idx] = val;
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_alloc_locals<'gc, M: Machine<'gc>>(m: &mut M,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
let count = reader.read_u32() as usize;
m.env()
.borrow_mut(mc)
.locals
.extend(std::iter::repeat_n(Value::default(), count));
Step::Continue(())
}
#[inline(always)]
pub(crate) fn op_alloc_locals<'gc, M: Machine<'gc>>(
m: &mut M,
reader: &mut BytecodeReader<'_>,
mc: &Mutation<'gc>,
) -> Step {
let count = reader.read_u32() as usize;
m.env()
.borrow_mut(mc)
.locals
.extend(std::iter::repeat_n(Value::default(), count));
Step::Continue(())
}
+1 -2
View File
@@ -13,7 +13,6 @@ use fix_lang::{BUILTINS, BuiltinId, StringId};
use gc_arena::metrics::Pacing;
use gc_arena::{Arena, Collect, Gc, Mutation, RefLock, Rootable};
use hashbrown::HashMap;
use num_enum::TryFromPrimitive;
use smallvec::SmallVec;
#[cfg(feature = "tailcall")]
@@ -58,7 +57,7 @@ fn init_builtins<'gc>(mc: &Mutation<'gc>, ctx: &mut impl VmRuntimeCtx) -> Value<
let mut entries = SmallVec::with_capacity(BUILTINS.len());
for (idx, &(name, arity)) in BUILTINS.iter().enumerate() {
let id = BuiltinId::try_from_primitive(idx as u8).expect("infallible");
let id = BuiltinId::try_from(idx as u8).expect("infallible");
let name = name.strip_prefix("__").unwrap_or(name);
let name = ctx.intern_string(name);
let dispatch_ip = PrimOpPhase::entry_for_builtin(id).ip();