diff --git a/lang/src/compiler/entry/bundle_resolver.hako b/lang/src/compiler/entry/bundle_resolver.hako new file mode 100644 index 00000000..b5bfd27b --- /dev/null +++ b/lang/src/compiler/entry/bundle_resolver.hako @@ -0,0 +1,53 @@ +// bundle_resolver.hako — Stage‑B bundling resolver (Box‑first) + +static box BundleResolver { + // Resolve and merge bundles. Returns merged prefix string or null on error. + // Policy: + // - Duplicate named modules are Fail‑Fast ([bundle/duplicate] Name) + // - --require-mod Name must appear in named bundles ([bundle/missing] Name) + // - Merge order: bundle-src* → bundle-mod* (in given order) + resolve(bundle_srcs, bundle_names, bundle_mod_srcs, require_mods) { + // Fail on duplicate names + if bundle_names != null && bundle_names.length() > 1 { + local i = 0; local n = bundle_names.length() + loop(i < n) { + local name_i = "" + bundle_names.get(i) + local j = i + 1 + loop(j < n) { + if ("" + bundle_names.get(j)) == name_i { + print("[bundle/duplicate] " + name_i) + return null + } + j = j + 1 + } + i = i + 1 + } + } + // Check required modules + if require_mods != null && require_mods.length() > 0 { + local idx = 0; local rn = require_mods.length() + loop(idx < rn) { + local need = "" + require_mods.get(idx) + local found = 0 + if bundle_names != null { + local j = 0; local bn = bundle_names.length() + loop(j < bn) { if ("" + bundle_names.get(j)) == need { found = 1 break } j = j + 1 } + } + if found == 0 { print("[bundle/missing] " + need) return null } + idx = idx + 1 + } + } + // Merge in order: bundle-src* → bundle-mod* + local merged = "" + if bundle_srcs != null { + local i = 0; local m = bundle_srcs.length() + loop(i < m) { merged = merged + bundle_srcs.get(i) + "\n" i = i + 1 } + } + if bundle_mod_srcs != null { + local i2 = 0; local m2 = bundle_mod_srcs.length() + loop(i2 < m2) { merged = merged + bundle_mod_srcs.get(i2) + "\n" i2 = i2 + 1 } + } + return merged + } +} + diff --git a/lang/src/compiler/entry/compiler_stageb.hako b/lang/src/compiler/entry/compiler_stageb.hako index d536d537..8ec9753e 100644 --- a/lang/src/compiler/entry/compiler_stageb.hako +++ b/lang/src/compiler/entry/compiler_stageb.hako @@ -188,17 +188,10 @@ static box Main { } if bundles.length() > 0 || bundle_srcs.length() > 0 { - // Concatenate bundles + body_src with newlines between blocks - local merged = "" - local i = 0 - local m = bundles.length() - loop(i < m) { merged = merged + bundles.get(i) + "\n" i = i + 1 } - // Append named bundles in order provided - i = 0 - m = bundle_srcs.length() - loop(i < m) { merged = merged + bundle_srcs.get(i) + "\n" i = i + 1 } - merged = merged + body_src - body_src = merged + include "lang/src/compiler/entry/bundle_resolver.hako" + local merged_prefix = BundleResolver.resolve(bundles, bundle_names, bundle_srcs, require_mods) + if merged_prefix == null { return 1 } + body_src = merged_prefix + body_src } // 5) Parse and emit Stage‑1 JSON v0 (Program) diff --git a/tools/smokes/v2/profiles/quick/core/core_budget_exceeded_gatec_vm.sh b/tools/smokes/v2/profiles/quick/core/core_budget_exceeded_gatec_vm.sh index e69de980..633a4019 100644 --- a/tools/smokes/v2/profiles/quick/core/core_budget_exceeded_gatec_vm.sh +++ b/tools/smokes/v2/profiles/quick/core/core_budget_exceeded_gatec_vm.sh @@ -12,13 +12,11 @@ source "$ROOT/tools/smokes/v2/lib/test_runner.sh" source "$ROOT/tools/smokes/v2/lib/stageb_helpers.sh" require_env || exit 2 -# Opt-in guard: Core budget rc mapping is still stabilizing under Gate-C. -if [ "${SMOKES_ENABLE_CORE_BUDGET:-0}" != "1" ]; then - echo "[PASS] core_budget_exceeded_gatec_vm (SKIP)" - exit 0 -fi +# Default ON: rely on Gate‑C → VM Interpreter rc mapping under step budget code='static box Main { method main(args) { local i=0; loop(true){ i=i+1 } return i } }' +# Allow fallback path for this heavy-loop canary to reduce flakiness in Stage‑B entry +export HAKO_STAGEB_ALLOW_FALLBACK=1 json=$(stageb_compile_to_json "$code") || { echo "[FAIL] core_budget_exceeded_gatec_vm (emit failed)" >&2; exit 1; } set +e diff --git a/tools/smokes/v2/profiles/quick/core/map/map_keys_size_vm.sh b/tools/smokes/v2/profiles/quick/core/map/map_keys_size_vm.sh new file mode 100644 index 00000000..86f4def7 --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/map/map_keys_size_vm.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# map_keys_size_vm.sh — Map.keys().size() positive case → expect 2 + +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=$(cat <<'NY' +static box Main { + main() { + local m = new MapBox(); + m.set("a", 1); m.set("b", 2); + local ks = m.keys(); + print(ks.size()); + return 0 + } +} +NY +) +out=$(run_nyash_vm -c "$code") +if echo "$out" | grep -qx "2"; then + echo "[PASS] map_keys_size_vm" +else + echo "[FAIL] map_keys_size_vm" >&2; echo "$out" >&2; exit 1 +fi + diff --git a/tools/smokes/v2/profiles/quick/core/map/map_values_sum_vm.sh b/tools/smokes/v2/profiles/quick/core/map/map_values_sum_vm.sh new file mode 100644 index 00000000..98461247 --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/map/map_values_sum_vm.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# map_values_sum_vm.sh — Sum Map.values via loop → expect 3 + +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=$(cat <<'NY' +static box Main { + main() { + local m = new MapBox(); + m.set("a", 1); m.set("b", 2); + local vals = m.values(); + local n = vals.size(); + local i = 0; local s = 0; + loop(i < n) { + local v = vals.get(i); + if v != null { s = s + v } + i = i + 1 + } + print(s); + return 0 + } +} +NY +) +out=$(run_nyash_vm -c "$code") +if echo "$out" | grep -qx "3"; then + echo "[PASS] map_values_sum_vm" +else + echo "[FAIL] map_values_sum_vm" >&2; echo "$out" >&2; exit 1 +fi