use std::collections::HashMap;
use super::super::super::context::JITContext;
use crate::ffi::jit_kinds::*;
use crate::ffi::value_ffi::*;
#[inline(always)]
pub extern "C" fn jit_new_object(ctx: *mut JITContext, field_count: usize) -> u64 {
unsafe {
if ctx.is_null() || field_count > 64 {
return TAG_NULL;
}
let ctx_ref = &mut *ctx;
if ctx_ref.stack_ptr < field_count * 2 || ctx_ref.stack_ptr > 512 {
return TAG_NULL;
}
let mut map = HashMap::new();
for _ in 0..field_count {
ctx_ref.stack_ptr -= 1;
let value = ctx_ref.stack[ctx_ref.stack_ptr];
ctx_ref.stack_ptr -= 1;
let key_bits = ctx_ref.stack[ctx_ref.stack_ptr];
if is_heap_kind(key_bits, HK_STRING) {
let key = unbox_string(key_bits).to_string();
map.insert(key, value);
}
}
unified_box(HK_JIT_OBJECT, map)
}
}
#[inline(always)]
pub extern "C" fn jit_set_prop(obj_bits: u64, key_bits: u64, value_bits: u64) -> u64 {
unsafe {
match heap_kind(obj_bits) {
Some(HK_JIT_OBJECT) => {
if !is_heap_kind(key_bits, HK_STRING) {
return obj_bits;
}
let obj = unified_unbox_mut::<HashMap<String, u64>>(obj_bits);
let key = unbox_string(key_bits).to_string();
let old_bits = obj.get(&key).copied().unwrap_or(TAG_NULL);
super::super::gc::jit_write_barrier(old_bits, value_bits);
obj.insert(key, value_bits);
obj_bits
}
Some(HK_ARRAY) => {
let _ = (key_bits, value_bits);
todo!(
"phase-2c §2.7.4 / W10 jit-playbook §5: JitArray \
rebuild — jit_set_prop (HK_ARRAY arm). The deleted \
UnifiedArray layout blocks index/range writes; \
kinded rebuild reads Arc<TypedArrayData> per \
ADR-006 §2.7.6/Q8."
)
}
_ => obj_bits,
}
}
}
#[inline(always)]
pub extern "C" fn jit_object_rest(_obj_bits: u64, _keys_bits: u64) -> u64 {
todo!(
"phase-2c §2.7.4 / W10 jit-playbook §5: JitArray rebuild — \
jit_object_rest. The keys array walk decoded the deleted \
UnifiedArray layout; kinded rebuild reads Arc<TypedArrayData> \
of Arc<String> elements per ADR-006 §2.7.6/Q8."
)
}