factor/library/compiler/compiler.factor

48 lines
1.2 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: compiler
USING: errors generic hashtables inference io kernel math
namespaces optimizer prettyprint sequences test threads words ;
: (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
: compile ( word -- )
2006-08-10 14:39:12 -04:00
[ (compile) ] with-compiler ;
2006-03-25 01:06:52 -05:00
: compiled ( -- ) "compile" get [ word compile ] when ; parsing
2004-12-16 19:57:03 -05:00
: try-compile ( word -- )
[ compile ] [ error. update-xt ] recover ;
2004-12-16 19:57:03 -05:00
2006-02-09 20:34:49 -05:00
: compile-vocabs ( vocabs -- )
[ 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
: compile-all ( -- ) vocabs compile-vocabs ;
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 ;
: recompile ( -- )
[
changed-words get hash-keys [ try-compile ] each
changed-words get clear-hash
] with-class<cache ;
M: compound unxref-word*
dup "infer" word-prop [
drop
] [
dup dup changed-words get set-hash
{ "infer-effect" "base-case" "no-effect" } reset-props
] if ;