factor/core/compiler/compiler.factor

90 lines
2.3 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
generator debugger math.parser prettyprint words continuations
vocabs assocs alien.compiler ;
IN: compiler
M: object inference-error-major? drop t ;
: compile-error ( word error -- )
compile-errors get [
>r 2array r> push
2007-09-20 18:09:08 -04:00
] [
"quiet" get [ 2drop ] [ print-error flush drop ] if
] if* ;
2007-09-20 18:09:08 -04:00
2007-12-16 15:17:28 -05:00
: begin-batch ( -- )
2007-09-20 18:09:08 -04:00
V{ } clone compile-errors set-global ;
: compile-error. ( pair -- )
nl
"While compiling " write dup first pprint ": " print
nl
second print-error ;
: (:errors) ( -- seq )
compile-errors get-global
[ second inference-error-major? ] subset ;
: :errors (:errors) [ compile-error. ] each ;
: (:warnings) ( -- seq )
compile-errors get-global
[ second inference-error-major? not ] subset ;
: :warnings (:warnings) [ compile-error. ] each ;
: end-batch ( -- )
"quiet" get [
"Compile finished." print
nl
":errors - print " write (:errors) length pprint
" compiler errors." print
":warnings - print " write (:warnings) length pprint
" compiler warnings." print
nl
] unless ;
: with-compile-errors ( quot -- )
[ begin-batch call end-batch ] with-scope ; inline
2007-09-20 18:09:08 -04:00
: compile ( word -- )
H{ } clone [
compiled-xts [ (compile) ] with-variable
2007-12-16 15:17:28 -05:00
] keep [ swap add* ] { } assoc>map modify-code-heap ;
2007-09-20 18:09:08 -04:00
: compile-failed ( word error -- )
dupd compile-error dup update-xt unchanged-word ;
2007-12-16 15:17:28 -05:00
: (compile-batch) ( words -- )
H{ } clone [
compiled-xts [
[ [ (compile) ] [ compile-failed ] recover ] each
2007-12-16 15:17:28 -05:00
] with-variable
] keep [ swap add* ] { } assoc>map modify-code-heap ;
2007-09-20 18:09:08 -04:00
: compile-batch ( seq -- )
dup empty? [
drop
] [
[ (compile-batch) ] with-compile-errors
2007-09-20 18:09:08 -04:00
] if ;
: compile-vocabs ( seq -- ) [ words ] map concat compile-batch ;
: compile-quot ( quot -- word ) define-temp dup compile ;
: compile-1 ( quot -- ) compile-quot execute ;
: recompile ( -- )
changed-words get [
dup keys compile-batch clear-assoc
] when* ;
: forget-errors ( seq -- )
[ f "no-effect" set-word-prop ] each ;
: compile-all ( -- )
all-words dup forget-errors [ changed-word ] each recompile ;