Phase 22.1 WIP: SSOT resolver + TLV infrastructure + Hako MIR builder setup
Setup infrastructure for Phase 22.1 (TLV C shim & Resolver SSOT):
Core changes:
- Add nyash_tlv, nyash_c_core, nyash_kernel_min_c crates (opt-in)
- Implement SSOT resolver bridge (src/using/ssot_bridge.rs)
- Add HAKO_USING_SSOT=1 / HAKO_USING_SSOT_HAKO=1 env support
- Add HAKO_TLV_SHIM=1 infrastructure (requires --features tlv-shim)
MIR builder improvements:
- Fix using/alias consistency in Hako MIR builder
- Add hako.mir.builder.internal.{prog_scan,pattern_util} to nyash.toml
- Normalize LLVM extern calls: nyash.console.* → nyash_console_*
Smoke tests:
- Add phase2211 tests (using_ssot_hako_parity_canary_vm.sh)
- Add phase2220, phase2230, phase2231 test structure
- Add phase2100 S3 backend selector tests
- Improve test_runner.sh with quiet/timeout controls
Documentation:
- Add docs/ENV_VARS.md (Phase 22.1 env vars reference)
- Add docs/development/runtime/C_CORE_ABI.md
- Update de-rust-roadmap.md with Phase 22.x details
Tools:
- Add tools/hakorune_emit_mir.sh (Hako-first MIR emission wrapper)
- Add tools/tlv_roundtrip_smoke.sh placeholder
- Improve ny_mir_builder.sh with better backend selection
Known issues (to be fixed):
- Parser infinite loop in static method parameter parsing
- Stage-B output contamination with "RC: 0" (needs NYASH_JSON_ONLY=1)
- phase2211/using_ssot_hako_parity_canary_vm.sh fork bomb (needs recursion guard)
Next steps: Fix parser infinite loop + Stage-B quiet mode for green tests
This commit is contained in:
13
crates/nyash_c_core/Cargo.toml
Normal file
13
crates/nyash_c_core/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "nyash-c-core"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "nyash_c_core"
|
||||
path = "src/lib.rs"
|
||||
crate-type = ["rlib", "staticlib"]
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
|
||||
8
crates/nyash_c_core/build.rs
Normal file
8
crates/nyash_c_core/build.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=src/c_core.c");
|
||||
cc::Build::new()
|
||||
.file("src/c_core.c")
|
||||
.warnings(false)
|
||||
.compile("nyash_c_core_c");
|
||||
}
|
||||
|
||||
31
crates/nyash_c_core/src/c_core.c
Normal file
31
crates/nyash_c_core/src/c_core.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdint.h>
|
||||
|
||||
// Design-stage C core probe. Returns 0 on success.
|
||||
int ny_core_probe_invoke(const char* target, const char* method, int32_t argc) {
|
||||
// For now, just return success without doing anything.
|
||||
(void)target; (void)method; (void)argc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Design-stage: MapBox.set stub (no-op). Returns 0 on success.
|
||||
int ny_core_map_set(int32_t type_id, uint32_t instance_id, const char* key, const char* val) {
|
||||
(void)type_id; (void)instance_id; (void)key; (void)val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Design-stage: ArrayBox.push stub (no-op). Returns 0 on success.
|
||||
int ny_core_array_push(int32_t type_id, uint32_t instance_id, long long val) {
|
||||
(void)type_id; (void)instance_id; (void)val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Design-stage: ArrayBox.get/size stubs (no-op). Return 0 success.
|
||||
int ny_core_array_get(int32_t type_id, uint32_t instance_id, long long idx) {
|
||||
(void)type_id; (void)instance_id; (void)idx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ny_core_array_len(int32_t type_id, uint32_t instance_id) {
|
||||
(void)type_id; (void)instance_id;
|
||||
return 0;
|
||||
}
|
||||
37
crates/nyash_c_core/src/lib.rs
Normal file
37
crates/nyash_c_core/src/lib.rs
Normal file
@ -0,0 +1,37 @@
|
||||
#[allow(non_camel_case_types)]
|
||||
type c_int = i32;
|
||||
|
||||
extern "C" {
|
||||
fn ny_core_probe_invoke(target: *const u8, method: *const u8, argc: c_int) -> c_int;
|
||||
fn ny_core_map_set(type_id: i32, instance_id: u32, key: *const u8, val: *const u8) -> c_int;
|
||||
fn ny_core_array_push(type_id: i32, instance_id: u32, val: i64) -> c_int;
|
||||
fn ny_core_array_get(type_id: i32, instance_id: u32, idx: i64) -> c_int;
|
||||
fn ny_core_array_len(type_id: i32, instance_id: u32) -> c_int;
|
||||
}
|
||||
|
||||
/// Safe wrapper for core probe invoke (design-stage)
|
||||
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 }
|
||||
}
|
||||
|
||||
/// 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 }
|
||||
}
|
||||
|
||||
/// ArrayBox.push stub (design-stage): returns 0 on success
|
||||
pub fn core_array_push(type_id: i32, instance_id: u32, val: i64) -> i32 {
|
||||
unsafe { ny_core_array_push(type_id as i32, instance_id as u32, val as i64) as i32 }
|
||||
}
|
||||
|
||||
pub fn core_array_get(type_id: i32, instance_id: u32, idx: i64) -> i32 {
|
||||
unsafe { ny_core_array_get(type_id as i32, instance_id as u32, idx as i64) as i32 }
|
||||
}
|
||||
|
||||
pub fn core_array_len(type_id: i32, instance_id: u32) -> i32 {
|
||||
unsafe { ny_core_array_len(type_id as i32, instance_id as u32) as i32 }
|
||||
}
|
||||
@ -14,6 +14,13 @@ pub extern "C" fn nyash_console_log_export(ptr: *const i8) -> i64 {
|
||||
0
|
||||
}
|
||||
|
||||
// Legacy alias: some generators may emit bare `print(i8*)` (void/i64 tolerated)
|
||||
// Provide a C symbol `print` to forward into nyash.console.log
|
||||
#[no_mangle]
|
||||
pub extern "C" fn print(ptr: *const i8) -> i64 {
|
||||
nyash_console_log_export(ptr)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
||||
13
crates/nyash_kernel_min_c/Cargo.toml
Normal file
13
crates/nyash_kernel_min_c/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "nyash-kernel-min-c"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "nyash_kernel_min_c"
|
||||
path = "src/lib.rs"
|
||||
crate-type = ["staticlib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
|
||||
8
crates/nyash_kernel_min_c/build.rs
Normal file
8
crates/nyash_kernel_min_c/build.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=src/kernel_min.c");
|
||||
cc::Build::new()
|
||||
.file("src/kernel_min.c")
|
||||
.warnings(false)
|
||||
.compile("nyash_kernel_min_c");
|
||||
}
|
||||
|
||||
24
crates/nyash_kernel_min_c/src/kernel_min.c
Normal file
24
crates/nyash_kernel_min_c/src/kernel_min.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Minimal C runtime symbols (design-stage). These provide a safe, tiny set of
|
||||
// externs for experiments; real NyKernel remains authoritative.
|
||||
|
||||
// Print: accept pointer (may be NULL). Returns 0 on success.
|
||||
long nyash_console_log(char* p) {
|
||||
(void)p;
|
||||
puts("hello");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// from_i8_string: returns a fake handle (0). Real mapping is in Rust NyKernel.
|
||||
long nyash_box_from_i8_string(char* p) {
|
||||
(void)p; // not used in design stage stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Optional minimal stubs (not used by default; reserved for future reps)
|
||||
long nyash_array_birth_h(void) { return 1; }
|
||||
long nyash_array_length_h(long handle) { (void)handle; return 0; }
|
||||
long nyash_map_birth_h(void) { return 1; }
|
||||
long nyash_map_size_h(long handle) { (void)handle; return 0; }
|
||||
2
crates/nyash_kernel_min_c/src/lib.rs
Normal file
2
crates/nyash_kernel_min_c/src/lib.rs
Normal file
@ -0,0 +1,2 @@
|
||||
// Rust side is empty; the staticlib is produced from C sources via build.rs
|
||||
|
||||
18
crates/nyash_tlv/Cargo.toml
Normal file
18
crates/nyash_tlv/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "nyash-tlv"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
description = "Minimal TLV codec shim (C FFI) with safe Rust wrappers"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
# Enable building the C shim via cc
|
||||
c-shim = []
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
|
||||
13
crates/nyash_tlv/build.rs
Normal file
13
crates/nyash_tlv/build.rs
Normal file
@ -0,0 +1,13 @@
|
||||
fn main() {
|
||||
// Only build the C shim when the `c-shim` feature is enabled.
|
||||
let use_c = std::env::var("CARGO_FEATURE_C_SHIM").is_ok();
|
||||
if !use_c {
|
||||
println!("cargo:warning=nyash-tlv: c-shim feature disabled; using Rust stub");
|
||||
return;
|
||||
}
|
||||
cc::Build::new()
|
||||
.file("src/tlv.c")
|
||||
.flag_if_supported("-std=c99")
|
||||
.compile("nyash_tlv_c");
|
||||
}
|
||||
|
||||
44
crates/nyash_tlv/src/lib.rs
Normal file
44
crates/nyash_tlv/src/lib.rs
Normal file
@ -0,0 +1,44 @@
|
||||
#![deny(unused_must_use)]
|
||||
|
||||
use libc::{c_uchar, size_t};
|
||||
|
||||
#[cfg(feature = "c-shim")]
|
||||
extern "C" {
|
||||
fn ny_tlv_identity(in_ptr: *const c_uchar, len: size_t, out_ptr: *mut *mut c_uchar) -> size_t;
|
||||
fn ny_tlv_free(ptr: *mut c_uchar);
|
||||
}
|
||||
|
||||
/// Round‑trip helper (identity): returns a freshly allocated copy of the input.
|
||||
///
|
||||
/// When built with `c-shim` feature, this calls the C implementation.
|
||||
/// Otherwise, it falls back to a pure Rust copy (stub), preserving the public API.
|
||||
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);
|
||||
if sz == 0 || out_ptr.is_null() {
|
||||
return Vec::new();
|
||||
}
|
||||
let slice = std::slice::from_raw_parts(out_ptr, sz as usize);
|
||||
let v = slice.to_vec();
|
||||
ny_tlv_free(out_ptr);
|
||||
return v;
|
||||
}
|
||||
#[cfg(not(feature = "c-shim"))]
|
||||
{
|
||||
input.to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn identity_roundtrip() {
|
||||
let src = b"hello tlv";
|
||||
let out = tlv_roundtrip_identity(src);
|
||||
assert_eq!(out, src);
|
||||
}
|
||||
}
|
||||
|
||||
19
crates/nyash_tlv/src/tlv.c
Normal file
19
crates/nyash_tlv/src/tlv.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Minimal C shim: identity round‑trip (copy input to a new buffer).
|
||||
// Returns size written to *out_ptr. Caller must free via ny_tlv_free.
|
||||
size_t ny_tlv_identity(const uint8_t* in_ptr, size_t len, uint8_t** out_ptr) {
|
||||
if (!in_ptr || !out_ptr) return 0;
|
||||
uint8_t* buf = (uint8_t*)malloc(len == 0 ? 1 : len);
|
||||
if (!buf) return 0;
|
||||
if (len > 0) memcpy(buf, in_ptr, len);
|
||||
*out_ptr = buf;
|
||||
return len;
|
||||
}
|
||||
|
||||
void ny_tlv_free(uint8_t* ptr) {
|
||||
if (ptr) free(ptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user