factor/basis/compiler/tree/builder/builder.factor

64 lines
1.8 KiB
Factor
Raw Normal View History

! Copyright (C) 2008, 2009 Slava Pestov.
2008-07-20 05:24:37 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-08-22 18:38:23 -04:00
USING: fry accessors quotations kernel sequences namespaces
assocs words arrays vectors hints combinators continuations
effects compiler.tree
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
: with-tree-builder ( quot -- nodes )
2008-10-20 02:56:28 -04:00
'[ V{ } clone stack-visitor set @ ]
with-infer nip ; inline
: build-tree ( quot -- nodes )
[ f initial-recursive-state infer-quot ] with-tree-builder ;
: build-tree-with ( in-stack quot -- nodes out-stack )
[
[
[ >vector \ meta-d set ]
[ f initial-recursive-state infer-quot ] bi*
] with-tree-builder
unclip-last in-d>>
2009-04-21 17:09:53 -04:00
] [ 3drop f f ] recover ;
: build-sub-tree ( #call quot -- nodes/f )
2008-08-15 00:35:19 -04:00
[ [ out-d>> ] [ in-d>> ] bi ] dip build-tree-with
{
{ [ over not ] [ 3drop f ] }
{ [ over ends-with-terminate? ] [ drop swap [ f swap #push ] map append ] }
[ rot #copy suffix ]
} cond ;
: check-no-compile ( word -- )
dup "no-compile" word-prop [ do-not-compile ] [ drop ] if ;
2008-08-15 00:35:19 -04:00
: (build-tree-from-word) ( word -- )
2008-11-16 20:42:53 -05:00
dup initial-recursive-state recursive-state set
dup [ "inline" word-prop ] [ "recursive" word-prop ] bi and
[ 1quotation ] [ specialized-def ] if
infer-quot-here ;
2008-08-15 00:35:19 -04:00
: check-effect ( word effect -- )
swap required-stack-effect 2dup effect<=
[ 2drop ] [ effect-error ] if ;
2008-08-15 00:35:19 -04:00
: finish-word ( word -- )
current-effect check-effect ;
2008-08-15 00:35:19 -04:00
: build-tree-from-word ( word -- nodes )
[
[ check-no-compile ]
[ (build-tree-from-word) ]
[ finish-word ]
tri
] with-tree-builder ;
2009-04-17 00:14:11 -04:00
: contains-breakpoints? ( word -- ? )
def>> [ word? ] filter [ "break?" word-prop ] any? ;