llvm(py): introduce BuildCtx + trace hub; refactor if-merge prepass + PHI wiring into module; unify logs; ctx-enable compare/ret/call/boxcall/externcall/typeop/newbox/safepoint; curated smoke option for if-merge; README updates; keep behavior stable
This commit is contained in:
@ -9,16 +9,20 @@
|
||||
use crate::box_trait::NyashBox;
|
||||
|
||||
// ===== TLS: current VM pointer during plugin invoke =====
|
||||
// When legacy VM is enabled, keep a real pointer for write barriers.
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
thread_local! {
|
||||
static CURRENT_VM: std::cell::Cell<*mut crate::backend::vm::VM> = std::cell::Cell::new(std::ptr::null_mut());
|
||||
}
|
||||
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
pub fn set_current_vm(ptr: *mut crate::backend::vm::VM) {
|
||||
CURRENT_VM.with(|c| c.set(ptr));
|
||||
}
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
pub fn clear_current_vm() {
|
||||
CURRENT_VM.with(|c| c.set(std::ptr::null_mut()));
|
||||
}
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
fn with_current_vm_mut<F, R>(f: F) -> Option<R>
|
||||
where
|
||||
F: FnOnce(&mut crate::backend::vm::VM) -> R,
|
||||
@ -33,6 +37,19 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
// When legacy VM is disabled, provide stubs (no GC barriers).
|
||||
#[cfg(not(feature = "vm-legacy"))]
|
||||
pub fn set_current_vm(_ptr: *mut ()) {}
|
||||
#[cfg(not(feature = "vm-legacy"))]
|
||||
pub fn clear_current_vm() {}
|
||||
#[cfg(not(feature = "vm-legacy"))]
|
||||
fn with_current_vm_mut<F, R>(_f: F) -> Option<R>
|
||||
where
|
||||
F: FnOnce(&mut ()) -> R,
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
// ===== Utilities: TLV encode helpers (single-value) =====
|
||||
fn tlv_encode_one(val: &crate::backend::vm::VMValue) -> Vec<u8> {
|
||||
use crate::runtime::plugin_ffi_common as tlv;
|
||||
@ -201,12 +218,15 @@ pub extern "C" fn nyrt_host_call_name(
|
||||
v => v.to_string(),
|
||||
};
|
||||
// Barrier: use current VM runtime if available
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.setField",
|
||||
);
|
||||
});
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
{
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.setField",
|
||||
);
|
||||
});
|
||||
}
|
||||
// Accept primitives only for now
|
||||
let nv_opt = match argv[1].clone() {
|
||||
crate::backend::vm::VMValue::Integer(i) => {
|
||||
@ -268,12 +288,15 @@ pub extern "C" fn nyrt_host_call_name(
|
||||
crate::backend::vm::VMValue::BoxRef(b) => b.share_box(),
|
||||
_ => Box::new(crate::box_trait::VoidBox::new()),
|
||||
};
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.Array.set",
|
||||
);
|
||||
});
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
{
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.Array.set",
|
||||
);
|
||||
});
|
||||
}
|
||||
let out = arr.set(Box::new(crate::box_trait::IntegerBox::new(idx)), vb);
|
||||
let vmv = crate::backend::vm::VMValue::from_nyash_box(out);
|
||||
let buf = tlv_encode_one(&vmv);
|
||||
@ -402,12 +425,15 @@ pub extern "C" fn nyrt_host_call_slot(
|
||||
crate::backend::vm::VMValue::String(s) => s.clone(),
|
||||
v => v.to_string(),
|
||||
};
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.setField",
|
||||
);
|
||||
});
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
{
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.setField",
|
||||
);
|
||||
});
|
||||
}
|
||||
let nv_opt = match argv[1].clone() {
|
||||
crate::backend::vm::VMValue::Integer(i) => {
|
||||
Some(crate::value::NyashValue::Integer(i))
|
||||
@ -492,12 +518,15 @@ pub extern "C" fn nyrt_host_call_slot(
|
||||
crate::backend::vm::VMValue::BoxRef(b) => b.share_box(),
|
||||
_ => Box::new(crate::box_trait::VoidBox::new()),
|
||||
};
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.Array.set",
|
||||
);
|
||||
});
|
||||
#[cfg(feature = "vm-legacy")]
|
||||
{
|
||||
let _ = with_current_vm_mut(|vm| {
|
||||
crate::backend::gc_helpers::gc_write_barrier_site(
|
||||
vm.runtime_ref(),
|
||||
"HostAPI.Array.set",
|
||||
);
|
||||
});
|
||||
}
|
||||
let out = arr.set(Box::new(crate::box_trait::IntegerBox::new(idx)), vb);
|
||||
let vmv = crate::backend::vm::VMValue::from_nyash_box(out);
|
||||
let buf = tlv_encode_one(&vmv);
|
||||
|
||||
Reference in New Issue
Block a user