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-22 00:02:00 -04:00
|
|
|
M: callable (build-tree) f initial-recursive-state infer-quot ;
|
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-20 19:44:45 -04:00
|
|
|
: check-effect ( word effect -- )
|
2009-04-20 23:05:41 -04:00
|
|
|
swap required-stack-effect 2dup effect<=
|
|
|
|
[ 2drop ] [ effect-error ] if ;
|
2008-08-15 00:35:19 -04:00
|
|
|
|
2009-04-22 00:02:00 -04:00
|
|
|
: inline-recursive? ( word -- ? )
|
|
|
|
[ "inline" word-prop ] [ "recursive" word-prop ] bi and ;
|
2008-08-15 00:35:19 -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)
|
|
|
|
{
|
|
|
|
[ initial-recursive-state recursive-state set ]
|
2009-04-20 19:44:45 -04:00
|
|
|
[ check-no-compile ]
|
2009-04-22 00:02:00 -04:00
|
|
|
[ word-body infer-quot-here ]
|
|
|
|
[ current-effect check-effect ]
|
|
|
|
} cleave ;
|
|
|
|
|
|
|
|
: build-tree-with ( in-stack word/quot -- nodes )
|
|
|
|
[
|
|
|
|
V{ } clone stack-visitor set
|
|
|
|
[ [ >vector \ meta-d set ] [ length d-in set ] bi ]
|
|
|
|
[ (build-tree) ]
|
|
|
|
bi*
|
|
|
|
] with-infer nip ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: build-tree ( word/quot -- nodes )
|
|
|
|
[ f ] dip build-tree-with ;
|
|
|
|
|
|
|
|
:: build-sub-tree ( #call word/quot -- nodes/f )
|
2009-04-22 01:44:06 -04:00
|
|
|
#! We don't want methods on mixins to have a declaration for that mixin.
|
|
|
|
#! This slows down compiler.tree.propagation.inlining since then every
|
|
|
|
#! inlined usage of a method has an inline-dependency on the mixin, and
|
|
|
|
#! not the more specific type at the call site.
|
|
|
|
specialize-method? off
|
2009-04-22 00:02:00 -04:00
|
|
|
[
|
|
|
|
#call in-d>> word/quot build-tree-with unclip-last in-d>> :> in-d
|
|
|
|
{
|
|
|
|
{ [ dup not ] [ ] }
|
|
|
|
{ [ dup ends-with-terminate? ] [ #call out-d>> [ f swap #push ] map append ] }
|
|
|
|
[ in-d #call out-d>> #copy suffix ]
|
|
|
|
} cond
|
|
|
|
] [ dup inference-error? [ drop f ] [ rethrow ] if ] recover ;
|
2009-04-17 00:14:11 -04:00
|
|
|
|
|
|
|
: contains-breakpoints? ( word -- ? )
|
|
|
|
def>> [ word? ] filter [ "break?" word-prop ] any? ;
|