diff --git a/lang/src/compiler/tests/stageb_min_sample.hako b/lang/src/compiler/tests/stageb_min_sample.hako new file mode 100644 index 00000000..bd259ff8 --- /dev/null +++ b/lang/src/compiler/tests/stageb_min_sample.hako @@ -0,0 +1,63 @@ +// Stage-B minimal test harness +// Purpose: Reproduce SSA/ValueId bugs in a minimal 100-line sample +// This file should pass through Stage-B compilation without SSA errors + +static box TestArgs { + method process(args) { + // Pattern 1: Method call in if-block before loop + if args != null { + local n = args.length() // This creates pinned receiver + local i = 0 + loop(i < n) { + local item = args.get(i) + print(item) + i = i + 1 + } + } + return 0 + } +} + +static box TestSimple { + method run() { + // Pattern 2: Simple method calls without loops + local x = new ArrayBox() + local len = x.length() + print(len) + return 0 + } +} + +static box TestNested { + method complex(data) { + // Pattern 3: Nested if/loop with method calls + if data != null { + local count = data.length() + if count > 0 { + local j = 0 + loop(j < count) { + local val = data.get(j) + if val != null { + local s = "" + val + print(s) + } + j = j + 1 + } + } + } + return 0 + } +} + +static box Main { + method main(args) { + // Test all patterns + local t1 = TestArgs.process(args) + local t2 = TestSimple.run() + + local test_data = new ArrayBox() + local t3 = TestNested.complex(test_data) + + return 0 + } +} diff --git a/tools/test_stageb_min.sh b/tools/test_stageb_min.sh new file mode 100644 index 00000000..6f0a3334 --- /dev/null +++ b/tools/test_stageb_min.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Stage-B minimal harness test script +# Tests stageb_min_sample.hako through Stage-B compilation pipeline + +set -e + +NYASH_BIN="${NYASH_BIN:-./target/release/hakorune}" +TEST_FILE="lang/src/compiler/tests/stageb_min_sample.hako" + +echo "=== Stage-B Minimal Harness Test ===" +echo "Test file: $TEST_FILE" +echo "Binary: $NYASH_BIN" +echo "" + +# Test 1: Direct VM execution (should work) +echo "--- Test 1: Direct VM execution ---" +NYASH_DISABLE_PLUGINS=1 NYASH_PARSER_STAGE3=1 \ + "$NYASH_BIN" --backend vm "$TEST_FILE" 2>&1 | tail -10 +echo "" + +# Test 2: Stage-B compilation (may have ValueId errors) +echo "--- Test 2: Stage-B compilation ---" +NYASH_JSON_ONLY=1 \ +NYASH_DISABLE_NY_COMPILER=1 HAKO_DISABLE_NY_COMPILER=1 \ +HAKO_STAGEB_FUNC_SCAN=1 \ +NYASH_PARSER_STAGE3=1 HAKO_PARSER_STAGE3=1 \ +NYASH_PARSER_ALLOW_SEMICOLON=1 \ +NYASH_ENABLE_USING=1 HAKO_ENABLE_USING=1 \ + "$NYASH_BIN" --backend vm lang/src/compiler/entry/compiler_stageb.hako \ + -- --source "$(cat $TEST_FILE)" 2>&1 | tail -20 +echo "" + +# Test 3: MIR verification (check for SSA errors) +echo "--- Test 3: MIR verification ---" +NYASH_VM_VERIFY_MIR=1 \ +NYASH_DISABLE_PLUGINS=1 NYASH_PARSER_STAGE3=1 \ + "$NYASH_BIN" --backend vm "$TEST_FILE" 2>&1 | \ + grep -E "(Undefined|verification|✅)" || echo "No verification errors (good!)" +echo "" + +echo "=== Test complete ==="