🚀 Major LLVM breakthrough by ChatGPT5\!
PHI type coercion and core-first routing fixes: - Auto type conversion for PHI nodes (i64↔i8*↔i1↔f64) - Fixed ArrayBox.get misrouting to Map path - Core-first strategy for Array/Map creation - Added comprehensive debug logging ([PHI], [ARR], [MAP]) Results: ✅ Array smoke test: 'Result: 3' ✅ Map smoke test: 'Map: v=42, size=1' After 34+ minutes of battling Rust lifetime errors, ChatGPT5 achieved a major breakthrough\! Key insight: The bug wasn't in PHI/SSA logic but in Box type routing - ArrayBox.get was incorrectly caught by Map fallback due to missing annotations. We're SO CLOSE to Nyash self-hosting paradise\! 🌟 Once this stabilizes, everything can be written in simple, beautiful Nyash code instead of Rust complexity.
This commit is contained in:
@ -153,6 +153,15 @@ pub extern "C" fn nyash_env_box_new(type_name: *const i8) -> i64 {
|
||||
let arc: std::sync::Arc<dyn NyashBox> = std::sync::Arc::new(MapBox::new());
|
||||
return handles::to_handle(arc) as i64;
|
||||
}
|
||||
if ty == "ArrayBox" {
|
||||
use nyash_rust::boxes::array::ArrayBox;
|
||||
let arc: std::sync::Arc<dyn NyashBox> = std::sync::Arc::new(ArrayBox::new());
|
||||
let h = handles::to_handle(arc) as i64;
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("nyrt: env.box.new ArrayBox -> handle={}", h);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
let reg = get_global_registry();
|
||||
match reg.create_box(ty, &[]) {
|
||||
Ok(b) => {
|
||||
|
||||
@ -3,6 +3,9 @@
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nyash_array_get_h(handle: i64, idx: i64) -> i64 {
|
||||
use nyash_rust::{box_trait::IntegerBox, jit::rt::handles};
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[ARR] get_h(handle={}, idx={})", handle, idx);
|
||||
}
|
||||
if handle <= 0 || idx < 0 {
|
||||
return 0;
|
||||
}
|
||||
@ -13,6 +16,9 @@ pub extern "C" fn nyash_array_get_h(handle: i64, idx: i64) -> i64 {
|
||||
{
|
||||
let val = arr.get(Box::new(IntegerBox::new(idx)));
|
||||
if let Some(ib) = val.as_any().downcast_ref::<IntegerBox>() {
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[ARR] get_h => {}", ib.value);
|
||||
}
|
||||
return ib.value;
|
||||
}
|
||||
}
|
||||
@ -24,6 +30,9 @@ pub extern "C" fn nyash_array_get_h(handle: i64, idx: i64) -> i64 {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nyash_array_set_h(handle: i64, idx: i64, val: i64) -> i64 {
|
||||
use nyash_rust::{box_trait::IntegerBox, jit::rt::handles};
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[ARR] set_h(handle={}, idx={}, val={})", handle, idx, val);
|
||||
}
|
||||
if handle <= 0 || idx < 0 {
|
||||
return 0;
|
||||
}
|
||||
@ -44,6 +53,9 @@ pub extern "C" fn nyash_array_set_h(handle: i64, idx: i64, val: i64) -> i64 {
|
||||
} else {
|
||||
// Do nothing for gaps (keep behavior conservative)
|
||||
}
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[ARR] set_h done; size now {}", arr.len());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -57,6 +69,9 @@ pub extern "C" fn nyash_array_push_h(handle: i64, val: i64) -> i64 {
|
||||
box_trait::{IntegerBox, NyashBox},
|
||||
jit::rt::handles,
|
||||
};
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[ARR] push_h(handle={}, val={})", handle, val);
|
||||
}
|
||||
if handle <= 0 {
|
||||
return 0;
|
||||
}
|
||||
@ -76,7 +91,11 @@ pub extern "C" fn nyash_array_push_h(handle: i64, val: i64) -> i64 {
|
||||
Box::new(IntegerBox::new(val))
|
||||
};
|
||||
let _ = arr.push(vbox);
|
||||
return arr.len() as i64;
|
||||
let len = arr.len() as i64;
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[ARR] push_h -> len {}", len);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
}
|
||||
0
|
||||
|
||||
@ -4,6 +4,9 @@
|
||||
#[export_name = "nyash.map.size_h"]
|
||||
pub extern "C" fn nyash_map_size_h(handle: i64) -> i64 {
|
||||
use nyash_rust::jit::rt::handles;
|
||||
if std::env::var("NYASH_LLVM_MAP_DEBUG").ok().as_deref() == Some("1") {
|
||||
eprintln!("[MAP] size_h(handle={})", handle);
|
||||
}
|
||||
if handle <= 0 {
|
||||
return 0;
|
||||
}
|
||||
@ -17,6 +20,9 @@ pub extern "C" fn nyash_map_size_h(handle: i64) -> i64 {
|
||||
.as_any()
|
||||
.downcast_ref::<nyash_rust::box_trait::IntegerBox>()
|
||||
{
|
||||
if std::env::var("NYASH_LLVM_MAP_DEBUG").ok().as_deref() == Some("1") {
|
||||
eprintln!("[MAP] size_h => {}", ib.value);
|
||||
}
|
||||
return ib.value;
|
||||
}
|
||||
}
|
||||
@ -31,6 +37,9 @@ pub extern "C" fn nyash_map_get_h(handle: i64, key: i64) -> i64 {
|
||||
box_trait::{IntegerBox, NyashBox},
|
||||
jit::rt::handles,
|
||||
};
|
||||
if std::env::var("NYASH_LLVM_MAP_DEBUG").ok().as_deref() == Some("1") {
|
||||
eprintln!("[MAP] get_h(handle={}, key={})", handle, key);
|
||||
}
|
||||
if handle <= 0 {
|
||||
return 0;
|
||||
}
|
||||
@ -43,6 +52,9 @@ pub extern "C" fn nyash_map_get_h(handle: i64, key: i64) -> i64 {
|
||||
let v = map.get(kbox);
|
||||
let arc: std::sync::Arc<dyn NyashBox> = std::sync::Arc::from(v);
|
||||
let h = handles::to_handle(arc);
|
||||
if std::env::var("NYASH_LLVM_MAP_DEBUG").ok().as_deref() == Some("1") {
|
||||
eprintln!("[MAP] get_h => handle {}", h);
|
||||
}
|
||||
return h as i64;
|
||||
}
|
||||
}
|
||||
@ -77,6 +89,9 @@ pub extern "C" fn nyash_map_set_h(handle: i64, key: i64, val: i64) -> i64 {
|
||||
box_trait::{IntegerBox, NyashBox},
|
||||
jit::rt::handles,
|
||||
};
|
||||
if std::env::var("NYASH_LLVM_MAP_DEBUG").ok().as_deref() == Some("1") {
|
||||
eprintln!("[MAP] set_h(handle={}, key={}, val={})", handle, key, val);
|
||||
}
|
||||
if handle <= 0 {
|
||||
return 0;
|
||||
}
|
||||
@ -96,6 +111,15 @@ pub extern "C" fn nyash_map_set_h(handle: i64, key: i64, val: i64) -> i64 {
|
||||
Box::new(IntegerBox::new(val))
|
||||
};
|
||||
let _ = map.set(kbox, vbox);
|
||||
if std::env::var("NYASH_LLVM_MAP_DEBUG").ok().as_deref() == Some("1") {
|
||||
let sz = map
|
||||
.size()
|
||||
.as_any()
|
||||
.downcast_ref::<nyash_rust::box_trait::IntegerBox>()
|
||||
.map(|i| i.value)
|
||||
.unwrap_or(-1);
|
||||
eprintln!("[MAP] set_h done; size now {}", sz);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user