94 lines
2.3 KiB
Rust
94 lines
2.3 KiB
Rust
use fix_runtime::Machine;
|
|
use gc_arena::{Gc, Mutation, RefLock};
|
|
|
|
use crate::{BytecodeReader, Step, ThunkState, Value};
|
|
|
|
#[inline(always)]
|
|
pub(crate) fn op_make_thunk<'gc, M: Machine<'gc>>(
|
|
m: &mut M,
|
|
reader: &mut BytecodeReader<'_>,
|
|
mc: &Mutation<'gc>,
|
|
) -> Step {
|
|
let entry_point = reader.read_u32();
|
|
let thunk = Gc::new(
|
|
mc,
|
|
RefLock::new(ThunkState::Pending {
|
|
ip: entry_point as usize,
|
|
env: m.env(),
|
|
}),
|
|
);
|
|
m.push(Value::new(thunk));
|
|
Step::Continue(())
|
|
}
|
|
|
|
#[inline(always)]
|
|
pub(crate) fn op_make_closure<'gc, M: Machine<'gc>>(
|
|
m: &mut M,
|
|
reader: &mut BytecodeReader<'_>,
|
|
mc: &Mutation<'gc>,
|
|
) -> Step {
|
|
let entry_point = reader.read_u32();
|
|
let n_locals = reader.read_u32();
|
|
let closure = Gc::new(
|
|
mc,
|
|
crate::Closure {
|
|
ip: entry_point,
|
|
n_locals,
|
|
env: m.env(),
|
|
pattern: None,
|
|
},
|
|
);
|
|
m.push(Value::new(closure));
|
|
Step::Continue(())
|
|
}
|
|
|
|
#[inline(always)]
|
|
pub(crate) fn op_make_pattern_closure<'gc, M: Machine<'gc>>(
|
|
m: &mut M,
|
|
reader: &mut BytecodeReader<'_>,
|
|
mc: &Mutation<'gc>,
|
|
) -> Step {
|
|
let entry_point = reader.read_u32();
|
|
let n_locals = reader.read_u32();
|
|
let req_count = reader.read_u16() as usize;
|
|
let opt_count = reader.read_u16() as usize;
|
|
let has_ellipsis = reader.read_u8() != 0;
|
|
|
|
let mut required = smallvec::SmallVec::new();
|
|
for _ in 0..req_count {
|
|
required.push(reader.read_string_id());
|
|
}
|
|
let mut optional = smallvec::SmallVec::new();
|
|
for _ in 0..opt_count {
|
|
optional.push(reader.read_string_id());
|
|
}
|
|
let total = req_count + opt_count;
|
|
let mut param_spans = Vec::with_capacity(total);
|
|
for _ in 0..total {
|
|
let name = reader.read_string_id();
|
|
let span_id = reader.read_u32();
|
|
param_spans.push((name, span_id));
|
|
}
|
|
|
|
let pattern = Gc::new(
|
|
mc,
|
|
crate::PatternInfo {
|
|
required,
|
|
optional,
|
|
ellipsis: has_ellipsis,
|
|
param_spans: param_spans.into_boxed_slice(),
|
|
},
|
|
);
|
|
let closure = Gc::new(
|
|
mc,
|
|
crate::Closure {
|
|
ip: entry_point,
|
|
n_locals,
|
|
env: m.env(),
|
|
pattern: Some(pattern),
|
|
},
|
|
);
|
|
m.push(Value::new(closure));
|
|
Step::Continue(())
|
|
}
|