Paste: Type feedback
Author: | littledan |
Mode: | factor |
Date: | Sat, 30 Jan 2010 20:41:08 |
Plain Text |
USING: accessors assocs classes compiler.units generalizations
kernel locals parser sequences words fry ;
IN: type-feedback
: make-subword ( word quot effect -- word' )
[ name>> "%" dup surround <uninterned-word> dup ] 2dip
define-declared ;
CONSTANT: threshold 100
: add-hint? ( types table -- ? )
[ inc-at ] [ at threshold = ] 2bi ;
: change-word-prop ( word prop quot -- )
[ swap props>> ] dip change-at ; inline
: add-hint ( types impl -- )
[ "specializer" [ swap suffix ] change-word-prop ]
[ [ changed-effect ] with-compilation-unit ] bi ;
:: maybe-recompile ( n table impl -- )
n ndup [ class ] n napply n narray :> types
types table add-hint?
[ types impl add-hint ] when ; inline
:: define-type-feedback ( word quot effect n -- )
H{ } clone :> table
word quot effect make-subword :> impl
word table "type-feedback" set-word-prop
word impl "implementation" set-word-prop
word n "feedback-depth" set-word-prop
word
n table impl dup '[ _ _ _ maybe-recompile _ execute ]
effect define-declared ;
SYNTAX: TYPE-FEEDBACK:
(:) dup in>> length define-type-feedback ;
New Annotation