From e74fe8d3b080a52cc9ac2c07302d74e73f858917 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Sat, 1 Nov 2025 19:33:43 +0900 Subject: [PATCH] Docs: VM dispatch policy for length() and default quick canaries; Add array length canary; Enable json_lint in quick by default --- lang/src/vm/README.md | 9 ++++ .../v2/profiles/quick/apps/json_lint_vm.sh | 10 ++--- .../quick/core/array/array_length_vm.sh | 42 +++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 tools/smokes/v2/profiles/quick/core/array/array_length_vm.sh diff --git a/lang/src/vm/README.md b/lang/src/vm/README.md index 43fbc948..1b423c03 100644 --- a/lang/src/vm/README.md +++ b/lang/src/vm/README.md @@ -59,6 +59,15 @@ Quick profile opt‑in switches (smokes) - `SMOKES_ENABLE_OOB_STRICT=1` — Gate‑C(Core) strict OOB fail‑fast canary (`gate_c_oob_strict_fail_vm.sh`) - `SMOKES_ENABLE_LLVM_SELF_PARAM=1` — LLVM instruction boxes self‑param builder tests (const/binop/compare/branch/jump/ret) +Default quick canaries (regression) +- apps/json_lint_vm.sh — JSON Lint expected outputs (OK×10 / ERROR×6) +- core/array/array_length_vm.sh — ArrayBox.length returns 0→1→2→3 for push sequence + +Dispatch policy: length() +- String 受けに対してのみ StringBox ハンドラが length() を処理する。 +- Array/Map などは各 Box 専用ハンドラで length/len/size を処理する。 +- これにより、配列に対して誤って文字列長を返す回帰を防止する(2025‑11 修正)。 + Deprecations - `NYASH_GATE_C_DIRECT` は移行中の互換トグル(TTL)だよ。将来は Gate‑C(Core) 直行(`HAKO_GATE_C_CORE=1`)に統一予定。新しい導線では Core の実行仕様(数値=rc, diff --git a/tools/smokes/v2/profiles/quick/apps/json_lint_vm.sh b/tools/smokes/v2/profiles/quick/apps/json_lint_vm.sh index a729f39e..9baf2dc5 100644 --- a/tools/smokes/v2/profiles/quick/apps/json_lint_vm.sh +++ b/tools/smokes/v2/profiles/quick/apps/json_lint_vm.sh @@ -6,16 +6,14 @@ export SMOKES_USE_PYVM=0 require_env || exit 2 preflight_plugins || exit 2 -# Temporarily opt-in: json_lint_vm is heavy and currently trips a builder edge. -# Keep quick green; enable explicitly with SMOKES_ENABLE_JSON_LINT=1 -if [ "${SMOKES_ENABLE_JSON_LINT:-0}" != "1" ]; then - test_skip "json_lint_vm" "opt-in (set SMOKES_ENABLE_JSON_LINT=1)" && exit 0 -fi +## json_lint_vm is now default-on (regression fixed on 2025-11) +## Leave this header for context; no opt-in guard anymore. APP_DIR="$NYASH_ROOT/apps/examples/json_lint" # Note: Temporary tolerance for Void arithmetic in builder-subpaths (TTL: remove when builder fix lands) # This keeps quick green while we root-cause the Sub(Integer,Void) in Stage‑B/VM lowering. -export NYASH_VM_TOLERATE_VOID=1 +# Keep tolerance off by default; flip on if needed by environment +export NYASH_VM_TOLERATE_VOID=${NYASH_VM_TOLERATE_VOID:-0} output=$(run_nyash_vm "$APP_DIR/main.nyash" --dev) expected=$(cat << 'TXT' diff --git a/tools/smokes/v2/profiles/quick/core/array/array_length_vm.sh b/tools/smokes/v2/profiles/quick/core/array/array_length_vm.sh new file mode 100644 index 00000000..77902910 --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/array/array_length_vm.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# array_length_vm.sh — Canary: ArrayBox.length returns correct values + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +if ROOT_GIT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null); then + ROOT="$ROOT_GIT" +else + ROOT="$(cd "$SCRIPT_DIR/../../../../../../../../.." && pwd)" +fi +source "$ROOT/tools/smokes/v2/lib/test_runner.sh" +require_env || exit 2 + +code='static box Main { + main() { + local a = new ArrayBox() + print("" + a.length()) + a.push(1) + print("" + a.length()) + a.push(2) + print("" + a.length()) + a.push(3) + print("" + a.length()) + return 0 + } +}' + +output=$(run_nyash_vm -c "$code" --dev) +expected=$'0\n1\n2\n3' + +if [ "$output" = "$expected" ]; then + echo "[PASS] array_length_vm" + exit 0 +else + echo "[FAIL] array_length_vm" >&2 + echo "--- expected ---" >&2 + echo "$expected" >&2 + echo "--- actual ---" >&2 + echo "$output" >&2 + exit 1 +fi