Selfhost: EXE path switched to Program(JSON v0) → MIR(JSON) → ny-llvmc; BuildBox opts (structured via env/array) and Bridge v1 positive canary
- selfhost_build.sh: EXE now converts Stage‑B Program(JSON v0) to MIR(JSON) via --json-file + --program-json-to-mir, then feeds ny-llvmc - BuildBox: accept minimal opts via env or simple array parsing (alias_table, require_mods) - Add positive v1 bridge canary: canonicalize_method_size_on_array_vm.sh (quick)
This commit is contained in:
@ -42,6 +42,7 @@ pub fn build_command() -> Command {
|
||||
.arg(Arg::new("ny-parser-pipe").long("ny-parser-pipe").help("Read Ny JSON IR v0 from stdin and execute via MIR Interpreter").action(clap::ArgAction::SetTrue))
|
||||
.arg(Arg::new("json-file").long("json-file").value_name("FILE").help("Read Ny JSON IR v0 from a file and execute via MIR Interpreter"))
|
||||
.arg(Arg::new("emit-mir-json").long("emit-mir-json").value_name("FILE").help("Emit MIR JSON v0 to file and exit"))
|
||||
.arg(Arg::new("program-json-to-mir").long("program-json-to-mir").value_name("FILE").help("Convert Program(JSON v0) to MIR(JSON) and exit (use with --json-file)"))
|
||||
.arg(Arg::new("emit-exe").long("emit-exe").value_name("FILE").help("Emit native executable via ny-llvmc and exit"))
|
||||
.arg(Arg::new("emit-exe-nyrt").long("emit-exe-nyrt").value_name("DIR").help("Directory containing libnyash_kernel.a (used with --emit-exe)"))
|
||||
.arg(Arg::new("emit-exe-libs").long("emit-exe-libs").value_name("FLAGS").help("Extra linker flags for ny-llvmc when emitting executable"))
|
||||
@ -147,6 +148,7 @@ pub fn from_matches(matches: &ArgMatches) -> CliConfig {
|
||||
build_target: matches.get_one::<String>("build-target").cloned(),
|
||||
cli_usings: matches.get_many::<String>("using").map(|v| v.cloned().collect()).unwrap_or_else(|| Vec::new()),
|
||||
emit_mir_json: matches.get_one::<String>("emit-mir-json").cloned(),
|
||||
program_json_to_mir: matches.get_one::<String>("program-json-to-mir").cloned(),
|
||||
emit_exe: matches.get_one::<String>("emit-exe").cloned(),
|
||||
emit_exe_nyrt: matches.get_one::<String>("emit-exe-nyrt").cloned(),
|
||||
emit_exe_libs: matches.get_one::<String>("emit-exe-libs").cloned(),
|
||||
|
||||
@ -57,6 +57,7 @@ pub struct BuildConfig {
|
||||
pub struct EmitConfig {
|
||||
pub emit_cfg: Option<String>,
|
||||
pub emit_mir_json: Option<String>,
|
||||
pub program_json_to_mir: Option<String>,
|
||||
pub emit_exe: Option<String>,
|
||||
pub emit_exe_nyrt: Option<String>,
|
||||
pub emit_exe_libs: Option<String>,
|
||||
@ -86,4 +87,3 @@ pub struct CliGroups {
|
||||
pub run_task: Option<String>,
|
||||
pub load_ny_plugins: bool,
|
||||
}
|
||||
|
||||
|
||||
@ -59,6 +59,7 @@ pub struct CliConfig {
|
||||
pub build_target: Option<String>,
|
||||
pub cli_usings: Vec<String>,
|
||||
pub emit_mir_json: Option<String>,
|
||||
pub program_json_to_mir: Option<String>,
|
||||
pub emit_exe: Option<String>,
|
||||
pub emit_exe_nyrt: Option<String>,
|
||||
pub emit_exe_libs: Option<String>,
|
||||
@ -118,6 +119,7 @@ impl CliConfig {
|
||||
emit: EmitConfig {
|
||||
emit_cfg: self.emit_cfg.clone(),
|
||||
emit_mir_json: self.emit_mir_json.clone(),
|
||||
program_json_to_mir: self.program_json_to_mir.clone(),
|
||||
emit_exe: self.emit_exe.clone(),
|
||||
emit_exe_nyrt: self.emit_exe_nyrt.clone(),
|
||||
emit_exe_libs: self.emit_exe_libs.clone(),
|
||||
@ -190,6 +192,7 @@ impl Default for CliConfig {
|
||||
build_target: None,
|
||||
cli_usings: Vec::new(),
|
||||
emit_mir_json: None,
|
||||
program_json_to_mir: None,
|
||||
emit_exe: None,
|
||||
emit_exe_nyrt: None,
|
||||
emit_exe_libs: None,
|
||||
|
||||
@ -37,6 +37,24 @@ impl NyashRunner {
|
||||
}
|
||||
buf
|
||||
};
|
||||
// Optional: convert Program(JSON v0) → MIR(JSON) and exit when requested
|
||||
if let Some(out) = &groups.emit.program_json_to_mir {
|
||||
match super::json_v0_bridge::parse_json_v0_to_module(&json) {
|
||||
Ok(module) => {
|
||||
let p = std::path::Path::new(out);
|
||||
if let Err(e) = super::mir_json_emit::emit_mir_json_for_harness_bin(&module, p) {
|
||||
eprintln!("❌ Program→MIR emit error: {}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("❌ Program(JSON v0) parse error: {}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: delegate to PyVM when NYASH_PIPE_USE_PYVM=1
|
||||
if crate::config::env::pipe_use_pyvm() {
|
||||
let py = which::which("python3").ok();
|
||||
|
||||
@ -105,18 +105,25 @@ if [ -n "$EXE_OUT" ]; then
|
||||
# Requirements: ny-llvmc present and harness envs
|
||||
NYLL="${NYASH_NY_LLVM_COMPILER:-$ROOT/target/release/ny-llvmc}"
|
||||
if [ ! -x "$NYLL" ] && [ ! -f "$NYLL" ]; then
|
||||
echo "[selfhost] ny-llvmc not found: $NYLL (skip EXE). Set NYASH_NY_LLVM_COMPILER or build ny-llvmc" >&2
|
||||
echo "[selfhost] ny-llvmc not found: $NYLL (Set NYASH_NY_LLVM_COMPILER or build ny-llvmc)" >&2
|
||||
exit 2
|
||||
fi
|
||||
NYRT_DIR="${NYASH_EMIT_EXE_NYRT:-$ROOT/target/release}"
|
||||
export NYASH_LLVM_USE_HARNESS=1
|
||||
export NYASH_NY_LLVM_COMPILER="$NYLL"
|
||||
export NYASH_EMIT_EXE_NYRT="$NYRT_DIR"
|
||||
echo "[selfhost] emitting EXE via ny-llvmc → $EXE_OUT" >&2
|
||||
# Note: This path compiles the original Hako source via LLVM backend. Stage‑B JSON is emitted above for reference.
|
||||
"$BIN" --backend llvm --emit-exe "$EXE_OUT" "$IN"
|
||||
# Done
|
||||
|
||||
# Convert Program(JSON v0) → MIR(JSON) via runner
|
||||
MIR_TMP="${MIR_OUT:-/tmp/hako_stageb_mir_$$.json}"
|
||||
echo "[selfhost] converting Program(JSON v0) → MIR(JSON) → EXE" >&2
|
||||
"$BIN" --json-file "$tmp_json" --program-json-to-mir "$MIR_TMP"
|
||||
|
||||
# Build EXE via ny-llvmc
|
||||
"$NYLL" --in "$MIR_TMP" --emit exe --nyrt "$NYRT_DIR" --out "$EXE_OUT"
|
||||
|
||||
# Cleanup
|
||||
if [ -z "$JSON_OUT" ]; then rm -f "$tmp_json" 2>/dev/null || true; fi
|
||||
if [ -z "$MIR_OUT" ]; then rm -f "$MIR_TMP" 2>/dev/null || true; fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# canonicalize_method_size_on_array_vm.sh — v1 bridge positive: Constructor + Method(size) → rc=0
|
||||
|
||||
set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
if ROOT_GIT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null); then
|
||||
ROOT="$ROOT_GIT"
|
||||
else
|
||||
ROOT="$(cd "$SCRIPT_DIR/../../../../../../../../.." && pwd)"
|
||||
fi
|
||||
source "$ROOT/tools/smokes/v2/lib/test_runner.sh"
|
||||
require_env || exit 2
|
||||
|
||||
json_path="/tmp/ny_v1_ctor_method_size_$$.json"
|
||||
cat >"$json_path" <<'JSON'
|
||||
{"schema_version":"1.0","functions":[{"name":"main","blocks":[{"id":0,"instructions":[
|
||||
{"op":"mir_call","dst":1, "callee":{"type":"Constructor","box_type":"ArrayBox"}, "args":[]},
|
||||
{"op":"mir_call","dst":2, "callee":{"type":"Method","method":"size","receiver":1}, "args":[]},
|
||||
{"op":"ret","value":2}
|
||||
]}]}]}
|
||||
JSON
|
||||
|
||||
set +e
|
||||
HAKO_NYVM_V1_DOWNCONVERT=1 "$NYASH_BIN" --json-file "$json_path" >/dev/null 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
rm -f "$json_path"
|
||||
|
||||
if [ "$rc" = "0" ]; then
|
||||
echo "[PASS] canonicalize_method_size_on_array_vm"
|
||||
else
|
||||
echo "[FAIL] canonicalize_method_size_on_array_vm (rc=$rc)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user