diff --git a/lib/compiler.sx b/lib/compiler.sx index 28a8a415..94e2b963 100644 --- a/lib/compiler.sx +++ b/lib/compiler.sx @@ -387,6 +387,60 @@ (emit-op em 5)) (init forms)) (compile-expr em (last forms) scope false)))) + (= name "map") + (if + (and (= (len args) 2) (list? (first args)) (not (empty? (first args))) (= (type-of (first (first args))) "symbol") (or (= (symbol-name (first (first args))) "fn") (= (symbol-name (first (first args))) "lambda"))) + (compile-list + em + `(let ((_hf ,(first args)) (_hcl ,(nth args 1))) (let _hml ((_hacc (list)) (_hc _hcl)) (if (empty? _hc) (reverse _hacc) (_hml (cons (_hf (first _hc)) _hacc) (rest _hc))))) + scope + tail?) + (compile-call em head args scope tail?)) + (= name "filter") + (if + (and (= (len args) 2) (list? (first args)) (not (empty? (first args))) (= (type-of (first (first args))) "symbol") (or (= (symbol-name (first (first args))) "fn") (= (symbol-name (first (first args))) "lambda"))) + (compile-list + em + `(let ((_hf ,(first args)) (_hcl ,(nth args 1))) (let _hml ((_hacc (list)) (_hc _hcl)) (if (empty? _hc) (reverse _hacc) (_hml (if (_hf (first _hc)) (cons (first _hc) _hacc) _hacc) (rest _hc))))) + scope + tail?) + (compile-call em head args scope tail?)) + (= name "reduce") + (if + (and (= (len args) 3) (list? (first args)) (not (empty? (first args))) (= (type-of (first (first args))) "symbol") (or (= (symbol-name (first (first args))) "fn") (= (symbol-name (first (first args))) "lambda"))) + (compile-list + em + `(let ((_hf ,(first args)) (_hin ,(nth args 1)) (_hcl ,(nth args 2))) (let _hml ((_hacc _hin) (_hc _hcl)) (if (empty? _hc) _hacc (_hml (_hf _hacc (first _hc)) (rest _hc))))) + scope + tail?) + (compile-call em head args scope tail?)) + (= name "for-each") + (if + (and (= (len args) 2) (list? (first args)) (not (empty? (first args))) (= (type-of (first (first args))) "symbol") (or (= (symbol-name (first (first args))) "fn") (= (symbol-name (first (first args))) "lambda"))) + (compile-list + em + `(let ((_hf ,(first args)) (_hcl ,(nth args 1))) (let _hml ((_hc _hcl)) (if (empty? _hc) nil (begin (_hf (first _hc)) (_hml (rest _hc)))))) + scope + tail?) + (compile-call em head args scope tail?)) + (= name "some") + (if + (and (= (len args) 2) (list? (first args)) (not (empty? (first args))) (= (type-of (first (first args))) "symbol") (or (= (symbol-name (first (first args))) "fn") (= (symbol-name (first (first args))) "lambda"))) + (compile-list + em + `(let ((_hf ,(first args)) (_hcl ,(nth args 1))) (let _hml ((_hc _hcl)) (if (empty? _hc) false (let ((_hr (_hf (first _hc)))) (if _hr _hr (_hml (rest _hc))))))) + scope + tail?) + (compile-call em head args scope tail?)) + (= name "every?") + (if + (and (= (len args) 2) (list? (first args)) (not (empty? (first args))) (= (type-of (first (first args))) "symbol") (or (= (symbol-name (first (first args))) "fn") (= (symbol-name (first (first args))) "lambda"))) + (compile-list + em + `(let ((_hf ,(first args)) (_hcl ,(nth args 1))) (let _hml ((_hc _hcl)) (if (empty? _hc) true (if (_hf (first _hc)) (_hml (rest _hc)) false)))) + scope + tail?) + (compile-call em head args scope tail?)) :else (compile-call em head args scope tail?))))))) (define compile-if diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index aedfc056..b3ec6d93 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -3351,3 +3351,13 @@ (bind-path! (host-global "window") name-path) wrapper))))) + +;; Hyperscript's tokenizer/parser are recursive-descent combinators (hs-tokenize, +;; hs-stream-*, hs-parse-*). Like every other guest interpreter (scheme-*, er-*, +;; pl-*, cl-*, js-*, hk-*), their recursion web miscompiles under the bytecode JIT +;; (the parser-combinator JIT bug — see project_jit_bytecode_bug). Declare the whole +;; hs- namespace interpret-only: it runs on the CEK, where it is correct. Hyperscript +;; is compiled to SX once at author/load time (not per request), so there is no +;; serve-time perf cost. With this, run_tests --jit == CEK (4862/1082, zero +;; JIT-specific failures). +(jit-exclude! "hs-*")