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,25 @@
#!/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"
# Do NOT set NYASH_MACRO_CAP_ENV; pass via ctx JSON instead
unset NYASH_MACRO_CAP_ENV || true
raw=$("$bin" --dump-expanded-ast-json "$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] env-tag macro applied via ctx JSON" && exit 0
echo "[FAIL] env-tag macro did not apply (ctx JSON path)" >&2
echo "$out" >&2
exit 2

View File

@ -0,0 +1,22 @@
#!/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"
export NYASH_MACRO_CAP_ENV=1
raw=$("$bin" --dump-expanded-ast-json "$src")
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] env-tag macro applied" && exit 0
echo "[FAIL] env-tag macro did not apply" >&2
echo "$out" >&2
exit 2

View File

@ -0,0 +1,8 @@
{"kind":"Program","statements":[
{"kind":"Local","variables":["i"],"inits":[{"kind":"Literal","value":{"type":"int","value":0}}]},
{"kind":"Loop","condition":{"kind":"BinaryOp","op":"<=","left":{"kind":"Variable","name":"i"},"right":{"kind":"Literal","value":{"type":"int","value":4}}},"body":[
{"kind":"Print","expression":{"kind":"Variable","name":"i"}},
{"kind":"Assignment","target":{"kind":"Variable","name":"i"},"value":{"kind":"BinaryOp","op":"+","left":{"kind":"Variable","name":"i"},"right":{"kind":"Literal","value":{"type":"int","value":2}}}}
]}
]}

View File

@ -0,0 +1,27 @@
#!/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"
golden="$root/tools/test/golden/macro/for_step2.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] for_step2 expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden for_step2 expansion matched"

View File

@ -0,0 +1,9 @@
{"kind":"Program","statements":[
{"kind":"Local","variables":["arr"],"inits":[{"kind":"Array","elements":[]}]},
{"kind":"Local","variables":["__ny_i"],"inits":[{"kind":"Literal","value":{"type":"int","value":0}}]},
{"kind":"Loop","condition":{"kind":"BinaryOp","op":"<","left":{"kind":"Variable","name":"__ny_i"},"right":{"kind":"MethodCall","object":{"kind":"Variable","name":"arr"},"method":"size","arguments":[]}},"body":[
{"kind":"Print","expression":{"kind":"MethodCall","object":{"kind":"Variable","name":"arr"},"method":"get","arguments":[{"kind":"Variable","name":"__ny_i"}]}},
{"kind":"Assignment","target":{"kind":"Variable","name":"__ny_i"},"value":{"kind":"BinaryOp","op":"+","left":{"kind":"Variable","name":"__ny_i"},"right":{"kind":"Literal","value":{"type":"int","value":1}}}}
]}
]}

View File

@ -0,0 +1,27 @@
#!/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"
golden="$root/tools/test/golden/macro/foreach_empty.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] foreach_empty expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden foreach_empty expansion matched"

View File

@ -0,0 +1,15 @@
{"kind":"Program","statements":[
{"kind":"FunctionDeclaration","name":"main","params":["args"],"body":[
{"kind":"Local","variables":["x"],"inits":[null]},
{"kind":"Local","variables":["c"],"inits":[{"kind":"Literal","value":{"type":"int","value":0}}]},
{"kind":"Loop","condition":{"kind":"Literal","value":{"type":"int","value":1}},"body":[
{"kind":"If","condition":{"kind":"BinaryOp","op":"==","left":{"kind":"Variable","name":"c"},"right":{"kind":"Literal","value":{"type":"int","value":1}}},
"then":[{"kind":"Assignment","target":{"kind":"Variable","name":"x"},"value":{"kind":"Literal","value":{"type":"int","value":10}}}],
"else":[{"kind":"Assignment","target":{"kind":"Variable","name":"x"},"value":{"kind":"Literal","value":{"type":"int","value":20}}}]
},
{"kind":"Break"}
]},
{"kind":"Print","expression":{"kind":"Variable","name":"x"}}
]}
]}

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/if/with_else.nyash"
golden="$root/tools/test/golden/macro/if_else_loopform.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
export NYASH_IF_AS_LOOPFORM=1
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] if_else_loopform expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden if_else_loopform expansion matched"

View File

@ -0,0 +1,15 @@
{"kind":"Program","statements":[
{"kind":"FunctionDeclaration","name":"main","params":["args"],"body":[
{"kind":"Local","variables":["x"],"inits":[{"kind":"Literal","value":{"type":"int","value":0}}]},
{"kind":"Loop","condition":{"kind":"Literal","value":{"type":"int","value":1}},"body":[
{"kind":"If","condition":{"kind":"Literal","value":{"type":"int","value":1}},
"then":[
{"kind":"Assignment","target":{"kind":"Variable","name":"x"},"value":{"kind":"Literal","value":{"type":"int","value":42}}},
{"kind":"Print","expression":{"kind":"Variable","name":"x"}}
],
"else": null
},
{"kind":"Break"}
]}
]}
]}

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/if/then_only.nyash"
golden="$root/tools/test/golden/macro/if_then_loopform.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
export NYASH_IF_AS_LOOPFORM=1
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] if_then_loopform expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden if_then_loopform expansion matched"

View File

@ -0,0 +1,15 @@
{"kind":"Program","statements":[
{"kind":"FunctionDeclaration","name":"f","params":["x"],"body":[{"kind":"Return","value":{"kind":"Variable","name":"x"}}]},
{"kind":"FunctionDeclaration","name":"main","params":["args"],"body":[
{"kind":"Local","variables":["i"],"inits":[{"kind":"Literal","value":{"type":"int","value":0}}]},
{"kind":"Loop","condition":{"kind":"BinaryOp","op":"<","left":{"kind":"Variable","name":"i"},"right":{"kind":"Literal","value":{"type":"int","value":2}}},"body":[
{"kind":"TryCatch",
"try":[{"kind":"FunctionCall","name":"f","arguments":[{"kind":"Variable","name":"i"}]}],
"catch":[{"type":"Error","var":"e","body":[{"kind":"Print","expression":{"kind":"Variable","name":"e"}}]}],
"cleanup":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"cleanup"}}}]
},
{"kind":"Assignment","target":{"kind":"Variable","name":"i"},"value":{"kind":"BinaryOp","op":"+","left":{"kind":"Variable","name":"i"},"right":{"kind":"Literal","value":{"type":"int","value":1}}}}
]}
]}
]}

View File

@ -0,0 +1,28 @@
#!/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"
golden="$root/tools/test/golden/macro/loop_postfix_sugar.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
export NYASH_CATCH_NEW=1
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] loop_postfix_sugar expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden loop_postfix_sugar expansion matched"

View File

@ -0,0 +1,19 @@
{"kind":"Program","statements":[
{"kind":"Local","variables":["d"],"inits":[{"kind":"Literal","value":{"type":"int","value":3}}]},
{"kind":"Local","variables":["r"],"inits":[
{"kind":"If","condition":{"kind":"BinaryOp","op":"==","left":{"kind":"Variable","name":"d"},"right":{"kind":"Literal","value":{"type":"int","value":1}}},"then":[
{"kind":"Literal","value":{"type":"int","value":10}}
],"else":[
{"kind":"If","condition":{"kind":"BinaryOp","op":"==","left":{"kind":"Variable","name":"d"},"right":{"kind":"Literal","value":{"type":"int","value":2}}},"then":[
{"kind":"Literal","value":{"type":"int","value":20}}
],"else":[
{"kind":"If","condition":{"kind":"BinaryOp","op":"==","left":{"kind":"Variable","name":"d"},"right":{"kind":"Literal","value":{"type":"int","value":3}}},"then":[
{"kind":"Literal","value":{"type":"int","value":30}}
],"else":[
{"kind":"Literal","value":{"type":"int","value":40}}
]}
]}
]}
]},
{"kind":"Print","expression":{"kind":"Variable","name":"r"}}
]}

View File

@ -0,0 +1,31 @@
#!/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"
golden="$root/tools/test/golden/macro/match_literal_three_arms.expanded.json"
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
normalize_json() {
python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",",":")))'
}
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "Golden mismatch (match literal three arms)" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden match literal three arms matched"

View File

@ -0,0 +1,10 @@
{"kind":"Program","statements":[
{"kind":"FunctionDeclaration","name":"do_work","params":["args"],"body":[{"kind":"Return","value":{"kind":"Literal","value":{"type":"int","value":0}}}]},
{"kind":"FunctionDeclaration","name":"main","params":["args"],"body":[
{"kind":"TryCatch",
"try":[{"kind":"FunctionCall","name":"do_work","arguments":[{"kind":"Variable","name":"args"}]}],
"catch":[{"type":"Error","var":"e","body":[{"kind":"Print","expression":{"kind":"Variable","name":"e"}}]}],
"cleanup":null}
]}
]}

View File

@ -0,0 +1,13 @@
{"kind":"Program","statements":[
{"kind":"BoxDeclaration","name":"Worker","methods":{
"run": {"kind":"FunctionDeclaration","name":"run","params":[],"body":[{"kind":"Return","value":{"kind":"Literal","value":{"type":"int","value":0}}}],"static":false,"override":false}
}},
{"kind":"FunctionDeclaration","name":"main","params":["args"],"body":[
{"kind":"Local","variables":["w"],"inits":[{"kind":"New","class":"Worker","args":[]}]},
{"kind":"TryCatch",
"try":[{"kind":"MethodCall","object":{"kind":"Variable","name":"w"},"method":"run","arguments":[]}],
"catch":[{"type":"Error","var":"e","body":[{"kind":"Print","expression":{"kind":"Variable","name":"e"}}]}],
"cleanup":null}
]}
]}

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/exception/postfix_catch_method.nyash"
golden="$root/tools/test/golden/macro/postfix_catch_method.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
export NYASH_CATCH_NEW=1
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] postfix_catch_method expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden postfix_catch_method expansion matched"

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/exception/postfix_catch.nyash"
golden="$root/tools/test/golden/macro/postfix_catch.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
export NYASH_CATCH_NEW=1
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] postfix_catch expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden postfix_catch expansion matched"

View File

@ -0,0 +1,11 @@
{"kind":"Program","statements":[
{"kind":"FunctionDeclaration","name":"cleanup_target","params":["args"],"body":[{"kind":"Return","value":{"kind":"Literal","value":{"type":"int","value":1}}}]},
{"kind":"FunctionDeclaration","name":"main","params":["args"],"body":[
{"kind":"TryCatch",
"try":[{"kind":"FunctionCall","name":"cleanup_target","arguments":[{"kind":"Variable","name":"args"}]}],
"catch":[],
"cleanup":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"done"}}}]
}
]}
]}

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/exception/with_cleanup.nyash"
golden="$root/tools/test/golden/macro/with_cleanup.expanded.json"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
normalize_json() { python3 -c 'import sys,json; print(json.dumps(json.loads(sys.stdin.read()), sort_keys=True, separators=(",", ":")))'; }
export NYASH_CATCH_NEW=1
out_raw=$("$bin" --dump-expanded-ast-json "$src")
out_norm=$(printf '%s' "$out_raw" | normalize_json)
gold_norm=$(normalize_json < "$golden")
if [ "$out_norm" != "$gold_norm" ]; then
echo "[FAIL] with_cleanup expanded JSON mismatch" >&2
diff -u <(echo "$out_norm") <(echo "$gold_norm") || true
exit 2
fi
echo "[OK] golden with_cleanup expansion matched"

View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/llvm_const_ret.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release --features llvm)" >&2
exit 1
fi
export NYASH_LLVM_USE_HARNESS=1
export NYASH_LLVM_SANITIZE_EMPTY_PHI=1
irfile="$root/tmp/$(basename "$src" .nyash)_llvm.ll"
mkdir -p "$root/tmp"
NYASH_LLVM_DUMP_IR="$irfile" "$bin" --backend llvm "$src" >/dev/null 2>&1 || true
if [ ! -s "$irfile" ]; then
echo "[FAIL] IR not dumped for $src" >&2
exit 2
fi
# No empty phi nodes in IR
empty_cnt=$( (rg -n "\bphi\b" "$irfile" || true) | (rg -v "\[" || true) | wc -l | tr -d ' ' )
if [ "${empty_cnt:-0}" != "0" ]; then
echo "[FAIL] Empty PHI detected in $irfile" >&2
rg -n "\bphi\b" "$irfile" | rg -v "\[" || true
exit 2
fi
echo "[OK] LLVM PHI hygiene (const ret) passed"
exit 0

View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/llvm_if_phi_ret.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release --features llvm)" >&2
exit 1
fi
export NYASH_LLVM_USE_HARNESS=1
export NYASH_LLVM_SANITIZE_EMPTY_PHI=1
irfile="$root/tmp/$(basename "$src" .nyash)_llvm.ll"
mkdir -p "$root/tmp"
NYASH_LLVM_DUMP_IR="$irfile" "$bin" --backend llvm "$src" >/dev/null 2>&1 || true
if [ ! -s "$irfile" ]; then
echo "[FAIL] IR not dumped for $src" >&2
exit 2
fi
# No empty phi nodes in IR
empty_cnt=$( (rg -n "\bphi\b" "$irfile" || true) | (rg -v "\[" || true) | wc -l | tr -d ' ' )
if [ "${empty_cnt:-0}" != "0" ]; then
echo "[FAIL] Empty PHI detected in $irfile" >&2
rg -n "\bphi\b" "$irfile" | rg -v "\[" || true
exit 2
fi
echo "[OK] LLVM PHI hygiene (if phi ret) passed"
exit 0

View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/llvm_phi_if_min.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release --features llvm)" >&2
exit 1
fi
export NYASH_LLVM_USE_HARNESS=1
export NYASH_LLVM_SANITIZE_EMPTY_PHI=1
irfile="$root/tmp/$(basename "$src" .nyash)_llvm.ll"
mkdir -p "$root/tmp"
NYASH_LLVM_DUMP_IR="$irfile" "$bin" --backend llvm "$src" >/dev/null 2>&1 || true
if [ ! -s "$irfile" ]; then
echo "[FAIL] IR not dumped for $src" >&2
exit 2
fi
# No empty phi nodes in IR
empty_cnt=$( (rg -n "\bphi\b" "$irfile" || true) | (rg -v "\[" || true) | wc -l | tr -d ' ' )
if [ "${empty_cnt:-0}" != "0" ]; then
echo "[FAIL] Empty PHI detected in $irfile" >&2
rg -n "\bphi\b" "$irfile" | rg -v "\[" || true
exit 2
fi
echo "[OK] LLVM PHI hygiene (min if) passed"
exit 0

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

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/if/assign_three_vars.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_MIR_TRACE_HINTS=1
out=$({ "$bin" --backend vm "$src"; } 2>&1 || true)
echo "$out" | rg -q "\[mir\]\[hint\] JoinResult\(a\)" || { echo "[FAIL] missing JoinResult(a)" >&2; echo "$out" >&2; exit 2; }
echo "$out" | rg -q "\[mir\]\[hint\] JoinResult\(b\)" || { echo "[FAIL] missing JoinResult(b)" >&2; echo "$out" >&2; exit 2; }
echo "$out" | rg -q "\[mir\]\[hint\] JoinResult\(c\)" || { echo "[FAIL] missing JoinResult(c)" >&2; echo "$out" >&2; exit 2; }
echo "[OK] MIR hints JoinResult for three vars"
exit 0

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/if/assign_two_vars.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_MIR_TRACE_HINTS=1
out=$({ "$bin" --backend vm "$src"; } 2>&1 || true)
echo "$out" | rg -q "\[mir\]\[hint\] JoinResult\(x\)" || { echo "[FAIL] missing JoinResult(x)" >&2; echo "$out" >&2; exit 2; }
echo "$out" | rg -q "\[mir\]\[hint\] JoinResult\(y\)" || { echo "[FAIL] missing JoinResult(y)" >&2; echo "$out" >&2; exit 2; }
echo "[OK] MIR hints JoinResult for two vars"
exit 0

View File

@ -0,0 +1,31 @@
#!/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
out_jsonl="$root/tmp/mir_hints_basic.jsonl"
rm -f "$out_jsonl"
# Emit scope + join hints into JSONL file (no stderr noise)
export NYASH_PARSER_STAGE3=1
export NYASH_MIR_HINTS="jsonl=$out_jsonl|scope|join"
# Run two small samples that exercise both kinds (errors are tolerated, we only need hints emission)
"$bin" --backend vm "$root/apps/tests/macro/exception/expr_postfix_direct.nyash" >/dev/null 2>&1 || true
"$bin" --backend vm "$root/apps/tests/macro/if/assign_both_branches.nyash" >/dev/null 2>&1 || true
test -s "$out_jsonl" || { echo "[FAIL] hints jsonl not created" >&2; exit 2; }
# Basic presence checks (dont overfit exact ids)
rg -q '"kind":"ScopeEnter"' "$out_jsonl" || { echo "[FAIL] ScopeEnter not found in jsonl" >&2; exit 2; }
rg -q '"kind":"JoinResult"' "$out_jsonl" || { echo "[FAIL] JoinResult not found in jsonl" >&2; exit 2; }
echo "[OK] MIR hints JSONL basic smoke passed ($out_jsonl)"
exit 0

View File

@ -0,0 +1,27 @@
#!/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
export NYASH_MIR_HINTS="trace|scope|join"
src1="apps/tests/macro/exception/expr_postfix_direct.nyash"
out=$({ "$bin" --backend vm "$root/$src1" 1>/dev/null; } 2>&1 || true)
# Accept placeholder ids for now; assert presence only (exception scope)
echo "$out" | rg -F -q "[mir][hint] ScopeEnter(" || { echo "[FAIL] missing ScopeEnter in try/catch/cleanup case" >&2; echo "$out" >&2; exit 2; }
# Now check join on a basic if-assign case (existing sample)
src2="apps/tests/macro/if/assign_both_branches.nyash"
out2=$({ "$bin" --backend vm "$root/$src2" 1>/dev/null; } 2>&1 || true)
echo "$out2" | rg -F -q "[mir][hint] JoinResult(" || { echo "[FAIL] missing JoinResult in simple if-assign case" >&2; echo "$out2" >&2; exit 2; }
echo "[OK] MIR hints (scope+join) observed in loop+trycatch case"
exit 0

View File

@ -0,0 +1,30 @@
#!/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_MIR_TRACE_HINTS=1
# Case 1: loop body induces scope enter/leave and loop header/latch hints
src1="apps/tests/macro/loopform/simple.nyash"
out1=$({ "$bin" --backend vm "$src1" 1>/dev/null; } 2>&1 || true)
echo "$out1" | rg -q "\[mir\]\[hint\] LoopHeader" || { echo "[FAIL] missing LoopHeader" >&2; exit 2; }
echo "$out1" | rg -q "\[mir\]\[hint\] LoopLatch" || { echo "[FAIL] missing LoopLatch" >&2; exit 2; }
echo "$out1" | rg -q "\[mir\]\[hint\] ScopeEnter\([1-9][0-9]*\)" || { echo "[FAIL] missing non-zero ScopeEnter for loop body" >&2; echo "$out1" >&2; exit 2; }
echo "$out1" | rg -q "\[mir\]\[hint\] ScopeLeave\([1-9][0-9]*\)" || { echo "[FAIL] missing non-zero ScopeLeave for loop body" >&2; echo "$out1" >&2; exit 2; }
# Case 2: if branches induce scope enter/leave
src2="apps/tests/macro/if/assign_two_vars.nyash"
out2=$({ "$bin" --backend vm "$src2" 1>/dev/null; } 2>&1 || true)
echo "$out2" | rg -q "\[mir\]\[hint\] ScopeEnter\([1-9][0-9]*\)" || { echo "[FAIL] missing non-zero ScopeEnter for if-branch" >&2; echo "$out2" >&2; exit 2; }
echo "$out2" | rg -q "\[mir\]\[hint\] ScopeLeave\([1-9][0-9]*\)" || { echo "[FAIL] missing non-zero ScopeLeave for if-branch" >&2; echo "$out2" >&2; exit 2; }
echo "[OK] MIR scope hints for loop and if passed"
exit 0

View File

@ -0,0 +1,23 @@
#!/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
# Enable Stage-3 for postfix catch/cleanup; enable MIR hint traces
export NYASH_PARSER_STAGE3=1
export NYASH_MIR_HINTS="trace|scope|join"
src="apps/tests/macro/exception/expr_postfix_direct.nyash"
out=$({ "$bin" --backend vm "$root/$src" 1>/dev/null; } 2>&1 || true)
echo "$out" | rg -q "\[mir\]\[hint\] ScopeEnter\([1-9][0-9]*\)" || { echo "[FAIL] missing non-zero ScopeEnter for try/catch scope" >&2; echo "$out" >&2; exit 2; }
echo "$out" | rg -q "\[mir\]\[hint\] ScopeLeave\([1-9][0-9]*\)" || { echo "[FAIL] missing non-zero ScopeLeave for try/catch scope" >&2; echo "$out" >&2; exit 2; }
echo "[OK] MIR scope hints with postfix try/catch/cleanup passed"
exit 0

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/if/assign_two_vars.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_SCOPEBOX_ENABLE=1
out=$("$bin" --backend vm "$src" 2>/dev/null || true)
# Expect two lines printed (x and y). Just check exit success and non-empty
if [ -n "${out//$'\n'/}" ]; then
echo "[OK] ScopeBox enabled run produced output"; exit 0
fi
echo "[FAIL] ScopeBox enabled run produced no output" >&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="$root/apps/tests/sugar/not_basic.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1
out=$("$bin" --backend vm "$src" 2>&1 | sed '/^\[entry\] Warning/d')
# Expect lines: 1 then 0
line1=$(printf '%s\n' "$out" | sed -n '1p')
line2=$(printf '%s\n' "$out" | sed -n '2p')
test "$line1" = "1" || { echo "[FAIL] not on 0 expected 1, got '$line1'" >&2; echo "$out" >&2; exit 2; }
test "$line2" = "0" || { echo "[FAIL] not on 1 expected 0, got '$line2'" >&2; echo "$out" >&2; exit 2; }
echo "[OK] not-operator smoke passed"

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
prog="$root/apps/tests/parser/semicolon_basic.nyash"
out=$(NYASH_PARSER_ALLOW_SEMICOLON=1 NYASH_VM_USE_PY=1 "$bin" --backend vm "$prog")
expected=$'A\nB'
test "$out" = "$expected" || { echo "[FAIL] semicolon_accept expected '$expected', got '$out'" >&2; exit 2; }
echo "[OK] semicolon_accept"

View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/tests/parser/semicolon_else_edge.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_PARSER_ALLOW_SEMICOLON=1
set +e
err=$("$bin" --backend vm "$src" 2>&1 >/dev/null)
code=$?
set -e
if [ "$code" -eq 0 ]; then
echo "[FAIL] parser accepted forbidden '} ; else' boundary"
exit 2
fi
echo "$err" | rg -qi 'parse error' || { echo "[FAIL] parser did not report parse error" >&2; echo "$err" >&2; exit 2; }
echo "[OK] parser semicolon else-edge smoke passed"

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
prog="$root/apps/tests/pyvm/argv_echo.nyash"
out=$(NYASH_VM_USE_PY=1 "$bin" --backend vm "$prog" -- hello 2>/dev/null)
test "$out" = "hello" || { echo "[FAIL] pyvm argv inject expected 'hello', got '$out'" >&2; exit 2; }
echo "[OK] pyvm argv inject"

View File

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

View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_MINIVM_READ_STDIN=1
# cond=1 -> then prints "T" only
json_then='{"kind":"Program","statements":[{"kind":"If","condition":{"kind":"Literal","value":{"type":"int","value":1}},"then_body":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"T"}}}],"else_body":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"F"}}}]}]}'
out=$(printf '%s' "$json_then" | "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -qx 'T' || { echo "[FAIL] then branch did not print T only" >&2; echo "$out" >&2; exit 2; }
# cond=0 -> else prints "F" only
json_else='{"kind":"Program","statements":[{"kind":"If","condition":{"kind":"Literal","value":{"type":"int","value":0}},"then_body":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"T"}}}],"else_body":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"F"}}}]}]}'
out=$(printf '%s' "$json_else" | "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -qx 'F' || { echo "[FAIL] else branch did not print F only" >&2; echo "$out" >&2; exit 2; }
echo "[OK] mini-vm if literal branch smoke passed"

View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_MINIVM_READ_STDIN=1
# BinaryOp int + int → 46
json1='{"kind":"Program","statements":[{"kind":"Print","expression":{"kind":"BinaryOp","operator":"+","left":{"kind":"Literal","value":{"type":"int","value":12}},"right":{"kind":"Literal","value":{"type":"int","value":34}}}}]}'
out1=$(printf '%s' "$json1" | "$bin" --backend vm "$src" 2>&1)
echo "$out1" | rg -qx '46' || { echo "[FAIL] BinaryOp int+int failed" >&2; echo "$out1" >&2; exit 2; }
echo "[OK] mini-vm binop (int) smoke passed"

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
# BinaryOp int + int → addition (12 + 34 = 46)
export NYASH_MINIVM_READ_STDIN=1
json='{"kind":"Program","statements":[{"kind":"Print","expression":{"kind":"BinaryOp","operator":"+","left":{"kind":"Literal","value":{"type":"int","value":12}},"right":{"kind":"Literal","value":{"type":"int","value":34}}}}]}'
out=$(printf '%s' "$json" | NYASH_VM_USE_PY=1 "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -qx '46' || { echo "[FAIL] BinaryOp int+int failed" >&2; echo "$out" >&2; exit 2; }
echo "[OK] mini-vm binop int+int smoke passed"

View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_MINIVM_READ_STDIN=1
# Single comparison: 1 < 2 → 1
json='{"kind":"Program","statements":[
{"kind":"Print","expression":{"kind":"Compare","operation":"<","lhs":{"kind":"Literal","value":{"type":"int","value":1}},"rhs":{"kind":"Literal","value":{"type":"int","value":2}}}}
]}'
out=$(printf '%s' "$json" | "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -qx '1' || { echo "[FAIL] Compare (<) failed" >&2; echo "$out" >&2; exit 2; }
echo "[OK] mini-vm compare (<) smoke passed"

View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_MINIVM_READ_STDIN=1
json='{"kind":"Program","statements":[
{"kind":"Print","expression":{"kind":"FunctionCall","name":"echo","arguments":[{"kind":"Literal","value":{"type":"string","value":"hello"}}]}},
{"kind":"Print","expression":{"kind":"FunctionCall","name":"itoa","arguments":[{"kind":"Literal","value":{"type":"int","value":123}}]}}
]}'
out=$(printf '%s' "$json" | "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -q '^hello$' || { echo "[FAIL] line1 not hello" >&2; echo "$out" >&2; exit 2; }
echo "$out" | rg -q '^123$' || { echo "[FAIL] line2 not 123" >&2; echo "$out" >&2; exit 2; }
echo "[OK] mini-vm print functioncall literal smoke passed"

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
prog="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
# Minimal AST JSON with a single print of int literal 42
json='{"kind":"Program","statements":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"int","value":42}}}]}'
out=$(NYASH_VM_USE_PY=1 "$bin" --backend vm "$prog" -- "$json" 2>/dev/null)
test "$out" = "42" || { echo "[FAIL] mini_vm_print_literal expected 42, got '$out'" >&2; exit 2; }
echo "[OK] mini_vm_print_literal"
exit 0

View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_MINIVM_READ_STDIN=1
json='{"kind":"Program","statements":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"hello"}}},{"kind":"Print","expression":{"kind":"Literal","value":{"type":"int","value":123}}}]}'
out=$(printf '%s' "$json" | "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -q '^hello$' || { echo "[FAIL] line1 not hello" >&2; echo "$out" >&2; exit 2; }
echo "$out" | rg -q '^123$' || { echo "[FAIL] line2 not 123" >&2; echo "$out" >&2; exit 2; }
echo "[OK] mini-vm print multi literal smoke passed"

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_MINIVM_READ_STDIN=1
json='{"kind":"Program","statements":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"string","value":"hello"}}}]}'
out=$(printf '%s' "$json" | "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -q '^hello$' || { echo "[FAIL] mini-vm print string literal failed" >&2; echo "$out" >&2; exit 2; }
echo "[OK] mini-vm print string literal smoke passed"

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/selfhost-vm/mini_vm.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
export NYASH_MINIVM_READ_STDIN=1
json='{"kind":"Program","statements":[{"kind":"Print","expression":{"kind":"Literal","value":{"type":"int","value":123}}}]}'
out=$(printf '%s' "$json" | "$bin" --backend vm "$src" 2>&1)
echo "$out" | rg -q '^123$' || { echo "[FAIL] mini-vm stdin loader did not print 123" >&2; echo "$out" >&2; exit 2; }
echo "[OK] mini-vm stdin loader smoke passed"

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/tests/strings/byte_ascii_demo.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
unset NYASH_MINIVM_READ_STDIN || true
out=$("$bin" --backend vm "$src" 2>/dev/null)
want=$(printf "15\n5\nworld\n")
test "$out" = "$want" || { echo "[FAIL] byte ascii smoke: expected\\n$want\\ngot\\n$out" >&2; exit 2; }
echo "[OK] byte ascii smoke"

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="$root/apps/tests/strings/utf8_cp_demo.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_VM_USE_PY=1
unset NYASH_MINIVM_READ_STDIN || true
out=$("$bin" --backend vm "$src" 2>/dev/null)
want=$(printf "3\n1\n1\né𝄞\n")
test "$out" = "$want" || { echo "[FAIL] utf8 cp smoke: expected\\n$want\\ngot\\n$out" >&2; exit 2; }
echo "[OK] utf8 cp smoke"