! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators.short-circuit continuations
-fry generalizations kernel locals.rewrite.closures namespaces
-sequences smalltalk.ast ;
+generalizations kernel locals.rewrite locals.types sequences
+smalltalk.ast ;
IN: smalltalk.compiler.return
SYMBOL: return-continuation
{
[ receiver>> need-return-continuation? ]
[ arguments>> need-return-continuation? ]
- } 1&& ;
+ } 1|| ;
M: ast-cascade need-return-continuation?
{
[ receiver>> need-return-continuation? ]
[ messages>> need-return-continuation? ]
- } 1&& ;
+ } 1|| ;
M: ast-message need-return-continuation?
arguments>> need-return-continuation? ;
M: object need-return-continuation? drop f ;
-: make-return ( quot n block -- quot )
- need-return-continuation? [
- '[
- [
- _ _ ncurry
- [ return-continuation set ] prepose callcc1
- ] with-scope
- ]
- ] [ drop ] if
- rewrite-closures first ;
\ No newline at end of file
+:: make-return ( quot n lexenv block -- quot )
+ block need-return-continuation? [
+ quot clone [ lexenv return>> <def> '[ _ ] prepend ] change-body
+ n '[ _ _ ncurry callcc1 ]
+ ] [ quot ] if rewrite-closures first ;