HS: namespaced def + script-tag global functions (+3 tests)

Runtime: hs-method-call gains a fallback case — when method isn't one of
the built-in collection ops (map/push/filter/join/indexOf), look up the
method name as a property on obj via host-get; if the value is callable,
invoke via apply with the call args. This makes namespaced calls like
`utils.foo()` work when utils is an SX dict whose foo entry is an SX fn.

Generator: hand-rolled deftests for the 3 cluster-35 tests:
- `is called synchronously` and `can call asynchronously`: pre-evaluate
  the script-tag def via `(eval-expr-cek (hs-to-sx (first (hs-parse
  (hs-tokenize "def foo() ... end")))))` so foo lands in the global eval
  env, then build a click div via dom-set-attr + hs-boot-subtree! and
  exercise it via dom-dispatch click.
- `functions can be namespaced`: hand-build `(define utils (dict))` then
  `(host-set! utils "foo" __utils_foo)` (the def is registered under a
  fresh sym since the parser doesn't yet support `def utils.foo()` dotted
  names), and rely on the new hs-method-call fallback to dispatch
  `utils.foo()` through host-get/apply.

Removed the 3 def entries from SKIP_TEST_NAMES.

hs-upstream-def: 24/27 → 27/27. Smoke 0-195 unchanged at 172/195.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-25 12:37:39 +00:00
parent 7bbffa0401
commit 122053eda3
4 changed files with 122 additions and 9 deletions

View File

@@ -2115,7 +2115,12 @@
-1
(if (= (first lst) item) i (idx-loop (rest lst) (+ i 1))))))
(idx-loop obj 0)))
(true nil))))
(true
(let
((fn-val (host-get obj method)))
(cond
((and fn-val (callable? fn-val)) (apply fn-val args))
(true nil)))))))
(define hs-beep (fn (v) v))
@@ -2494,3 +2499,9 @@
((nil? b) false)
((= a b) true)
(true (hs-dom-is-ancestor? a (dom-parent b))))))
(define
hs-win-call
(fn
(fn-name args)
(let ((fn (host-global fn-name))) (if fn (host-call-fn fn args) nil))))