Clean up compiler vocab

db4
Slava Pestov 2009-04-21 22:33:04 -05:00
parent 97a522da0e
commit 24a22e233c
1 changed files with 46 additions and 29 deletions

View File

@ -15,6 +15,7 @@ SYMBOL: compile-queue
SYMBOL: compiled SYMBOL: compiled
: queue-compile? ( word -- ? ) : queue-compile? ( word -- ? )
#! Don't attempt to compile certain words.
{ {
[ "forgotten" word-prop ] [ "forgotten" word-prop ]
[ compiled get key? ] [ compiled get key? ]
@ -25,17 +26,14 @@ SYMBOL: compiled
: queue-compile ( word -- ) : queue-compile ( word -- )
dup queue-compile? [ compile-queue get push-front ] [ drop ] if ; dup queue-compile? [ compile-queue get push-front ] [ drop ] if ;
: maybe-compile ( word -- )
dup optimized>> [ drop ] [ queue-compile ] if ;
: recompile-callers? ( word -- ? ) : recompile-callers? ( word -- ? )
changed-effects get key? ; changed-effects get key? ;
: recompile-callers ( words -- ) : recompile-callers ( words -- )
dup recompile-callers? [ #! If a word's stack effect changed, recompile all words that
[ usage [ word? ] filter ] [ compiled-usage keys ] bi #! have compiled calls to it.
[ [ queue-compile ] each ] bi@ dup recompile-callers?
] [ drop ] if ; [ compiled-usage keys [ queue-compile ] each ] [ drop ] if ;
: start ( word -- ) : start ( word -- )
"trace-compilation" get [ dup name>> print flush ] when "trace-compilation" get [ dup name>> print flush ] when
@ -44,6 +42,8 @@ SYMBOL: compiled
f swap compiler-error ; f swap compiler-error ;
: ignore-error? ( word error -- ? ) : ignore-error? ( word error -- ? )
#! Ignore warnings on inline combinators, macros, and special
#! words such as 'call'.
[ [
{ {
[ macro? ] [ macro? ]
@ -53,35 +53,61 @@ SYMBOL: compiled
} 1|| } 1||
] [ error-type +compiler-warning+ eq? ] bi* and ; ] [ error-type +compiler-warning+ eq? ] bi* and ;
: (fail) ( word compiled -- * ) : finish ( word -- )
swap #! Recompile callers if the word's stack effect changed, then
#! save the word's dependencies so that if they change, the
#! word can get recompiled too.
[ recompile-callers ] [ recompile-callers ]
[ compiled-unxref ] [ compiled-unxref ]
[ compiled get set-at ] [
tri return ; dup crossref? [
dependencies get
generic-dependencies get
compiled-xref
] [ drop ] if
] tri ;
: deoptimize-with ( word def -- * )
#! If the word failed to infer, compile it with the
#! non-optimizing compiler.
swap [ finish ] [ compiled get set-at ] bi return ;
: not-compiled-def ( word error -- def ) : not-compiled-def ( word error -- def )
'[ _ _ not-compiled ] [ ] like ; '[ _ _ not-compiled ] [ ] like ;
: fail ( word error -- * ) : deoptimize ( word error -- * )
#! If the error is ignorable, compile the word with the
#! non-optimizing compiler, using its definition. Otherwise,
#! if the compiler error is not ignorable, use a dummy
#! definition from 'not-compiled-def' which throws an error.
2dup ignore-error? 2dup ignore-error?
[ drop f over def>> ] [ drop f over def>> ]
[ 2dup not-compiled-def ] if [ 2dup not-compiled-def ] if
[ swap compiler-error ] [ (fail) ] bi-curry* bi ; [ swap compiler-error ] [ deoptimize-with ] bi-curry* bi ;
: frontend ( word -- nodes ) : frontend ( word -- nodes )
dup contains-breakpoints? [ dup def>> (fail) ] [ #! If the word contains breakpoints, don't optimize it, since
[ build-tree-from-word ] [ fail ] recover optimize-tree #! the walker does not support this.
dup contains-breakpoints? [ dup def>> deoptimize-with ] [
[ build-tree ] [ deoptimize ] recover optimize-tree
] if ; ] if ;
: compile-dependency ( word -- )
#! If a word calls an unoptimized word, try to compile the callee.
dup optimized>> [ drop ] [ queue-compile ] if ;
! Only switch this off for debugging. ! Only switch this off for debugging.
SYMBOL: compile-dependencies? SYMBOL: compile-dependencies?
t compile-dependencies? set-global t compile-dependencies? set-global
: compile-dependencies ( asm -- )
compile-dependencies? get
[ calls>> [ compile-dependency ] each ] [ drop ] if ;
: save-asm ( asm -- ) : save-asm ( asm -- )
[ [ code>> ] [ label>> ] bi compiled get set-at ] [ [ code>> ] [ label>> ] bi compiled get set-at ]
[ compile-dependencies? get [ calls>> [ maybe-compile ] each ] [ drop ] if ] [ compile-dependencies ]
bi ; bi ;
: backend ( nodes word -- ) : backend ( nodes word -- )
@ -95,18 +121,9 @@ t compile-dependencies? set-global
save-asm save-asm
] each ; ] each ;
: finish ( word -- ) : compile-word ( word -- )
[ recompile-callers ] #! We return early if the word has breakpoints or if it
[ compiled-unxref ] #! failed to infer.
[
dup crossref? [
dependencies get
generic-dependencies get
compiled-xref
] [ drop ] if
] tri ;
: (compile) ( word -- )
'[ '[
_ { _ {
[ start ] [ start ]
@ -117,7 +134,7 @@ t compile-dependencies? set-global
] with-return ; ] with-return ;
: compile-loop ( deque -- ) : compile-loop ( deque -- )
[ (compile) yield-hook get call( -- ) ] slurp-deque ; [ compile-word yield-hook get call( -- ) ] slurp-deque ;
: decompile ( word -- ) : decompile ( word -- )
dup def>> 2array 1array modify-code-heap ; dup def>> 2array 1array modify-code-heap ;