Fix compiler: handle clause-syntax cond — (cond (test body) ...)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
compile-cond expected flat syntax (cond test body test body ...) but hs-parse uses clause syntax (cond (test body) (test body) ...). The compiler treated the whole clause as the test expression, compiling ((and ...) (do ...)) as a function call — which tried to call the and-result as a function, producing "not callable: false" JIT errors. Now detects clause syntax (first arg is a list whose first element is also a list) and flattens to the expected format before compilation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -724,14 +724,17 @@
|
|||||||
compile-cond
|
compile-cond
|
||||||
(fn
|
(fn
|
||||||
(em args scope tail?)
|
(em args scope tail?)
|
||||||
"Compile (cond test1 body1 test2 body2 ... :else fallback)."
|
"Compile (cond test1 body1 test2 body2 ... :else fallback).\n Also handles clause syntax: (cond (test1 body1) (test2 body2) ...)."
|
||||||
|
(let
|
||||||
|
((flat-args (if (and (not (empty? args)) (list? (first args)) (> (len (first args)) 1) (list? (first (first args)))) (reduce (fn (acc clause) (if (list? clause) (append acc clause) (append acc (list clause)))) (list) args) args)))
|
||||||
(if
|
(if
|
||||||
(< (len args) 2)
|
(< (len flat-args) 2)
|
||||||
(emit-op em 2)
|
(emit-op em 2)
|
||||||
(let
|
(let
|
||||||
((test (first args))
|
((test (nth flat-args 0))
|
||||||
(body (nth args 1))
|
(body (nth flat-args 1))
|
||||||
(rest-clauses (if (> (len args) 2) (slice args 2) (list))))
|
(rest-clauses
|
||||||
|
(if (> (len flat-args) 2) (slice flat-args 2) (list))))
|
||||||
(if
|
(if
|
||||||
(or
|
(or
|
||||||
(and
|
(and
|
||||||
@@ -755,7 +758,7 @@
|
|||||||
(patch-i16
|
(patch-i16
|
||||||
em
|
em
|
||||||
end-jump
|
end-jump
|
||||||
(- (current-offset em) (+ end-jump 2)))))))))))
|
(- (current-offset em) (+ end-jump 2))))))))))))
|
||||||
(define
|
(define
|
||||||
compile-case
|
compile-case
|
||||||
(fn
|
(fn
|
||||||
|
|||||||
Reference in New Issue
Block a user