84 lines
2.4 KiB
Factor
84 lines
2.4 KiB
Factor
! Copyright (C) 2009, 2010 Slava Pestov.
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
USING: assocs accessors classes.algebra fry generic kernel math
|
|
namespaces sequences words ;
|
|
IN: stack-checker.dependencies
|
|
|
|
! Words that the current quotation depends on
|
|
SYMBOL: dependencies
|
|
|
|
SYMBOLS: inlined-dependency class-dependency flushed-dependency called-dependency ;
|
|
|
|
: index>= ( obj1 obj2 seq -- ? )
|
|
[ index ] curry bi@ >= ;
|
|
|
|
: dependency>= ( how1 how2 -- ? )
|
|
{ called-dependency class-dependency flushed-dependency inlined-dependency }
|
|
index>= ;
|
|
|
|
: strongest-dependency ( how1 how2 -- how )
|
|
[ called-dependency or ] bi@ [ dependency>= ] most ;
|
|
|
|
: depends-on ( word how -- )
|
|
over primitive? [ 2drop ] [
|
|
dependencies get dup [
|
|
swap '[ _ strongest-dependency ] change-at
|
|
] [ 3drop ] if
|
|
] if ;
|
|
|
|
! Generic words that the current quotation depends on
|
|
SYMBOL: generic-dependencies
|
|
|
|
: ?class-or ( class class/f -- class' )
|
|
[ class-or ] when* ;
|
|
|
|
: depends-on-generic ( class generic -- )
|
|
generic-dependencies get dup
|
|
[ [ ?class-or ] change-at ] [ 3drop ] if ;
|
|
|
|
! Conditional dependencies are re-evaluated when classes change;
|
|
! if any fail, the word is recompiled
|
|
SYMBOL: conditional-dependencies
|
|
|
|
GENERIC: satisfied? ( dependency -- ? )
|
|
|
|
: conditional-dependency ( ... class -- )
|
|
boa conditional-dependencies get
|
|
dup [ push ] [ 2drop ] if ; inline
|
|
|
|
TUPLE: depends-on-class<= class1 class2 ;
|
|
|
|
: depends-on-class<= ( class1 class2 -- )
|
|
\ depends-on-class<= conditional-dependency ;
|
|
|
|
M: depends-on-class<= satisfied?
|
|
[ class1>> ] [ class2>> ] bi class<= ;
|
|
|
|
TUPLE: depends-on-classes-disjoint class1 class2 ;
|
|
|
|
: depends-on-classes-disjoint ( class1 class2 -- )
|
|
\ depends-on-classes-disjoint conditional-dependency ;
|
|
|
|
M: depends-on-classes-disjoint satisfied?
|
|
[ class1>> ] [ class2>> ] bi classes-intersect? not ;
|
|
|
|
TUPLE: depends-on-method class generic method ;
|
|
|
|
: depends-on-method ( class generic method -- )
|
|
\ depends-on-method conditional-dependency ;
|
|
|
|
M: depends-on-method satisfied?
|
|
[ [ class>> ] [ generic>> ] bi method-for-class ] [ method>> ] bi eq? ;
|
|
|
|
: init-dependencies ( -- )
|
|
H{ } clone dependencies set
|
|
H{ } clone generic-dependencies set
|
|
V{ } clone conditional-dependencies set ;
|
|
|
|
: without-dependencies ( quot -- )
|
|
[
|
|
dependencies off
|
|
generic-dependencies off
|
|
call
|
|
] with-scope ; inline
|