docs: update CURRENT_TASK with Box Theory PHI plan (defer/finalize) and MIR v0.5 type meta; add parity tooling and PyVM scaffolding
impl(pyvm/llvmlite): - add tools/parity.sh; tools/pyvm_runner.py; src/llvm_py/pyvm/* - emit string const as handle type in MIR JSON; add dst_type hints - unify '+' to concat_hh with from_i64/from_i8_string bridges; console print via to_i8p_h - add runtime bridges: nyash.box.from_i64, nyash.string.to_i8p_h tests: - add apps/tests/min_str_cat_loop (minimal repro for string cat loop)
This commit is contained in:
@ -79,7 +79,9 @@ pub extern "C" fn nyash_string_concat_hh_export(a_h: i64, b_h: i64) -> i64 {
|
||||
};
|
||||
let s = format!("{}{}", to_s(a_h), to_s(b_h));
|
||||
let arc: std::sync::Arc<dyn NyashBox> = std::sync::Arc::new(StringBox::new(s));
|
||||
handles::to_handle(arc) as i64
|
||||
let h = handles::to_handle(arc) as i64;
|
||||
eprintln!("[TRACE] concat_hh -> {}", h);
|
||||
h
|
||||
}
|
||||
|
||||
// String.eq_hh(lhs_h, rhs_h) -> i64 (0/1)
|
||||
@ -120,7 +122,9 @@ pub extern "C" fn nyash_string_substring_hii_export(h: i64, start: i64, end: i64
|
||||
let (st_u, en_u) = (st as usize, en as usize);
|
||||
let sub = s.get(st_u.min(s.len())..en_u.min(s.len())).unwrap_or("");
|
||||
let arc: std::sync::Arc<dyn NyashBox> = std::sync::Arc::new(StringBox::new(sub.to_string()));
|
||||
handles::to_handle(arc) as i64
|
||||
let nh = handles::to_handle(arc) as i64;
|
||||
eprintln!("[TRACE] substring_hii -> {}", nh);
|
||||
nh
|
||||
}
|
||||
|
||||
// String.lastIndexOf_hh(haystack_h, needle_h) -> i64
|
||||
@ -159,7 +163,9 @@ pub extern "C" fn nyash_box_from_i8_string(ptr: *const i8) -> i64 {
|
||||
Err(_) => return 0,
|
||||
};
|
||||
let arc: std::sync::Arc<dyn NyashBox> = std::sync::Arc::new(StringBox::new(s));
|
||||
handles::to_handle(arc) as i64
|
||||
let h = handles::to_handle(arc) as i64;
|
||||
eprintln!("[TRACE] from_i8_string -> {}", h);
|
||||
h
|
||||
}
|
||||
|
||||
// box.from_f64(val) -> handle
|
||||
@ -171,6 +177,15 @@ pub extern "C" fn nyash_box_from_f64(val: f64) -> i64 {
|
||||
handles::to_handle(arc) as i64
|
||||
}
|
||||
|
||||
// box.from_i64(val) -> handle
|
||||
// Helper: build an IntegerBox and return a handle
|
||||
#[export_name = "nyash.box.from_i64"]
|
||||
pub extern "C" fn nyash_box_from_i64(val: i64) -> i64 {
|
||||
use nyash_rust::{box_trait::{NyashBox, IntegerBox}, jit::rt::handles};
|
||||
let arc: std::sync::Arc<dyn NyashBox> = std::sync::Arc::new(IntegerBox::new(val));
|
||||
handles::to_handle(arc) as i64
|
||||
}
|
||||
|
||||
// env.box.new(type_name: *const i8) -> handle (i64)
|
||||
// Minimal shim for Core-13 pure AOT: constructs Box via registry by name (no args)
|
||||
#[export_name = "nyash.env.box.new"]
|
||||
|
||||
@ -83,7 +83,7 @@ pub extern "C" fn nyash_string_concat_is(a: i64, b: *const i8) -> *mut i8 {
|
||||
// Exported as: nyash.string.substring_sii(i8* s, i64 start, i64 end) -> i8*
|
||||
#[export_name = "nyash.string.substring_sii"]
|
||||
pub extern "C" fn nyash_string_substring_sii(s: *const i8, start: i64, end: i64) -> *mut i8 {
|
||||
use std::ffi::CStr;
|
||||
use std::ffi::CStr;
|
||||
if s.is_null() {
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
@ -121,3 +121,34 @@ pub extern "C" fn nyash_string_lastindexof_ss(s: *const i8, needle: *const i8) -
|
||||
pos as i64
|
||||
} else { -1 }
|
||||
}
|
||||
|
||||
// Exported as: nyash.string.to_i8p_h(i64 handle) -> i8*
|
||||
#[export_name = "nyash.string.to_i8p_h"]
|
||||
pub extern "C" fn nyash_string_to_i8p_h(handle: i64) -> *mut i8 {
|
||||
use nyash_rust::jit::rt::handles;
|
||||
if handle <= 0 {
|
||||
// return "0" for consistency with existing fallback behavior
|
||||
let s = handle.to_string();
|
||||
let mut bytes = s.into_bytes();
|
||||
bytes.push(0);
|
||||
let boxed = bytes.into_boxed_slice();
|
||||
let raw = Box::into_raw(boxed) as *mut u8;
|
||||
return raw as *mut i8;
|
||||
}
|
||||
if let Some(obj) = handles::get(handle as u64) {
|
||||
let s = obj.to_string_box().value;
|
||||
let mut bytes = s.into_bytes();
|
||||
bytes.push(0);
|
||||
let boxed = bytes.into_boxed_slice();
|
||||
let raw = Box::into_raw(boxed) as *mut u8;
|
||||
raw as *mut i8
|
||||
} else {
|
||||
// not found -> print numeric handle string
|
||||
let s = handle.to_string();
|
||||
let mut bytes = s.into_bytes();
|
||||
bytes.push(0);
|
||||
let boxed = bytes.into_boxed_slice();
|
||||
let raw = Box::into_raw(boxed) as *mut u8;
|
||||
raw as *mut i8
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user