pyvm: split op handlers into ops_core/ops_box/ops_ctrl; add ops_flow + intrinsic; delegate vm.py without behavior change

net-plugin: modularize constants (consts.rs) and sockets (sockets.rs); remove legacy commented socket code; fix unused imports
mir: move instruction unit tests to tests/mir_instruction_unit.rs (file lean-up); no semantic changes
runner/pyvm: ensure using pre-strip; misc docs updates

Build: cargo build ok; legacy cfg warnings remain as before
This commit is contained in:
Selfhosting Dev
2025-09-21 08:53:00 +09:00
parent ee17cfd979
commit c8063c9e41
247 changed files with 10187 additions and 23124 deletions

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_PARSER_STAGE3=1
src="apps/tests/macro/exception/expr_postfix_direct.nyash"
out=$("$bin" --backend vm "$root/$src" 2>/dev/null)
count=$(printf "%s" "$out" | rg -n "^cleanup$" | wc -l | tr -d ' ')
test "$count" = "2" || { echo "[FAIL] expected 2 cleanup prints, got $count" >&2; echo "$out" >&2; exit 2; }
echo "[OK] direct postfix catch/cleanup output passed"
exit 0

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_PARSER_STAGE3=1
tmp="$root/tmp/expr_postfix_chain_tmp.nyash"
cat > "$tmp" <<'SRC'
function main(args) {
obj.m1().m2() catch { print("ok") }
}
SRC
# Expect parse success and run-time exit 0
"$bin" --backend vm "$tmp" >/dev/null 2>&1 && echo "[OK] postfix chain parse passed" && exit 0
echo "[FAIL] postfix chain parse failed" >&2
exit 2

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/loopform/for_step2.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
out=$("$bin" --backend vm "$src" 2>/dev/null || true)
# 0,2,4 が出力されることを簡易確認
echo "$out" | rg -q "^0$" && echo "$out" | rg -q "^2$" && echo "$out" | rg -q "^4$" && { echo "[OK] for_step2 output"; exit 0; }
echo "[FAIL] for_step2 output mismatch" >&2
echo "$out" >&2
exit 2

View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/loopform/foreach_empty.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
out=$("$bin" --backend vm "$src" 2>/dev/null || true)
# 空配列なので出力なし(空行も不可)
if [ -z "${out//$'\n'/}" ]; then
echo "[OK] foreach_empty output (no lines)"; exit 0
fi
echo "[FAIL] foreach_empty produced output unexpectedly" >&2
echo "$out" >&2
exit 2

View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")/../../../.." && pwd)
bin="$root/target/release/nyash"
prog="$root/apps/tests/macro/loopform/nested_block_break.nyash"
out=$("$bin" --backend vm "$prog")
# Expect lines 0,1,2 then break
expected=$'0\n1\n2'
if [ "$out" != "$expected" ]; then
echo "[FAIL] nested_block_break output mismatch" >&2
echo "got:" >&2
echo "$out" >&2
exit 2
fi
echo "[OK] nested_block_break output matched"

View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
# nested_if_continue: expect 1,3,5
out_c=$("$bin" --backend vm apps/tests/macro/loopform/nested_if_continue.nyash)
exp_c=$'1\n3\n5'
if [ "$(printf '%s' "$out_c" | tr -d '\r')" != "$(printf '%s' "$exp_c")" ]; then
echo "[FAIL] nested_if_continue output mismatch" >&2
echo "--- got ---" >&2; printf '%s\n' "$out_c" >&2
echo "--- exp ---" >&2; printf '%s\n' "$exp_c" >&2
exit 2
fi
# nested_if_break: expect 0,1,2
out_b=$("$bin" --backend vm apps/tests/macro/loopform/nested_if_break.nyash)
exp_b=$'0\n1\n2'
if [ "$(printf '%s' "$out_b" | tr -d '\r')" != "$(printf '%s' "$exp_b")" ]; then
echo "[FAIL] nested_if_break output mismatch" >&2
echo "--- got ---" >&2; printf '%s\n' "$out_b" >&2
echo "--- exp ---" >&2; printf '%s\n' "$exp_b" >&2
exit 3
fi
echo "[OK] loop nested-if break/continue outputs matched"
exit 0

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/exception/loop_postfix_sugar.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_CATCH_NEW=1
out=$("$bin" --backend vm "$src" 2>/dev/null || true)
exp=$'cleanup\ncleanup'
if [ "$(printf '%s' "$out" | tr -d '\r')" != "$(printf '%s' "$exp")" ]; then
echo "[FAIL] loop_postfix_sugar produced unexpected output" >&2
echo "--- got ---" >&2; printf '%s\n' "$out" >&2
echo "--- exp ---" >&2; printf '%s\n' "$exp" >&2
exit 2
fi
echo "[OK] loop_postfix_catch_cleanup output matched"
exit 0

View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/strings/env_tag_demo.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_MACRO_ENABLE=1
export NYASH_MACRO_PATHS="apps/macros/examples/env_tag_string_macro.nyash"
unset NYASH_MACRO_CAP_ENV || true
raw=$("$bin" --dump-expanded-ast-json "$root/$src")
export NYASH_MACRO_CTX_JSON='{"caps":{"io":false,"net":false,"env":true}}'
out=$(printf '%s' "$raw" | "$bin" --macro-expand-child apps/macros/examples/env_tag_string_macro.nyash)
echo "$out" | rg -q '"value":"hello \[ENV\]"' && { echo "[OK] macro ctx json smoke"; exit 0; }
echo "[FAIL] macro ctx json smoke (no tag)" >&2
echo "$out" >&2
exit 2

View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/match/literal_basic.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
out=$("$bin" --backend vm "$root/$src" 2>/dev/null)
test "$out" = "20" || { echo "[FAIL] expected 20, got '$out'" >&2; exit 2; }
echo "[OK] match literal_basic output passed"
exit 0

View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/match/literal_three_arms.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
out=$("$bin" --backend vm "$root/$src" 2>/dev/null)
test "$out" = "30" || { echo "[FAIL] expected 30, got '$out'" >&2; exit 2; }
echo "[OK] match literal_three_arms output passed"
exit 0

View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/strings/index_of_demo.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
out=$("$bin" --backend vm "$root/$src" 2>/dev/null)
test "$out" = "6" || { echo "[FAIL] expected 6, got '$out'" >&2; exit 2; }
echo "[OK] string indexOf output passed"
exit 0