Phase 25.1a: selfhost builder hotfix (fn rename, docs)
This commit is contained in:
@ -113,8 +113,11 @@ fn main() -> Result<()> {
|
||||
if canary_norm {
|
||||
// Read file, normalize, and write to a temp path
|
||||
let mut buf = String::new();
|
||||
File::open(&p).and_then(|mut f| f.read_to_string(&mut buf)).context("read input json")?;
|
||||
let mut val: serde_json::Value = serde_json::from_str(&buf).context("input is not valid JSON")?;
|
||||
File::open(&p)
|
||||
.and_then(|mut f| f.read_to_string(&mut buf))
|
||||
.context("read input json")?;
|
||||
let mut val: serde_json::Value =
|
||||
serde_json::from_str(&buf).context("input is not valid JSON")?;
|
||||
val = normalize_canary_json(val);
|
||||
let tmp = std::env::temp_dir().join("ny_llvmc_in.json");
|
||||
let mut f = File::create(&tmp).context("create temp json file")?;
|
||||
@ -156,7 +159,9 @@ fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
// Optional: print concise shape hint in verbose mode when not normalizing
|
||||
if env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") && env::var("HAKO_LLVM_CANARY_NORMALIZE").ok().as_deref() != Some("1") {
|
||||
if env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1")
|
||||
&& env::var("HAKO_LLVM_CANARY_NORMALIZE").ok().as_deref() != Some("1")
|
||||
{
|
||||
if let Ok(mut f) = File::open(&input_path) {
|
||||
let mut buf = String::new();
|
||||
if f.read_to_string(&mut buf).is_ok() {
|
||||
@ -255,17 +260,32 @@ fn normalize_canary_json(mut v: serde_json::Value) -> serde_json::Value {
|
||||
bm.insert("instructions".to_string(), insts);
|
||||
}
|
||||
// Normalize instructions
|
||||
if let Some(Value::Array(ref mut ins_arr)) = bm.get_mut("instructions") {
|
||||
if let Some(Value::Array(ref mut ins_arr)) =
|
||||
bm.get_mut("instructions")
|
||||
{
|
||||
for ins in ins_arr.iter_mut() {
|
||||
if let Value::Object(ref mut im) = ins {
|
||||
if im.get("op").and_then(|x| x.as_str()) == Some("const") {
|
||||
if im.get("op").and_then(|x| x.as_str())
|
||||
== Some("const")
|
||||
{
|
||||
// if 'ty' and flat 'value' exist, wrap into typed value
|
||||
if let (Some(ty), Some(val)) = (im.remove("ty"), im.remove("value")) {
|
||||
if let (Some(ty), Some(val)) =
|
||||
(im.remove("ty"), im.remove("value"))
|
||||
{
|
||||
let mut val_obj = Map::new();
|
||||
if let Value::String(ts) = ty { val_obj.insert("type".to_string(), Value::String(ts)); }
|
||||
else { val_obj.insert("type".to_string(), ty); }
|
||||
if let Value::String(ts) = ty {
|
||||
val_obj.insert(
|
||||
"type".to_string(),
|
||||
Value::String(ts),
|
||||
);
|
||||
} else {
|
||||
val_obj.insert("type".to_string(), ty);
|
||||
}
|
||||
val_obj.insert("value".to_string(), val);
|
||||
im.insert("value".to_string(), Value::Object(val_obj));
|
||||
im.insert(
|
||||
"value".to_string(),
|
||||
Value::Object(val_obj),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -325,7 +345,9 @@ fn propagate_opt_level(cmd: &mut Command) {
|
||||
let level = nyash.clone().or(hako.clone());
|
||||
if let Some(level) = level {
|
||||
if hako.is_some() && nyash.is_none() {
|
||||
eprintln!("[deprecate/env] 'HAKO_LLVM_OPT_LEVEL' is deprecated; use 'NYASH_LLVM_OPT_LEVEL'");
|
||||
eprintln!(
|
||||
"[deprecate/env] 'HAKO_LLVM_OPT_LEVEL' is deprecated; use 'NYASH_LLVM_OPT_LEVEL'"
|
||||
);
|
||||
}
|
||||
cmd.env("HAKO_LLVM_OPT_LEVEL", &level);
|
||||
cmd.env("NYASH_LLVM_OPT_LEVEL", &level);
|
||||
|
||||
@ -5,4 +5,3 @@ fn main() {
|
||||
.warnings(false)
|
||||
.compile("nyash_c_core_c");
|
||||
}
|
||||
|
||||
|
||||
@ -13,14 +13,27 @@ extern "C" {
|
||||
pub fn core_probe_invoke(target: &str, method: &str, argc: i32) -> i32 {
|
||||
let t = std::ffi::CString::new(target).unwrap_or_else(|_| std::ffi::CString::new("?").unwrap());
|
||||
let m = std::ffi::CString::new(method).unwrap_or_else(|_| std::ffi::CString::new("?").unwrap());
|
||||
unsafe { ny_core_probe_invoke(t.as_ptr() as *const u8, m.as_ptr() as *const u8, argc as c_int) as i32 }
|
||||
unsafe {
|
||||
ny_core_probe_invoke(
|
||||
t.as_ptr() as *const u8,
|
||||
m.as_ptr() as *const u8,
|
||||
argc as c_int,
|
||||
) as i32
|
||||
}
|
||||
}
|
||||
|
||||
/// MapBox.set stub (design-stage): returns 0 on success
|
||||
pub fn core_map_set(type_id: i32, instance_id: u32, key: &str, val: &str) -> i32 {
|
||||
let k = std::ffi::CString::new(key).unwrap_or_else(|_| std::ffi::CString::new("").unwrap());
|
||||
let v = std::ffi::CString::new(val).unwrap_or_else(|_| std::ffi::CString::new("").unwrap());
|
||||
unsafe { ny_core_map_set(type_id as i32, instance_id as u32, k.as_ptr() as *const u8, v.as_ptr() as *const u8) as i32 }
|
||||
unsafe {
|
||||
ny_core_map_set(
|
||||
type_id as i32,
|
||||
instance_id as u32,
|
||||
k.as_ptr() as *const u8,
|
||||
v.as_ptr() as *const u8,
|
||||
) as i32
|
||||
}
|
||||
}
|
||||
|
||||
/// ArrayBox.push stub (design-stage): returns 0 on success
|
||||
|
||||
@ -82,11 +82,17 @@ pub extern "C" fn nyash_string_charcode_at_h_export(handle: i64, idx: i64) -> i6
|
||||
// Exported as: nyash.env.argv_get() -> i64 (ArrayBox handle)
|
||||
#[export_name = "nyash.env.argv_get"]
|
||||
pub extern "C" fn nyash_env_argv_get() -> i64 {
|
||||
use nyash_rust::{box_trait::{NyashBox, StringBox}, boxes::array::ArrayBox, runtime::host_handles as handles};
|
||||
use nyash_rust::{
|
||||
box_trait::{NyashBox, StringBox},
|
||||
boxes::array::ArrayBox,
|
||||
runtime::host_handles as handles,
|
||||
};
|
||||
let mut arr = ArrayBox::new();
|
||||
// Skip argv[0] (program name), collect the rest
|
||||
for (i, a) in std::env::args().enumerate() {
|
||||
if i == 0 { continue; }
|
||||
if i == 0 {
|
||||
continue;
|
||||
}
|
||||
let sb: Box<dyn NyashBox> = Box::new(StringBox::new(a));
|
||||
let _ = arr.push(sb);
|
||||
}
|
||||
|
||||
@ -82,7 +82,10 @@ impl BoxCore for IntArrayCore {
|
||||
|
||||
impl NyashBox for IntArrayCore {
|
||||
fn to_string_box(&self) -> StringBox {
|
||||
StringBox::new(&format!("IntArrayCore(len={})", self.data.read().unwrap().len()))
|
||||
StringBox::new(&format!(
|
||||
"IntArrayCore(len={})",
|
||||
self.data.read().unwrap().len()
|
||||
))
|
||||
}
|
||||
|
||||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||||
|
||||
@ -3,10 +3,10 @@ pub mod birth;
|
||||
pub mod console;
|
||||
pub mod future;
|
||||
pub mod instance;
|
||||
pub mod intarray;
|
||||
pub mod invoke;
|
||||
pub mod invoke_core;
|
||||
pub mod map;
|
||||
pub mod intarray;
|
||||
pub mod semantics;
|
||||
pub mod string;
|
||||
|
||||
@ -15,9 +15,9 @@ pub use birth::*;
|
||||
pub use console::*;
|
||||
pub use future::*;
|
||||
pub use instance::*;
|
||||
pub use intarray::*;
|
||||
pub use invoke::*;
|
||||
pub use invoke_core::*;
|
||||
pub use map::*;
|
||||
pub use intarray::*;
|
||||
pub use semantics::*;
|
||||
pub use string::*;
|
||||
|
||||
@ -151,9 +151,11 @@ pub extern "C" fn nyash_string_length_si(s: *const i8, mode: i64) -> i64 {
|
||||
let cs = unsafe { CStr::from_ptr(s) };
|
||||
// Safe UTF-8 conversion; on failure, fall back to byte length scan
|
||||
if let Ok(st) = cs.to_str() {
|
||||
if mode == 1 { // char count
|
||||
if mode == 1 {
|
||||
// char count
|
||||
return st.chars().count() as i64;
|
||||
} else { // byte length
|
||||
} else {
|
||||
// byte length
|
||||
return st.as_bytes().len() as i64;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,4 +5,3 @@ fn main() {
|
||||
.warnings(false)
|
||||
.compile("nyash_kernel_min_c");
|
||||
}
|
||||
|
||||
|
||||
@ -1,2 +1 @@
|
||||
// Rust side is empty; the staticlib is produced from C sources via build.rs
|
||||
|
||||
|
||||
@ -10,4 +10,3 @@ fn main() {
|
||||
.flag_if_supported("-std=c99")
|
||||
.compile("nyash_tlv_c");
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,11 @@ pub fn tlv_roundtrip_identity(input: &[u8]) -> Vec<u8> {
|
||||
#[cfg(feature = "c-shim")]
|
||||
unsafe {
|
||||
let mut out_ptr: *mut c_uchar = std::ptr::null_mut();
|
||||
let sz = ny_tlv_identity(input.as_ptr(), input.len() as size_t, &mut out_ptr as *mut *mut c_uchar);
|
||||
let sz = ny_tlv_identity(
|
||||
input.as_ptr(),
|
||||
input.len() as size_t,
|
||||
&mut out_ptr as *mut *mut c_uchar,
|
||||
);
|
||||
if sz == 0 || out_ptr.is_null() {
|
||||
return Vec::new();
|
||||
}
|
||||
@ -41,4 +45,3 @@ mod tests {
|
||||
assert_eq!(out, src);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user