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:
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