factor/core/compiler/compiler.factor

59 lines
1.5 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2004, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel namespaces arrays sequences io inference.backend
2007-12-24 19:40:09 -05:00
generator debugger math.parser prettyprint words words.private
continuations vocabs assocs alien.compiler dlists optimizer
definitions ;
2007-09-20 18:09:08 -04:00
IN: compiler
SYMBOL: compiler-hook
: compile-begins ( word -- )
compiler-hook get [ call ] when*
"quiet" get [ drop ] [ "Compiling " write . flush ] if ;
: compiled-usage ( word -- seq )
#! XXX
usage [ word? ] subset ;
: ripple-up ( word effect -- )
over "compiled-effect" word-prop =
[ drop ] [
compiled-usage
[ "was-compiled" word-prop ] subset
[ queue-compile ] each
] if ;
: save-effect ( word effect -- )
over t "was-compiled" set-word-prop
"compiled-effect" set-word-prop ;
: (compile) ( word -- )
dup compiling? not over compound? and [
[
dup compile-begins
dup word-dataflow optimize >r over dup r> generate
] [
2007-12-24 20:56:23 -05:00
print-error f
] recover
2dup ripple-up save-effect
] [ drop ] if ;
: compile ( words -- )
[
<dlist> compile-queue set
H{ } clone compiled-xts set
[ queue-compile ] each
compile-queue get [ (compile) ] dlist-slurp
2007-12-24 19:40:09 -05:00
compiled-xts get >alist modify-code-heap
] with-scope ; inline
: compile-quot ( quot -- word )
2007-12-24 19:40:09 -05:00
[ define-temp ] with-compilation-unit ;
2007-09-20 18:09:08 -04:00
: compile-call ( quot -- )
compile-quot execute ;
2007-09-20 18:09:08 -04:00
: compile-all ( -- )
2007-12-24 19:40:09 -05:00
all-words compile ;