2006-03-08 15:03:01 -05:00
|
|
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2004-09-06 22:39:12 -04:00
|
|
|
IN: compiler
|
2006-08-10 16:44:00 -04:00
|
|
|
USING: errors generic hashtables inference io kernel math
|
2006-08-11 16:55:43 -04:00
|
|
|
namespaces optimizer parser prettyprint sequences test threads
|
|
|
|
words ;
|
2004-09-06 22:39:12 -04:00
|
|
|
|
2006-01-19 03:03:32 -05:00
|
|
|
: (compile) ( word -- )
|
2006-08-10 14:39:12 -04:00
|
|
|
dup compiling? not over compound? and [
|
|
|
|
"Compiling " write dup . flush
|
|
|
|
dup specialized-def dataflow optimize generate
|
2006-04-28 18:38:48 -04:00
|
|
|
] [
|
2006-08-10 14:39:12 -04:00
|
|
|
drop
|
2006-04-28 18:38:48 -04:00
|
|
|
] if ;
|
2004-09-08 02:31:03 -04:00
|
|
|
|
2004-09-06 22:39:12 -04:00
|
|
|
: compile ( word -- )
|
2006-08-10 14:39:12 -04:00
|
|
|
[ (compile) ] with-compiler ;
|
2004-09-06 22:39:12 -04:00
|
|
|
|
2004-12-16 19:57:03 -05:00
|
|
|
: try-compile ( word -- )
|
2006-08-10 16:44:00 -04:00
|
|
|
[ compile ] [ error. update-xt ] recover ;
|
2004-12-16 19:57:03 -05:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: compile-vocabs ( seq -- )
|
2006-02-09 20:34:49 -05:00
|
|
|
[ words ] map concat
|
|
|
|
dup [ f "no-effect" set-word-prop ] each
|
2006-07-17 15:08:38 -04:00
|
|
|
[ try-compile ] each ;
|
2006-02-09 20:34:49 -05:00
|
|
|
|
2006-08-15 21:23:05 -04:00
|
|
|
: compile-all ( -- )
|
|
|
|
[ vocabs compile-vocabs ] with-class<cache ;
|
2005-01-06 19:10:02 -05:00
|
|
|
|
2006-03-15 15:58:22 -05:00
|
|
|
: compile-quot ( quot -- word )
|
2006-05-29 04:27:30 -04:00
|
|
|
define-temp "compile" get [ dup compile ] when ;
|
2006-03-15 15:58:22 -05:00
|
|
|
|
|
|
|
: compile-1 ( quot -- ) compile-quot execute ;
|
2006-08-10 16:44:00 -04:00
|
|
|
|
|
|
|
: recompile ( -- )
|
2006-08-11 16:55:43 -04:00
|
|
|
#! If we are recompiling a lot of words, we can save time
|
|
|
|
#! with the class<cache.
|
|
|
|
changed-words get [
|
|
|
|
dup hash-keys [ [ try-compile ] each clear-hash ]
|
|
|
|
over length 20 > [ with-class<cache ] [ call ] if
|
|
|
|
] when* ;
|
|
|
|
|
|
|
|
[ recompile ] parse-hook set
|