factor/basis/compiler/tree/finalization/finalization.factor

47 lines
1.3 KiB
Factor
Raw Normal View History

! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors sequences words memoize combinators
classes classes.builtin classes.tuple math.partial-dispatch
fry assocs
2008-09-02 03:02:05 -04:00
compiler.tree
compiler.tree.combinators
compiler.tree.propagation.info
compiler.tree.late-optimizations ;
IN: compiler.tree.finalization
! This is a late-stage optimization.
! See the comment in compiler.tree.late-optimizations.
! This pass runs after propagation, so that it can expand
! type predicates; these cannot be expanded before
2008-10-23 06:55:50 -04:00
! propagation since we need to see 'fixnum?' instead of
! 'tag 0 eq?' and so on, for semantic reasoning.
GENERIC: finalize* ( node -- nodes )
2008-10-08 04:51:44 -04:00
: finalize ( nodes -- nodes' ) [ finalize* ] map-nodes ;
: splice-final ( quot -- nodes ) splice-quot finalize ;
MEMO: cached-expansion ( word -- nodes )
2008-10-08 04:51:44 -04:00
def>> splice-final ;
GENERIC: finalize-word ( #call word -- nodes )
M: predicate finalize-word
"predicating" word-prop {
{ [ dup builtin-class? ] [ drop word>> cached-expansion ] }
{ [ dup tuple-class? ] [ drop word>> def>> splice-final ] }
[ drop ]
} cond ;
M: math-partial finalize-word
dup primitive? [ drop ] [ nip cached-expansion ] if ;
M: word finalize-word drop ;
2008-09-02 03:02:05 -04:00
M: #call finalize*
dup word>> finalize-word ;
2008-09-02 03:02:05 -04:00
M: node finalize* ;