Robuuster returns in javascript.

This commit is contained in:
2026-05-28 17:44:53 +02:00
parent 36b8b5de78
commit 6ffc11d2b1
4 changed files with 47 additions and 70 deletions
+6 -25
View File
@@ -1439,32 +1439,13 @@ if (~a !== false) return ~a;" tmp (compile-expr arg) tmp tmp)))
[(list f args ...) (compile-call f args)]
[_ (literal->js d)]))
(define (top-tail-returnable? d)
(match d
[(list 'define _ ...) #f]
[(list 'define-values _ ...) #f]
[(list 'define-class _ ...) #f]
[(list 'set! _ ...) #f]
[(list 'vector-set! _ ...) #f]
[(list 'set-prop! _ ...) #f]
[(list 'delete-prop! _ ...) #f]
[(list 'while _ ...) #f]
[(list 'for _ ...) #f]
;; Top-level js is statement/program output. with-handlers may contain
;; a handler used only for side effects; compiling it as an implicit
;; tail return would emit return statements inside the generated
;; try/catch and prematurely leave the caller's wrapper. Use
;; js/expression when the value of with-handlers is needed.
[(list 'with-handlers _ ...) #f]
[_ #t]))
(define (compile-top forms)
(cond
[(null? forms) ""]
[(top-tail-returnable? (last forms))
(compile-body forms #:return-last? #t)]
[else
(compile-body forms #:return-last? #f)])))
;; A js form produces JavaScript program/statement text. It must be valid
;; when handed directly to a WebView run/evaluateJavaScript entry point, so
;; it may not invent top-level return statements. Return insertion still
;; happens in expression contexts and function bodies, where JavaScript
;; return is syntactically valid.
(compile-body forms #:return-last? #f)))
(define-syntax (js stx)
(syntax-case stx ()