diff --git a/src/boxes/map_box.rs b/src/boxes/map_box.rs index be2bcc28..23d1c637 100644 --- a/src/boxes/map_box.rs +++ b/src/boxes/map_box.rs @@ -154,7 +154,7 @@ impl MapBox { } value.clone_box() } - None => Box::new(StringBox::new(&format!("Key not found: {}", key_str))), + None => Box::new(StringBox::new(&format!("[map/missing] Key not found: {}", key_str))), } } diff --git a/tools/smokes/v2/lib/stageb_helpers.sh b/tools/smokes/v2/lib/stageb_helpers.sh index 57bf56f4..078029c6 100644 --- a/tools/smokes/v2/lib/stageb_helpers.sh +++ b/tools/smokes/v2/lib/stageb_helpers.sh @@ -28,8 +28,8 @@ stageb_compile_to_json() { "$NYASH_BIN" --backend vm \ "$NYASH_ROOT/lang/src/compiler/entry/compiler_stageb.hako" -- --source "$(cat "$hako_tmp")" ) > "$raw" 2>&1 || true - # Accept both MIR JSON v0 ("version":0, "kind":"Program") and Stage-1 JSON ("type":"Program") - if awk '(/"version":0/ && /"kind":"Program"/) || /"type":"Program"/ {print; found=1; exit} END{exit(found?0:1)}' "$raw" > "$json_out"; then + # Require MIR JSON v0 header: {"version":0, "kind":"Program", ...} + if awk '(/"version":0/ && /"kind":"Program"/) {print; found=1; exit} END{exit(found?0:1)}' "$raw" > "$json_out"; then rm -f "$raw" "$hako_tmp" echo "$json_out" return 0 diff --git a/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_array_len_on_off_vm.sh b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_array_len_on_off_vm.sh new file mode 100644 index 00000000..b6b8a843 --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_array_len_on_off_vm.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# canonicalize_array_len_on_off_vm.sh — Verify ArrayBox.len ModuleFunction → Method rewrite + +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_array_len_$$.json" +mut_on="/tmp/ny_v1_array_len_on_$$.json" +mut_off="/tmp/ny_v1_array_len_off_$$.json" + +cat >"$json_path" <<'JSON' +{"schema_version":"1.0","functions":[{"name":"main","blocks":[{"id":0,"instructions":[{"op":"const","dst":1,"value":{"type":"i64","value":0}},{"op":"mir_call","mir_call":{"callee":{"type":"ModuleFunction","name":"ArrayBox.len"},"args":[1]}},{"op":"ret"}]}]}]} +JSON + +# ON → should rewrite to Method(box=ArrayBox, method=size, receiver=1) +set +e +HAKO_NYVM_V1_DOWNCONVERT=1 HAKO_BRIDGE_INJECT_SINGLETON=1 HAKO_DEBUG_NYVM_BRIDGE_DUMP_MUT="$mut_on" \ + "$ROOT/target/release/nyash" --json-file "$json_path" >/dev/null 2>&1 +set -e || true +if [ ! -f "$mut_on" ] || ! grep -q '"type":"Method"' "$mut_on" || ! grep -q '"box_name":"ArrayBox"' "$mut_on" || ! grep -q '"method":"size"' "$mut_on"; then + echo "[FAIL] canonicalize_array_len_on_off_vm (ON)" >&2; exit 1 +fi + +# OFF → should keep ModuleFunction (or no mutation dump) +set +e +HAKO_NYVM_V1_DOWNCONVERT=1 HAKO_DEBUG_NYVM_BRIDGE_DUMP_MUT="$mut_off" \ + "$ROOT/target/release/nyash" --json-file "$json_path" >/dev/null 2>&1 +set -e || true +if [ -f "$mut_off" ] && ! grep -q '"type":"ModuleFunction"' "$mut_off"; then + echo "[FAIL] canonicalize_array_len_on_off_vm (OFF)" >&2; exit 1 +fi + +echo "[PASS] canonicalize_array_len_on_off_vm" +rm -f "$json_path" "$mut_on" "$mut_off" +exit 0 + diff --git a/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_map_len_on_off_vm.sh b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_map_len_on_off_vm.sh new file mode 100644 index 00000000..15c2f39c --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_map_len_on_off_vm.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# canonicalize_map_len_on_off_vm.sh — Verify MapBox.len ModuleFunction → Method rewrite + +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_map_len_$$.json" +mut_on="/tmp/ny_v1_map_len_on_$$.json" +mut_off="/tmp/ny_v1_map_len_off_$$.json" + +cat >"$json_path" <<'JSON' +{"schema_version":"1.0","functions":[{"name":"main","blocks":[{"id":0,"instructions":[{"op":"const","dst":1,"value":{"type":"i64","value":0}},{"op":"mir_call","mir_call":{"callee":{"type":"ModuleFunction","name":"MapBox.len"},"args":[1]}},{"op":"ret"}]}]}]} +JSON + +# ON → should rewrite to Method(box=MapBox, method=len, receiver=1) +set +e +HAKO_NYVM_V1_DOWNCONVERT=1 HAKO_BRIDGE_INJECT_SINGLETON=1 HAKO_DEBUG_NYVM_BRIDGE_DUMP_MUT="$mut_on" \ + "$ROOT/target/release/nyash" --json-file "$json_path" >/dev/null 2>&1 +set -e || true +if [ ! -f "$mut_on" ] || ! grep -q '"type":"Method"' "$mut_on" || ! grep -q '"box_name":"MapBox"' "$mut_on" || ! grep -q '"method":"len"' "$mut_on"; then + echo "[FAIL] canonicalize_map_len_on_off_vm (ON)" >&2; exit 1 +fi + +# OFF → should keep ModuleFunction (or no mutation dump) +set +e +HAKO_NYVM_V1_DOWNCONVERT=1 HAKO_DEBUG_NYVM_BRIDGE_DUMP_MUT="$mut_off" \ + "$ROOT/target/release/nyash" --json-file "$json_path" >/dev/null 2>&1 +set -e || true +if [ -f "$mut_off" ] && ! grep -q '"type":"ModuleFunction"' "$mut_off"; then + echo "[FAIL] canonicalize_map_len_on_off_vm (OFF)" >&2; exit 1 +fi + +echo "[PASS] canonicalize_map_len_on_off_vm" +rm -f "$json_path" "$mut_on" "$mut_off" +exit 0 +