Bridge canonicalize: add ArrayBox.len / MapBox.len diff tests; Stage‑B helpers: require v0 header; MapBox.get: add stable tag prefix [map/missing]; new core smokes (string lastIndexOf -1, map delete missing)
This commit is contained in:
@ -154,7 +154,7 @@ impl MapBox {
|
|||||||
}
|
}
|
||||||
value.clone_box()
|
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))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,8 +28,8 @@ stageb_compile_to_json() {
|
|||||||
"$NYASH_BIN" --backend vm \
|
"$NYASH_BIN" --backend vm \
|
||||||
"$NYASH_ROOT/lang/src/compiler/entry/compiler_stageb.hako" -- --source "$(cat "$hako_tmp")"
|
"$NYASH_ROOT/lang/src/compiler/entry/compiler_stageb.hako" -- --source "$(cat "$hako_tmp")"
|
||||||
) > "$raw" 2>&1 || true
|
) > "$raw" 2>&1 || true
|
||||||
# Accept both MIR JSON v0 ("version":0, "kind":"Program") and Stage-1 JSON ("type":"Program")
|
# Require MIR JSON v0 header: {"version":0, "kind":"Program", ...}
|
||||||
if awk '(/"version":0/ && /"kind":"Program"/) || /"type":"Program"/ {print; found=1; exit} END{exit(found?0:1)}' "$raw" > "$json_out"; then
|
if awk '(/"version":0/ && /"kind":"Program"/) {print; found=1; exit} END{exit(found?0:1)}' "$raw" > "$json_out"; then
|
||||||
rm -f "$raw" "$hako_tmp"
|
rm -f "$raw" "$hako_tmp"
|
||||||
echo "$json_out"
|
echo "$json_out"
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
@ -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
|
||||||
|
|
||||||
Reference in New Issue
Block a user