bridge(loop): exit PHI を SSOT へ統一(break/continue スナップショットの stack 化)+ ループ比較スモーク(bridge)追加\n\n- lowering.rs: ループ用 break/continue スナップショットを thread-local stack で管理(push/pop/record)\n- loop_.rs: continue/break スナップを取り込み、seal_incomplete_phis_with・build_exit_phis_with に委譲\n- smokes: bridge_loop_sum/break/continue を opt-in 追加(SMOKES_ENABLE_LOOP_BRIDGE=1)
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
# Bridge(JSON v0) → MIR Interpreter での loop+break 検証
|
||||
# 既定は SKIP(opt-in: SMOKES_ENABLE_LOOP_BRIDGE=1)
|
||||
|
||||
source "$(dirname "$0")/../../../lib/test_runner.sh"
|
||||
source "$(dirname "$0")/../../../lib/result_checker.sh"
|
||||
|
||||
require_env || exit 2
|
||||
preflight_plugins || exit 2
|
||||
|
||||
if [ "${SMOKES_ENABLE_LOOP_BRIDGE:-0}" != "1" ]; then
|
||||
test_skip "bridge_loop_break_vm" "opt-in (set SMOKES_ENABLE_LOOP_BRIDGE=1)" && exit 0
|
||||
fi
|
||||
|
||||
test_bridge_loop_break() {
|
||||
local tmp_json="/tmp/nyash_bridge_loop_break_$$.json"
|
||||
cat > "$tmp_json" <<'JSON'
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Local","name":"i","expr":{"type":"Int","value":0}},
|
||||
{"type":"Local","name":"result","expr":{"type":"Int","value":0}},
|
||||
{"type":"Loop",
|
||||
"cond":{"type":"Compare","op":"<","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":100}},
|
||||
"body":[
|
||||
{"type":"If","cond":{"type":"Compare","op":"==","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":5}},
|
||||
"then":[{"type":"Break"}],"else":[]},
|
||||
{"type":"Local","name":"result","expr":{"type":"Binary","op":"+","lhs":{"type":"Var","name":"result"},"rhs":{"type":"Var","name":"i"}}},
|
||||
{"type":"Local","name":"i","expr":{"type":"Binary","op":"+","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":1}}}
|
||||
]
|
||||
},
|
||||
{"type":"Extern","iface":"env.console","method":"log","args":[{"type":"Var","name":"result"}]}
|
||||
]}
|
||||
JSON
|
||||
local output
|
||||
output=$(NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 "$NYASH_BIN" --backend vm --json-file "$tmp_json" 2>&1 | filter_noise)
|
||||
rm -f "$tmp_json"
|
||||
check_exact "10" "$output" "bridge_loop_break"
|
||||
}
|
||||
|
||||
run_test "bridge_loop_break" test_bridge_loop_break
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
# Bridge(JSON v0) → MIR Interpreter での loop+continue 検証
|
||||
# 既定は SKIP(opt-in: SMOKES_ENABLE_LOOP_BRIDGE=1)
|
||||
|
||||
source "$(dirname "$0")/../../../lib/test_runner.sh"
|
||||
source "$(dirname "$0")/../../../lib/result_checker.sh"
|
||||
|
||||
require_env || exit 2
|
||||
preflight_plugins || exit 2
|
||||
|
||||
if [ "${SMOKES_ENABLE_LOOP_BRIDGE:-0}" != "1" ]; then
|
||||
test_skip "bridge_loop_continue_vm" "opt-in (set SMOKES_ENABLE_LOOP_BRIDGE=1)" && exit 0
|
||||
fi
|
||||
|
||||
test_bridge_loop_continue() {
|
||||
local tmp_json="/tmp/nyash_bridge_loop_continue_$$.json"
|
||||
cat > "$tmp_json" <<'JSON'
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Local","name":"i","expr":{"type":"Int","value":0}},
|
||||
{"type":"Local","name":"sum","expr":{"type":"Int","value":0}},
|
||||
{"type":"Loop",
|
||||
"cond":{"type":"Compare","op":"<","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":5}},
|
||||
"body":[
|
||||
{"type":"Local","name":"i","expr":{"type":"Binary","op":"+","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":1}}},
|
||||
{"type":"If","cond":{"type":"Compare","op":"==","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":3}},
|
||||
"then":[{"type":"Continue"}],"else":[]},
|
||||
{"type":"Local","name":"sum","expr":{"type":"Binary","op":"+","lhs":{"type":"Var","name":"sum"},"rhs":{"type":"Var","name":"i"}}}
|
||||
]
|
||||
},
|
||||
{"type":"Extern","iface":"env.console","method":"log","args":[{"type":"Var","name":"sum"}]}
|
||||
]}
|
||||
JSON
|
||||
local output
|
||||
output=$(NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 "$NYASH_BIN" --backend vm --json-file "$tmp_json" 2>&1 | filter_noise)
|
||||
rm -f "$tmp_json"
|
||||
check_exact "12" "$output" "bridge_loop_continue"
|
||||
}
|
||||
|
||||
run_test "bridge_loop_continue" test_bridge_loop_continue
|
||||
|
||||
Reference in New Issue
Block a user