1 ! Copyright (C) 2004, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: errors generic hashtables inference io kernel math
5 namespaces optimizer parser prettyprint sequences test threads
10 t print-warnings set-global
14 GENERIC: batch-begins ( batch-errors -- )
16 M: f batch-begins drop ;
18 GENERIC: compile-begins ( word batch-errors -- )
20 M: f compile-begins drop "Compiling " write . flush ;
22 GENERIC: compile-error ( error batch-errors -- )
26 dup inference-error-major? print-warnings get or
27 [ dup error. flush ] when drop ;
29 GENERIC: batch-ends ( batch-errors -- )
31 M: f batch-ends drop ;
33 : word-dataflow ( word -- dataflow )
35 dup "no-effect" word-prop [ no-effect ] when
36 dup dup add-recursive-state
37 [ specialized-def (dataflow) ] keep
41 : (compile) ( word -- )
42 dup compiling? not over compound? and [
43 dup batch-errors get compile-begins
44 dup word-dataflow optimize generate
50 [ (compile) ] with-compiler ;
52 : try-compile ( word -- )
54 [ batch-errors get compile-error update-xt ] recover ;
56 : compile-batch ( seq -- )
57 batch-errors get batch-begins
59 [ f "no-effect" set-word-prop ] each
61 batch-errors get batch-ends ;
63 : compile-vocabs ( seq -- )
64 [ words ] map concat compile-batch ;
67 vocabs compile-vocabs changed-words get clear-hash ;
69 : compile-quot ( quot -- word )
70 define-temp dup compile ;
72 : compile-1 ( quot -- ) compile-quot execute ;
76 dup hash-keys compile-batch clear-hash