2019-10-18 09:05:06 -04:00
|
|
|
! Copyright (C) 2004, 2007 Slava Pestov.
|
2006-03-08 15:03:01 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2004-09-06 22:39:12 -04:00
|
|
|
IN: compiler
|
2019-10-18 09:05:08 -04:00
|
|
|
USING: errors generic assocs inference io kernel math
|
2019-10-18 09:05:06 -04:00
|
|
|
namespaces generator optimizer parser prettyprint sequences
|
2019-10-18 09:05:08 -04:00
|
|
|
threads words arrays ;
|
2004-09-06 22:39:12 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
SYMBOL: compiler-hook
|
2006-11-10 15:44:16 -05:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
SYMBOL: compile-errors
|
2006-11-10 15:44:16 -05:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
SYMBOL: batch-mode
|
2006-09-23 02:40:25 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: compile-begins ( word -- )
|
|
|
|
|
compiler-hook get call
|
|
|
|
|
"quiet" get batch-mode get or [
|
|
|
|
|
drop
|
|
|
|
|
] [
|
|
|
|
|
"Compiling " write . flush
|
|
|
|
|
] if ;
|
2019-10-18 09:05:04 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
M: object inference-error-major? drop t ;
|
2006-09-23 02:40:25 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: compile-error ( word error -- )
|
|
|
|
|
batch-mode get [
|
|
|
|
|
2array compile-errors get push
|
|
|
|
|
] [
|
|
|
|
|
"quiet" get [ drop ] [ error. flush ] if drop
|
|
|
|
|
] if ;
|
2006-09-23 02:40:25 -04:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: begin-batch ( seq -- )
|
|
|
|
|
batch-mode on
|
|
|
|
|
[
|
|
|
|
|
"Compiling " % length # " words..." %
|
|
|
|
|
] "" make print flush
|
|
|
|
|
V{ } clone compile-errors set-global ;
|
|
|
|
|
|
|
|
|
|
: compile-error. ( pair -- )
|
|
|
|
|
nl
|
|
|
|
|
"While compiling " write dup first pprint ": " print
|
|
|
|
|
nl
|
|
|
|
|
second 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 ( -- )
|
|
|
|
|
batch-mode off
|
|
|
|
|
"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 ;
|
2006-09-23 02:40:25 -04:00
|
|
|
|
2006-08-18 01:35:04 -04:00
|
|
|
: word-dataflow ( word -- dataflow )
|
|
|
|
|
[
|
2006-11-12 22:14:04 -05:00
|
|
|
dup "no-effect" word-prop [ no-effect ] when
|
2006-08-18 01:35:04 -04:00
|
|
|
dup dup add-recursive-state
|
2006-11-12 22:14:04 -05:00
|
|
|
[ specialized-def (dataflow) ] keep
|
|
|
|
|
finish-word 2drop
|
2006-08-18 01:35:04 -04:00
|
|
|
] with-infer ;
|
|
|
|
|
|
2006-01-19 03:03:32 -05:00
|
|
|
: (compile) ( word -- )
|
2006-08-10 14:39:12 -04:00
|
|
|
dup compiling? not over compound? and [
|
2019-10-18 09:05:08 -04:00
|
|
|
dup compile-begins
|
2019-10-18 09:05:06 -04:00
|
|
|
dup dup word-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
|
|
|
|
2004-09-06 22:39:12 -04:00
|
|
|
: compile ( word -- )
|
2006-08-10 14:39:12 -04:00
|
|
|
[ (compile) ] with-compiler ;
|
2004-09-06 22:39:12 -04:00
|
|
|
|
2019-10-18 09:05:06 -04:00
|
|
|
: compile-failed ( word error -- )
|
2019-10-18 09:05:08 -04:00
|
|
|
dupd compile-error dup update-xt unchanged-word ;
|
2019-10-18 09:05:06 -04:00
|
|
|
|
2004-12-16 19:57:03 -05:00
|
|
|
: try-compile ( word -- )
|
2019-10-18 09:05:06 -04:00
|
|
|
[ compile ] [ compile-failed ] recover ;
|
|
|
|
|
|
|
|
|
|
: forget-errors ( seq -- )
|
|
|
|
|
[ f "no-effect" set-word-prop ] each ;
|
|
|
|
|
|
2006-09-23 02:40:25 -04:00
|
|
|
: compile-batch ( seq -- )
|
2019-10-18 09:05:06 -04:00
|
|
|
dup empty? [
|
|
|
|
|
drop
|
|
|
|
|
] [
|
2019-10-18 09:05:08 -04:00
|
|
|
dup begin-batch
|
|
|
|
|
dup forget-errors
|
|
|
|
|
[ try-compile ] each
|
|
|
|
|
end-batch
|
2019-10-18 09:05:06 -04:00
|
|
|
] if ;
|
2004-12-16 19:57:03 -05:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: compile-vocabs ( seq -- ) [ words ] map concat compile-batch ;
|
2006-02-09 20:34:49 -05:00
|
|
|
|
2019-10-18 09:05:06 -04:00
|
|
|
: compile-all ( -- ) vocabs compile-vocabs ;
|
2005-01-06 19:10:02 -05:00
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
: compile-quot ( quot -- word ) define-temp dup compile ;
|
2006-03-15 15:58:22 -05:00
|
|
|
|
|
|
|
|
: compile-1 ( quot -- ) compile-quot execute ;
|
2006-08-10 16:44:00 -04:00
|
|
|
|
|
|
|
|
: recompile ( -- )
|
2006-08-11 16:55:43 -04:00
|
|
|
changed-words get [
|
2019-10-18 09:05:08 -04:00
|
|
|
dup keys compile-batch clear-assoc
|
2006-08-11 16:55:43 -04:00
|
|
|
] when* ;
|