smokes: add curated LLVM runner; archive legacy smokes; PHI-off unified across Bridge/Builder; LLVM resolver tracing; minimal Throw lowering; config env getters; dev profile and root cleaner; docs updated; CI workflow runs curated LLVM (PHI-on/off)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::Mutex;
|
||||
use serde_json::Value as Json;
|
||||
use std::sync::Mutex;
|
||||
|
||||
const NYB_SUCCESS: i32 = 0;
|
||||
const NYB_E_INVALID_METHOD: i32 = -3;
|
||||
@ -14,10 +14,14 @@ const METHOD_FINI: u32 = u32::MAX;
|
||||
static NEXT_ID: Lazy<Mutex<u32>> = Lazy::new(|| Mutex::new(1));
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nyash_plugin_abi() -> u32 { 1 }
|
||||
pub extern "C" fn nyash_plugin_abi() -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nyash_plugin_init() -> i32 { NYB_SUCCESS }
|
||||
pub extern "C" fn nyash_plugin_init() -> i32 {
|
||||
NYB_SUCCESS
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nyash_plugin_invoke(
|
||||
@ -29,14 +33,20 @@ pub extern "C" fn nyash_plugin_invoke(
|
||||
result: *mut u8,
|
||||
result_len: *mut usize,
|
||||
) -> i32 {
|
||||
if type_id != TYPE_ID_COMPILER { return NYB_E_INVALID_METHOD; }
|
||||
if type_id != TYPE_ID_COMPILER {
|
||||
return NYB_E_INVALID_METHOD;
|
||||
}
|
||||
match method_id {
|
||||
METHOD_BIRTH => {
|
||||
unsafe {
|
||||
let mut id_g = NEXT_ID.lock().unwrap();
|
||||
let id = *id_g; *id_g += 1;
|
||||
let id = *id_g;
|
||||
*id_g += 1;
|
||||
let need = 4usize;
|
||||
if *result_len < need { *result_len = need; return NYB_E_SHORT_BUFFER; }
|
||||
if *result_len < need {
|
||||
*result_len = need;
|
||||
return NYB_E_SHORT_BUFFER;
|
||||
}
|
||||
let out = std::slice::from_raw_parts_mut(result, *result_len);
|
||||
out[0..4].copy_from_slice(&(id as u32).to_le_bytes());
|
||||
*result_len = need;
|
||||
@ -46,16 +56,20 @@ pub extern "C" fn nyash_plugin_invoke(
|
||||
METHOD_COMPILE => {
|
||||
// Decode TLV first string arg as JSON IR
|
||||
let ir = unsafe {
|
||||
if args.is_null() || args_len < 8 { None } else {
|
||||
if args.is_null() || args_len < 8 {
|
||||
None
|
||||
} else {
|
||||
let buf = std::slice::from_raw_parts(args, args_len);
|
||||
let tag = u16::from_le_bytes([buf[4], buf[5]]);
|
||||
let len = u16::from_le_bytes([buf[6], buf[7]]) as usize;
|
||||
if tag == 6 && 8 + len <= buf.len() {
|
||||
match std::str::from_utf8(&buf[8..8+len]) {
|
||||
match std::str::from_utf8(&buf[8..8 + len]) {
|
||||
Ok(s) => Some(s.to_string()),
|
||||
Err(_) => None
|
||||
Err(_) => None,
|
||||
}
|
||||
} else { None }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
let nyash_source = if let Some(s) = ir.or_else(|| std::env::var("NYASH_PY_IR").ok()) {
|
||||
@ -67,15 +81,22 @@ pub extern "C" fn nyash_plugin_invoke(
|
||||
} else if let Some(module) = map.get("module") {
|
||||
// Try module.functions[0].name and maybe return value
|
||||
let mut ret_expr = "0".to_string();
|
||||
if let Some(funcs) = module.get("functions").and_then(|v| v.as_array()) {
|
||||
if let Some(funcs) = module.get("functions").and_then(|v| v.as_array())
|
||||
{
|
||||
if let Some(fun0) = funcs.get(0) {
|
||||
if let Some(retv) = fun0.get("return_value") {
|
||||
if retv.is_number() { ret_expr = retv.to_string(); }
|
||||
else if let Some(s) = retv.as_str() { ret_expr = s.to_string(); }
|
||||
if retv.is_number() {
|
||||
ret_expr = retv.to_string();
|
||||
} else if let Some(s) = retv.as_str() {
|
||||
ret_expr = s.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
format!("static box Generated {{\n main() {{\n return {}\n }}\n}}", ret_expr)
|
||||
format!(
|
||||
"static box Generated {{\n main() {{\n return {}\n }}\n}}",
|
||||
ret_expr
|
||||
)
|
||||
} else {
|
||||
"static box Generated { main() { return 0 } }".to_string()
|
||||
}
|
||||
@ -88,11 +109,14 @@ pub extern "C" fn nyash_plugin_invoke(
|
||||
unsafe {
|
||||
let bytes = nyash_source.as_bytes();
|
||||
let need = 4 + bytes.len();
|
||||
if *result_len < need { *result_len = need; return NYB_E_SHORT_BUFFER; }
|
||||
if *result_len < need {
|
||||
*result_len = need;
|
||||
return NYB_E_SHORT_BUFFER;
|
||||
}
|
||||
let out = std::slice::from_raw_parts_mut(result, *result_len);
|
||||
out[0..2].copy_from_slice(&6u16.to_le_bytes());
|
||||
out[2..4].copy_from_slice(&(bytes.len() as u16).to_le_bytes());
|
||||
out[4..4+bytes.len()].copy_from_slice(bytes);
|
||||
out[4..4 + bytes.len()].copy_from_slice(bytes);
|
||||
*result_len = need;
|
||||
}
|
||||
NYB_SUCCESS
|
||||
|
||||
Reference in New Issue
Block a user