Files
hakorune/crates/nyash_kernel/src/plugin/console.rs

154 lines
4.2 KiB
Rust
Raw Normal View History

2025-09-11 11:19:55 +09:00
// ---- ExternCall helpers for LLVM lowering ----
// Exported as: nyash.console.log(i8* cstr) -> i64
#[export_name = "nyash.console.log"]
pub extern "C" fn nyash_console_log_export(ptr: *const i8) -> i64 {
if ptr.is_null() {
return 0;
}
unsafe {
let c = std::ffi::CStr::from_ptr(ptr);
if let Ok(s) = c.to_str() {
println!("{}", s);
}
}
0
}
// Exported as: nyash.console.log_handle(i64 handle) -> i64
#[export_name = "nyash.console.log_handle"]
pub extern "C" fn nyash_console_log_handle(handle: i64) -> i64 {
use nyash_rust::jit::rt::handles;
eprintln!("DEBUG: handle={}", handle);
feat: Phase 2.2 LLVM静的プラグイン検証完了!nyrt設計真実解明 ✅ **Phase 2.2達成項目**: - LLVMスモークテスト完全成功(1648バイト生成) - プラグイン統合動作確認(StringBox/IntegerBox@LLVM) - 静的コンパイル核心技術実証(MIR→LLVM→オブジェクト) - Everything is Plugin革命のLLVM対応確認 🔍 **Task先生nyrt調査成果**: - nyrt正体解明:AOT/LLVMランタイム必須インフラ - 機能分類:58%必須(ハンドル・GC・エントリー)42%代替可能 - 設計一貫性:75%達成(Box操作完全プラグイン化) - 削減戦略:Phase A実装で26個関数→プラグイン統合(42%削減) 🎯 **Everything is Plugin完全実現への道筋**: - 現状:プラグインファクトリー(StrictPluginFirst)完全動作 - 課題:nyrt中央集権 vs プラグイン哲学の矛盾 - 解決:Hybrid Plugin Architecture推進 - 目標:String/Box API→プラグイン統合で設計一貫性完成 📊 **技術的成果**: - LLVM static plugin integration: ✅ 完全動作 - Plugin priority system: ✅ 完全動作 - Object code generation: ✅ 実証済み - nyrt architectural analysis: ✅ 完全解明 🚀 **Phase 15.5革命基盤確立**: プラグイン優先アーキテクチャ実用化完了 次段階Phase 2.3でビルトインBox段階削除+nyrt Plugin統合推進へ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 12:22:08 +09:00
if let Some(obj) = handles::get(handle) {
2025-09-11 11:19:55 +09:00
let s = obj.to_string_box().value;
println!("{}", s);
} else {
eprintln!("DEBUG: handle {} not found in registry", handle);
println!("{}", handle);
}
0
}
// Exported as: nyash.console.warn_handle(i64 handle) -> i64
#[export_name = "nyash.console.warn_handle"]
pub extern "C" fn nyash_console_warn_handle(handle: i64) -> i64 {
if handle <= 0 {
return 0;
}
feat: Phase 2.2 LLVM静的プラグイン検証完了!nyrt設計真実解明 ✅ **Phase 2.2達成項目**: - LLVMスモークテスト完全成功(1648バイト生成) - プラグイン統合動作確認(StringBox/IntegerBox@LLVM) - 静的コンパイル核心技術実証(MIR→LLVM→オブジェクト) - Everything is Plugin革命のLLVM対応確認 🔍 **Task先生nyrt調査成果**: - nyrt正体解明:AOT/LLVMランタイム必須インフラ - 機能分類:58%必須(ハンドル・GC・エントリー)42%代替可能 - 設計一貫性:75%達成(Box操作完全プラグイン化) - 削減戦略:Phase A実装で26個関数→プラグイン統合(42%削減) 🎯 **Everything is Plugin完全実現への道筋**: - 現状:プラグインファクトリー(StrictPluginFirst)完全動作 - 課題:nyrt中央集権 vs プラグイン哲学の矛盾 - 解決:Hybrid Plugin Architecture推進 - 目標:String/Box API→プラグイン統合で設計一貫性完成 📊 **技術的成果**: - LLVM static plugin integration: ✅ 完全動作 - Plugin priority system: ✅ 完全動作 - Object code generation: ✅ 実証済み - nyrt architectural analysis: ✅ 完全解明 🚀 **Phase 15.5革命基盤確立**: プラグイン優先アーキテクチャ実用化完了 次段階Phase 2.3でビルトインBox段階削除+nyrt Plugin統合推進へ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 12:22:08 +09:00
if let Some(obj) = nyash_rust::jit::rt::handles::get(handle) {
2025-09-11 11:19:55 +09:00
let s = obj.to_string_box().value;
eprintln!("WARN: {}", s);
} else {
eprintln!("WARN: {}", handle);
}
0
}
// Exported as: nyash.console.error_handle(i64 handle) -> i64
#[export_name = "nyash.console.error_handle"]
pub extern "C" fn nyash_console_error_handle(handle: i64) -> i64 {
if handle <= 0 {
return 0;
}
feat: Phase 2.2 LLVM静的プラグイン検証完了!nyrt設計真実解明 ✅ **Phase 2.2達成項目**: - LLVMスモークテスト完全成功(1648バイト生成) - プラグイン統合動作確認(StringBox/IntegerBox@LLVM) - 静的コンパイル核心技術実証(MIR→LLVM→オブジェクト) - Everything is Plugin革命のLLVM対応確認 🔍 **Task先生nyrt調査成果**: - nyrt正体解明:AOT/LLVMランタイム必須インフラ - 機能分類:58%必須(ハンドル・GC・エントリー)42%代替可能 - 設計一貫性:75%達成(Box操作完全プラグイン化) - 削減戦略:Phase A実装で26個関数→プラグイン統合(42%削減) 🎯 **Everything is Plugin完全実現への道筋**: - 現状:プラグインファクトリー(StrictPluginFirst)完全動作 - 課題:nyrt中央集権 vs プラグイン哲学の矛盾 - 解決:Hybrid Plugin Architecture推進 - 目標:String/Box API→プラグイン統合で設計一貫性完成 📊 **技術的成果**: - LLVM static plugin integration: ✅ 完全動作 - Plugin priority system: ✅ 完全動作 - Object code generation: ✅ 実証済み - nyrt architectural analysis: ✅ 完全解明 🚀 **Phase 15.5革命基盤確立**: プラグイン優先アーキテクチャ実用化完了 次段階Phase 2.3でビルトインBox段階削除+nyrt Plugin統合推進へ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 12:22:08 +09:00
if let Some(obj) = nyash_rust::jit::rt::handles::get(handle) {
2025-09-11 11:19:55 +09:00
let s = obj.to_string_box().value;
eprintln!("ERROR: {}", s);
} else {
eprintln!("ERROR: {}", handle);
}
0
}
// Exported as: nyash.debug.trace_handle(i64 handle) -> i64
#[export_name = "nyash.debug.trace_handle"]
pub extern "C" fn nyash_debug_trace_handle(handle: i64) -> i64 {
if handle <= 0 {
return 0;
}
feat: Phase 2.2 LLVM静的プラグイン検証完了!nyrt設計真実解明 ✅ **Phase 2.2達成項目**: - LLVMスモークテスト完全成功(1648バイト生成) - プラグイン統合動作確認(StringBox/IntegerBox@LLVM) - 静的コンパイル核心技術実証(MIR→LLVM→オブジェクト) - Everything is Plugin革命のLLVM対応確認 🔍 **Task先生nyrt調査成果**: - nyrt正体解明:AOT/LLVMランタイム必須インフラ - 機能分類:58%必須(ハンドル・GC・エントリー)42%代替可能 - 設計一貫性:75%達成(Box操作完全プラグイン化) - 削減戦略:Phase A実装で26個関数→プラグイン統合(42%削減) 🎯 **Everything is Plugin完全実現への道筋**: - 現状:プラグインファクトリー(StrictPluginFirst)完全動作 - 課題:nyrt中央集権 vs プラグイン哲学の矛盾 - 解決:Hybrid Plugin Architecture推進 - 目標:String/Box API→プラグイン統合で設計一貫性完成 📊 **技術的成果**: - LLVM static plugin integration: ✅ 完全動作 - Plugin priority system: ✅ 完全動作 - Object code generation: ✅ 実証済み - nyrt architectural analysis: ✅ 完全解明 🚀 **Phase 15.5革命基盤確立**: プラグイン優先アーキテクチャ実用化完了 次段階Phase 2.3でビルトインBox段階削除+nyrt Plugin統合推進へ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 12:22:08 +09:00
if let Some(obj) = nyash_rust::jit::rt::handles::get(handle) {
2025-09-11 11:19:55 +09:00
let s = obj.to_string_box().value;
eprintln!("TRACE: {}", s);
} else {
eprintln!("TRACE: {}", handle);
}
0
}
// Exported as: nyash.console.warn(i8* cstr) -> i64
#[export_name = "nyash.console.warn"]
pub extern "C" fn nyash_console_warn_export(ptr: *const i8) -> i64 {
if ptr.is_null() {
return 0;
}
unsafe {
let c = std::ffi::CStr::from_ptr(ptr);
if let Ok(s) = c.to_str() {
eprintln!("[warn] {}", s);
}
}
0
}
// Exported as: nyash.console.error(i8* cstr) -> i64
#[export_name = "nyash.console.error"]
pub extern "C" fn nyash_console_error_export(ptr: *const i8) -> i64 {
if ptr.is_null() {
return 0;
}
unsafe {
let c = std::ffi::CStr::from_ptr(ptr);
if let Ok(s) = c.to_str() {
eprintln!("[error] {}", s);
}
}
0
}
// Exported as: nyash.debug.trace(i8* cstr) -> i64
#[export_name = "nyash.debug.trace"]
pub extern "C" fn nyash_debug_trace_export(ptr: *const i8) -> i64 {
if ptr.is_null() {
return 0;
}
unsafe {
let c = std::ffi::CStr::from_ptr(ptr);
if let Ok(s) = c.to_str() {
eprintln!("[trace] {}", s);
}
}
0
}
// Exported as: nyash.console.readline() -> i8*
#[export_name = "nyash.console.readline"]
pub extern "C" fn nyash_console_readline_export() -> *mut i8 {
use std::io;
// Read a line from stdin; normalize to UTF-8 and strip trailing CR/LF
let mut input = String::new();
// Use read_to_end if stdin is not a TTY? Simpler: read_line through BufRead
// For simplicity, read from stdin into buffer until newline or EOF
let mut buf = String::new();
// Note: use std::io::stdin() directly without an unused handle binding
2025-09-11 11:19:55 +09:00
// On failure or EOF, return empty string
match io::stdin().read_line(&mut buf) {
Ok(_n) => {
input = buf;
}
Err(_) => {
input.clear();
}
}
while input.ends_with('\n') || input.ends_with('\r') {
input.pop();
}
// Allocate C string (null-terminated)
let mut bytes = input.into_bytes();
bytes.push(0);
let boxed = bytes.into_boxed_slice();
let raw = Box::into_raw(boxed) as *mut u8;
raw as *mut i8
}