diff --git a/apps/tests/phase118_loop_nested_if_merge_min.hako b/apps/tests/phase118_loop_nested_if_merge_min.hako new file mode 100644 index 00000000..436d08a9 --- /dev/null +++ b/apps/tests/phase118_loop_nested_if_merge_min.hako @@ -0,0 +1,18 @@ +// Phase 118: loop + if-only merge parity test +// Expected output: 2 (numeric line) +// Calculation: i=0: x=0 (skip), i=1: x=0+1→1, i=2: x=1+1→2 + +static box Main { + main() { + local i = 0 + local x = 0 + loop(i < 3) { + if i > 0 { + x = x + 1 + } + i = i + 1 + } + print(x) + return "OK" + } +} diff --git a/apps/tests/phase118_pattern3_if_sum_min.hako b/apps/tests/phase118_pattern3_if_sum_min.hako new file mode 100644 index 00000000..acab1c48 --- /dev/null +++ b/apps/tests/phase118_pattern3_if_sum_min.hako @@ -0,0 +1,34 @@ +// Phase 118: Pattern3 (if-sum) carrier merge regression +// Expected output: 12 (numeric line) +// +// Shape: +// - loop(i < 3) +// - if-only conditional update on carrier `sum` +// - loop var `i` + non-loop carrier `sum` +// +// Computation: +// sum=10 +// i=0: if false → sum += 0 +// i=1: if true → sum += 1 +// i=2: if true → sum += 1 +// => sum=12 + +static box Main { + main() { + local sum = 10 + local i = 0 + + loop(i < 3) { + if i > 0 { + sum = sum + 1 + } else { + sum = sum + 0 + } + i = i + 1 + } + + print(sum) + return "OK" + } +} + diff --git a/tools/smokes/v2/profiles/integration/apps/phase118_loop_nested_if_merge_llvm_exe.sh b/tools/smokes/v2/profiles/integration/apps/phase118_loop_nested_if_merge_llvm_exe.sh new file mode 100644 index 00000000..9036b66d --- /dev/null +++ b/tools/smokes/v2/profiles/integration/apps/phase118_loop_nested_if_merge_llvm_exe.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Phase 118: loop + if-else merge parity (LLVM EXE) + +source "$(dirname "$0")/../../../lib/test_runner.sh" +source "$(dirname "$0")/../../../lib/llvm_exe_runner.sh" +export SMOKES_USE_PYVM=0 +require_env || exit 2 + +llvm_exe_preflight_or_skip || exit 0 + +# Phase 97/98/100 SSOT: plugin dlopen check → build only if needed → dlopen recheck. +FILEBOX_SO="$NYASH_ROOT/plugins/nyash-filebox-plugin/libnyash_filebox_plugin.so" +MAPBOX_SO="$NYASH_ROOT/plugins/nyash-map-plugin/libnyash_map_plugin.so" +STRINGBOX_SO="$NYASH_ROOT/plugins/nyash-string-plugin/libnyash_string_plugin.so" +CONSOLEBOX_SO="$NYASH_ROOT/plugins/nyash-console-plugin/libnyash_console_plugin.so" +INTEGERBOX_SO="$NYASH_ROOT/plugins/nyash-integer-plugin/libnyash_integer_plugin.so" + +LLVM_REQUIRED_PLUGINS=( + "FileBox|$FILEBOX_SO|nyash-filebox-plugin" + "MapBox|$MAPBOX_SO|nyash-map-plugin" + "StringBox|$STRINGBOX_SO|nyash-string-plugin" + "ConsoleBox|$CONSOLEBOX_SO|nyash-console-plugin" + "IntegerBox|$INTEGERBOX_SO|nyash-integer-plugin" +) +LLVM_PLUGIN_BUILD_LOG="/tmp/phase118_loop_nested_if_merge_plugin_build.log" +llvm_exe_ensure_plugins_or_fail || exit 1 + +INPUT_HAKO="$NYASH_ROOT/apps/tests/phase118_loop_nested_if_merge_min.hako" +OUTPUT_EXE="$NYASH_ROOT/tmp/phase118_loop_nested_if_merge_llvm_exe" + +EXPECTED='2' +EXPECTED_LINES=1 +LLVM_BUILD_LOG="/tmp/phase118_loop_nested_if_merge_build.log" +if llvm_exe_build_and_run_numeric_smoke; then + test_pass "phase118_loop_nested_if_merge_llvm_exe: output matches expected (2)" +else + exit 1 +fi diff --git a/tools/smokes/v2/profiles/integration/apps/phase118_loop_nested_if_merge_vm.sh b/tools/smokes/v2/profiles/integration/apps/phase118_loop_nested_if_merge_vm.sh new file mode 100644 index 00000000..f32c42e3 --- /dev/null +++ b/tools/smokes/v2/profiles/integration/apps/phase118_loop_nested_if_merge_vm.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/../../../lib/output_validator.sh" + +FIXTURE="apps/tests/phase118_loop_nested_if_merge_min.hako" + +echo "[phase118_loop_nested_if_merge_vm] Testing loop + if-else merge parity (VM)..." + +# VM execution with STRICT mode +OUTPUT=$(NYASH_DISABLE_PLUGINS=1 HAKO_JOINIR_STRICT=1 ./target/release/hakorune --backend vm "$FIXTURE" 2>&1) || { + echo "❌ VM execution failed" + echo "$OUTPUT" + exit 1 +} + +# Validate: expect 1 line with value 2 +validate_numeric_output 1 "2" "$OUTPUT" + +echo "✅ [phase118_loop_nested_if_merge_vm] PASS" diff --git a/tools/smokes/v2/profiles/integration/apps/phase118_pattern3_if_sum_llvm_exe.sh b/tools/smokes/v2/profiles/integration/apps/phase118_pattern3_if_sum_llvm_exe.sh new file mode 100644 index 00000000..0e4147aa --- /dev/null +++ b/tools/smokes/v2/profiles/integration/apps/phase118_pattern3_if_sum_llvm_exe.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Phase 118: Pattern3 carrier merge regression (LLVM EXE) + +source "$(dirname "$0")/../../../lib/test_runner.sh" +source "$(dirname "$0")/../../../lib/llvm_exe_runner.sh" +source "$(dirname "$0")/../../../lib/output_validator.sh" +export SMOKES_USE_PYVM=0 +require_env || exit 2 + +llvm_exe_preflight_or_skip || exit 0 + +FILEBOX_SO="$NYASH_ROOT/plugins/nyash-filebox-plugin/libnyash_filebox_plugin.so" +MAPBOX_SO="$NYASH_ROOT/plugins/nyash-map-plugin/libnyash_map_plugin.so" +STRINGBOX_SO="$NYASH_ROOT/plugins/nyash-string-plugin/libnyash_string_plugin.so" +CONSOLEBOX_SO="$NYASH_ROOT/plugins/nyash-console-plugin/libnyash_console_plugin.so" +INTEGERBOX_SO="$NYASH_ROOT/plugins/nyash-integer-plugin/libnyash_integer_plugin.so" + +LLVM_REQUIRED_PLUGINS=( + "FileBox|$FILEBOX_SO|nyash-filebox-plugin" + "MapBox|$MAPBOX_SO|nyash-map-plugin" + "StringBox|$STRINGBOX_SO|nyash-string-plugin" + "ConsoleBox|$CONSOLEBOX_SO|nyash-console-plugin" + "IntegerBox|$INTEGERBOX_SO|nyash-integer-plugin" +) +LLVM_PLUGIN_BUILD_LOG="/tmp/phase118_pattern3_if_sum_plugin_build.log" +llvm_exe_ensure_plugins_or_fail || exit 1 + +INPUT_HAKO="$NYASH_ROOT/apps/tests/phase118_pattern3_if_sum_min.hako" +OUTPUT_EXE="$NYASH_ROOT/tmp/phase118_pattern3_if_sum_llvm_exe" + +EXPECTED='12' +EXPECTED_LINES=1 +LLVM_BUILD_LOG="/tmp/phase118_pattern3_if_sum_build.log" +if llvm_exe_build_and_run_numeric_smoke; then + test_pass "phase118_pattern3_if_sum_llvm_exe: output matches expected (12)" +else + exit 1 +fi + diff --git a/tools/smokes/v2/profiles/integration/apps/phase118_pattern3_if_sum_vm.sh b/tools/smokes/v2/profiles/integration/apps/phase118_pattern3_if_sum_vm.sh new file mode 100644 index 00000000..57ca815a --- /dev/null +++ b/tools/smokes/v2/profiles/integration/apps/phase118_pattern3_if_sum_vm.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Phase 118: Pattern3 carrier merge regression (VM) + +source "$(dirname "$0")/../../../lib/test_runner.sh" +source "$(dirname "$0")/../../../lib/output_validator.sh" +export SMOKES_USE_PYVM=0 +require_env || exit 2 + +RUN_TIMEOUT_SECS=${RUN_TIMEOUT_SECS:-10} + +INPUT="$NYASH_ROOT/apps/tests/phase118_pattern3_if_sum_min.hako" +EXPECTED="12" + +echo "[INFO] Phase 118: Pattern3 if-sum carrier merge (VM) - $INPUT" + +set +e +OUTPUT=$(timeout "$RUN_TIMEOUT_SECS" env \ + NYASH_DISABLE_PLUGINS=1 \ + HAKO_JOINIR_STRICT=1 \ + "$NYASH_BIN" --backend vm "$INPUT" 2>&1) +EXIT_CODE=$? +set -e + +if [ "$EXIT_CODE" -eq 124 ]; then + test_fail "phase118_pattern3_if_sum_vm: hakorune timed out (>${RUN_TIMEOUT_SECS}s)" + exit 1 +fi + +if [ "$EXIT_CODE" -ne 0 ]; then + echo "[FAIL] hakorune failed with exit code $EXIT_CODE" + echo "[INFO] output (tail):" + echo "$OUTPUT" | tail -n 80 || true + test_fail "phase118_pattern3_if_sum_vm: execution failed" + exit 1 +fi + +if validate_numeric_output 1 "$EXPECTED" "$OUTPUT"; then + test_pass "phase118_pattern3_if_sum_vm: output matches expected (12)" + exit 0 +fi + +echo "[INFO] output (tail):" +echo "$OUTPUT" | tail -n 80 || true +test_fail "phase118_pattern3_if_sum_vm: output mismatch" +exit 1 +