2009-04-20 19:44:45 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-07-20 05:24:37 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-04-22 00:02:00 -04:00
|
|
|
USING: fry locals accessors quotations kernel sequences namespaces
|
2009-04-20 19:44:45 -04:00
|
|
|
assocs words arrays vectors hints combinators continuations
|
|
|
|
effects compiler.tree
|
2008-11-13 01:07:45 -05:00
|
|
|
stack-checker
|
|
|
|
stack-checker.state
|
|
|
|
stack-checker.errors
|
|
|
|
stack-checker.visitor
|
|
|
|
stack-checker.backend
|
|
|
|
stack-checker.recursive-state ;
|
2008-07-20 05:24:37 -04:00
|
|
|
IN: compiler.tree.builder
|
|
|
|
|
2009-04-22 00:02:00 -04:00
|
|
|
<PRIVATE
|
2008-07-24 00:50:21 -04:00
|
|
|
|
2009-04-22 00:02:00 -04:00
|
|
|
GENERIC: (build-tree) ( quot -- )
|
2008-07-24 00:50:21 -04:00
|
|
|
|
2009-04-23 23:17:25 -04:00
|
|
|
M: callable (build-tree) infer-quot-here ;
|
2009-04-20 19:44:45 -04:00
|
|
|
|
|
|
|
: check-no-compile ( word -- )
|
|
|
|
dup "no-compile" word-prop [ do-not-compile ] [ drop ] if ;
|
2008-08-10 23:22:26 -04:00
|
|
|
|
2009-04-22 00:02:00 -04:00
|
|
|
: word-body ( word -- quot )
|
|
|
|
dup inline-recursive? [ 1quotation ] [ specialized-def ] if ;
|
|
|
|
|
|
|
|
M: word (build-tree)
|
2009-04-23 23:17:25 -04:00
|
|
|
[ check-no-compile ]
|
|
|
|
[ word-body infer-quot-here ]
|
2010-07-28 00:49:26 -04:00
|
|
|
[ required-stack-effect check-effect ] tri ;
|
2009-04-22 00:02:00 -04:00
|
|
|
|
|
|
|
: build-tree-with ( in-stack word/quot -- nodes )
|
|
|
|
[
|
2009-04-23 23:17:25 -04:00
|
|
|
<recursive-state> recursive-state set
|
2009-04-22 00:02:00 -04:00
|
|
|
V{ } clone stack-visitor set
|
2012-07-20 13:48:16 -04:00
|
|
|
[ [ >vector (meta-d) set ] [ length input-count set ] bi ]
|
2009-04-22 00:02:00 -04:00
|
|
|
[ (build-tree) ]
|
|
|
|
bi*
|
|
|
|
] with-infer nip ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: build-tree ( word/quot -- nodes )
|
|
|
|
[ f ] dip build-tree-with ;
|
|
|
|
|
2009-08-09 17:29:21 -04:00
|
|
|
:: build-sub-tree ( in-d out-d word/quot -- nodes/f )
|
2010-01-20 18:06:28 -05:00
|
|
|
[
|
|
|
|
in-d word/quot build-tree-with unclip-last in-d>> :> in-d'
|
|
|
|
{
|
|
|
|
{ [ dup not ] [ ] }
|
2011-11-06 23:41:31 -05:00
|
|
|
{ [ dup ends-with-terminate? ] [ out-d [ f swap <#push> ] map append ] }
|
|
|
|
[ in-d' out-d [ [ length ] bi@ assert= ] [ <#copy> suffix ] 2bi ]
|
2010-01-20 18:06:28 -05:00
|
|
|
} cond
|
2011-11-06 23:41:31 -05:00
|
|
|
] [ dup inference-error? [ drop f ] [ rethrow ] if ] recover ;
|