factor/unfinished/compiler/tree/propagation/simple/simple.factor

97 lines
2.7 KiB
Factor
Raw Normal View History

2008-07-20 05:24:37 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: fry accessors kernel sequences assocs words namespaces
2008-07-22 05:45:03 -04:00
classes.algebra combinators classes
compiler.tree
compiler.tree.propagation.info
compiler.tree.propagation.nodes
2008-07-20 05:24:37 -04:00
compiler.tree.propagation.constraints ;
IN: compiler.tree.propagation.simple
M: #introduce propagate-before
2008-07-22 05:45:03 -04:00
object <class-info> swap values>> [ set-value-info ] with each ;
2008-07-20 05:24:37 -04:00
M: #push propagate-before
2008-07-22 05:45:03 -04:00
[ literal>> value>> <literal-info> ] [ out-d>> first ] bi
set-value-info ;
: refine-value-infos ( classes values -- )
[ refine-value-info ] 2each ;
: class-infos ( classes -- infos )
[ <class-info> ] map ;
: set-value-infos ( infos values -- )
[ set-value-info ] 2each ;
2008-07-20 05:24:37 -04:00
M: #declare propagate-before
[ [ in-d>> ] [ out-d>> ] bi are-copies-of ]
2008-07-22 05:45:03 -04:00
[
[ declaration>> class-infos ] [ out-d>> ] bi
refine-value-infos
] bi ;
2008-07-20 05:24:37 -04:00
M: #shuffle propagate-before
2008-07-22 05:45:03 -04:00
[ out-d>> dup ] [ mapping>> ] bi
'[ , at ] map swap are-copies-of ;
2008-07-20 05:24:37 -04:00
M: #>r propagate-before
[ in-d>> ] [ out-r>> ] bi are-copies-of ;
M: #r> propagate-before
[ in-r>> ] [ out-d>> ] bi are-copies-of ;
M: #copy propagate-before
[ in-d>> ] [ out-d>> ] bi are-copies-of ;
2008-07-22 05:45:03 -04:00
: predicate-constraints ( value class boolean-value -- constraint )
[ [ <class-constraint> ] dip if-true ]
[ [ class-not <class-constraint> ] dip if-false ]
3bi <conjunction> ;
2008-07-20 05:24:37 -04:00
2008-07-22 05:45:03 -04:00
: compute-constraints ( #call -- constraint )
dup word>> +constraints+ word-prop [ call assume ] [
dup word>> predicate?
2008-07-20 05:24:37 -04:00
[
2008-07-22 05:45:03 -04:00
[ in-d>> first ]
[ word>> "predicating" word-prop ]
[ out-d>> first ]
tri predicate-constraints assume
] [ drop ] if
2008-07-20 05:24:37 -04:00
] if* ;
2008-07-22 05:45:03 -04:00
: default-output-value-infos ( node -- infos )
dup word>> "default-output-classes" word-prop [
class-infos
] [
out-d>> length object <class-info> <repetition>
] ?if ;
2008-07-20 05:24:37 -04:00
2008-07-22 05:45:03 -04:00
: call-outputs-quot ( node quot -- infos )
[ in-d>> [ value-info ] map ] dip with-datastack ;
2008-07-20 05:24:37 -04:00
2008-07-22 05:45:03 -04:00
: output-value-infos ( node word -- infos )
dup word>> +outputs+ word-prop
[ call-outputs-quot ] [ default-output-value-infos ] if* ;
2008-07-20 05:24:37 -04:00
M: #call propagate-before
[ compute-constraints ]
2008-07-22 05:45:03 -04:00
[ [ output-value-infos ] [ out-d>> ] bi set-value-infos ] bi ;
2008-07-20 05:24:37 -04:00
M: node propagate-before drop ;
M: #call propagate-after
2008-07-22 05:45:03 -04:00
dup word>> "input-classes" word-prop dup [
class-infos swap in-d>> refine-value-infos
] [
2drop
] if ;
2008-07-20 05:24:37 -04:00
M: node propagate-after drop ;
: annotate-node ( node -- )
2008-07-22 05:45:03 -04:00
dup node-values [ dup value-info ] H{ } map>assoc >>info drop ;
M: node propagate-around
[ propagate-before ] [ annotate-node ] [ propagate-after ] tri ;