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
|
2005-12-21 02:43:41 -05:00
|
|
|
USING: compiler-backend compiler-frontend errors hashtables
|
|
|
|
inference io kernel lists math namespaces optimizer prettyprint
|
|
|
|
sequences words ;
|
2004-09-06 22:39:12 -04:00
|
|
|
|
2006-01-19 03:03:32 -05:00
|
|
|
: (compile) ( word -- )
|
2004-09-28 00:24:36 -04:00
|
|
|
#! Should be called inside the with-compiler scope.
|
2005-12-21 02:43:41 -05:00
|
|
|
dup word-def dataflow optimize linearize
|
2006-03-08 15:03:01 -05:00
|
|
|
[ split-blocks simplify generate ] hash-each ;
|
2005-12-21 02:43:41 -05:00
|
|
|
|
|
|
|
: inform-compile ( word -- ) "Compiling " write . flush ;
|
2004-09-08 02:31:03 -04:00
|
|
|
|
2004-09-28 00:24:36 -04:00
|
|
|
: compile-postponed ( -- )
|
2005-12-21 02:43:41 -05:00
|
|
|
compile-words get dup empty? [
|
|
|
|
dup pop
|
|
|
|
dup inform-compile
|
|
|
|
(compile)
|
|
|
|
compile-postponed
|
|
|
|
] unless drop ;
|
2004-09-08 02:31:03 -04:00
|
|
|
|
2004-09-06 22:39:12 -04:00
|
|
|
: compile ( word -- )
|
2004-09-28 00:24:36 -04:00
|
|
|
[ postpone-word compile-postponed ] with-compiler ;
|
2004-09-06 22:39:12 -04:00
|
|
|
|
2004-12-04 23:45:41 -05:00
|
|
|
: compiled ( -- )
|
2004-11-21 21:16:16 -05:00
|
|
|
#! Compile the most recently defined word.
|
2004-12-17 21:46:19 -05:00
|
|
|
"compile" get [ word compile ] when ; parsing
|
2004-11-22 21:12:29 -05:00
|
|
|
|
2004-12-16 19:57:03 -05:00
|
|
|
: try-compile ( word -- )
|
2005-09-21 01:12:16 -04:00
|
|
|
[ compile ] [ error. drop ] 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
|
|
|
|
[ try-compile ] each ;
|
|
|
|
|
|
|
|
: compile-all ( -- ) vocabs compile-vocabs ;
|
2005-01-06 19:10:02 -05:00
|
|
|
|
2005-09-08 22:23:54 -04:00
|
|
|
: recompile ( word -- ) dup update-xt compile ;
|
2005-08-14 01:17:25 -04:00
|
|
|
|
2005-09-04 17:07:59 -04:00
|
|
|
: compile-1 ( quot -- )
|
|
|
|
#! Compute and call a quotation.
|
|
|
|
"compile" get [
|
|
|
|
gensym [ swap define-compound ] keep dup compile execute
|
|
|
|
] [
|
|
|
|
call
|
2005-09-24 15:21:17 -04:00
|
|
|
] if ;
|