feat(llvm): Complete function call system implementation by ChatGPT5
Major improvements to LLVM backend function call infrastructure: ## Key Changes ### Function Call System Complete - All MIR functions now properly lowered to LLVM (not just entry) - Function parameter binding to LLVM arguments implemented - ny_main() wrapper added for proper entry point handling - Callee resolution from ValueId to function symbols working ### Call Instruction Analysis - MirInstruction::Call was implemented but system was incomplete - Fixed "rhs missing" errors caused by undefined Call return values - Function calls now properly return values through the system ### Code Modularization (Ongoing) - BoxCall → instructions/boxcall.rs ✓ - ExternCall → instructions/externcall.rs ✓ - Call remains in mod.rs (to be refactored) ### Phase 21 Documentation - Added comprehensive AI evaluation from Gemini and Codex - Both AIs confirm academic paper potential for self-parsing AST DB approach - "Code as Database" concept validated as novel contribution Co-authored-by: ChatGPT5 <noreply@openai.com> 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -79,3 +79,45 @@ pub extern "C" fn nyash_string_concat_is(a: i64, b: *const i8) -> *mut i8 {
|
||||
let raw = Box::into_raw(boxed) as *mut u8;
|
||||
raw as *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;
|
||||
if s.is_null() {
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
let src = unsafe { CStr::from_ptr(s) };
|
||||
let src = match src.to_str() {
|
||||
Ok(v) => v,
|
||||
Err(_) => return std::ptr::null_mut(),
|
||||
};
|
||||
let n = src.len() as i64;
|
||||
let mut st = if start < 0 { 0 } else { start };
|
||||
let mut en = if end < 0 { 0 } else { end };
|
||||
if st > n { st = n; }
|
||||
if en > n { en = n; }
|
||||
if en < st { std::mem::swap(&mut st, &mut en); }
|
||||
let (st_u, en_u) = (st as usize, en as usize);
|
||||
let sub = &src[st_u.min(src.len())..en_u.min(src.len())];
|
||||
let mut bytes = sub.as_bytes().to_vec();
|
||||
bytes.push(0);
|
||||
let boxed = bytes.into_boxed_slice();
|
||||
let raw = Box::into_raw(boxed) as *mut u8;
|
||||
raw as *mut i8
|
||||
}
|
||||
|
||||
// Exported as: nyash.string.lastIndexOf_ss(i8* s, i8* needle) -> i64
|
||||
#[export_name = "nyash.string.lastIndexOf_ss"]
|
||||
pub extern "C" fn nyash_string_lastindexof_ss(s: *const i8, needle: *const i8) -> i64 {
|
||||
use std::ffi::CStr;
|
||||
if s.is_null() || needle.is_null() { return -1; }
|
||||
let hs = unsafe { CStr::from_ptr(s) };
|
||||
let ns = unsafe { CStr::from_ptr(needle) };
|
||||
let h = match hs.to_str() { Ok(v) => v, Err(_) => return -1 };
|
||||
let n = match ns.to_str() { Ok(v) => v, Err(_) => return -1 };
|
||||
if n.is_empty() { return h.len() as i64; }
|
||||
if let Some(pos) = h.rfind(n) {
|
||||
pos as i64
|
||||
} else { -1 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user