Cleanup compiler
parent
1b2d7eac4a
commit
0314d05a08
|
@ -4,38 +4,55 @@ USING: kernel namespaces arrays sequences io inference.backend
|
||||||
inference.state generator debugger words compiler.units
|
inference.state generator debugger words compiler.units
|
||||||
continuations vocabs assocs alien.compiler dlists optimizer
|
continuations vocabs assocs alien.compiler dlists optimizer
|
||||||
definitions math compiler.errors threads graphs generic
|
definitions math compiler.errors threads graphs generic
|
||||||
inference ;
|
inference combinators ;
|
||||||
IN: compiler
|
IN: compiler
|
||||||
|
|
||||||
: ripple-up ( word -- )
|
: ripple-up ( word -- )
|
||||||
compiled-usage [ drop queue-compile ] assoc-each ;
|
compiled-usage [ drop queue-compile ] assoc-each ;
|
||||||
|
|
||||||
: save-effect ( word effect -- )
|
: save-effect ( word effect -- )
|
||||||
over "compiled-uses" word-prop [
|
|
||||||
2dup swap "compiled-effect" word-prop =
|
|
||||||
[ over ripple-up ] unless
|
|
||||||
] when
|
|
||||||
"compiled-effect" set-word-prop ;
|
|
||||||
|
|
||||||
: finish-compile ( word effect dependencies -- )
|
|
||||||
>r dupd save-effect r>
|
|
||||||
over compiled-unxref
|
|
||||||
over compiled-crossref? [ compiled-xref ] [ 2drop ] if ;
|
|
||||||
|
|
||||||
: compile-succeeded ( word -- effect dependencies )
|
|
||||||
[
|
[
|
||||||
[ word-dataflow optimize ] keep dup generate
|
over "compiled-effect" word-prop = [
|
||||||
] computing-dependencies ;
|
dup "compiled-uses" word-prop
|
||||||
|
[ dup ripple-up ] when
|
||||||
|
] unless drop
|
||||||
|
]
|
||||||
|
[ "compiled-effect" set-word-prop ] 2bi ;
|
||||||
|
|
||||||
|
: compile-begins ( word -- )
|
||||||
|
f swap compiler-error ;
|
||||||
|
|
||||||
: compile-failed ( word error -- )
|
: compile-failed ( word error -- )
|
||||||
f pick compiled get set-at
|
[ swap compiler-error ]
|
||||||
swap compiler-error ;
|
[
|
||||||
|
drop
|
||||||
|
[ f swap compiled get set-at ]
|
||||||
|
[ f save-effect ]
|
||||||
|
bi
|
||||||
|
] 2bi ;
|
||||||
|
|
||||||
|
: compile-succeeded ( effect word -- )
|
||||||
|
[ swap save-effect ]
|
||||||
|
[ compiled-unxref ]
|
||||||
|
[
|
||||||
|
dup compiled-crossref?
|
||||||
|
[ dependencies get compiled-xref ] [ drop ] if
|
||||||
|
] tri ;
|
||||||
|
|
||||||
: (compile) ( word -- )
|
: (compile) ( word -- )
|
||||||
f over compiler-error
|
[
|
||||||
[ dup compile-succeeded finish-compile ]
|
H{ } clone dependencies set
|
||||||
[ dupd compile-failed f save-effect ]
|
|
||||||
recover ;
|
{
|
||||||
|
[ compile-begins ]
|
||||||
|
[
|
||||||
|
[ word-dataflow ] [ compile-failed return ] recover
|
||||||
|
optimize
|
||||||
|
]
|
||||||
|
[ dup generate ]
|
||||||
|
[ compile-succeeded ]
|
||||||
|
} cleave
|
||||||
|
] curry with-return ;
|
||||||
|
|
||||||
: compile-loop ( assoc -- )
|
: compile-loop ( assoc -- )
|
||||||
dup assoc-empty? [ drop ] [
|
dup assoc-empty? [ drop ] [
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
IN: inference.state.tests
|
IN: inference.state.tests
|
||||||
USING: tools.test inference.state words ;
|
USING: tools.test inference.state words ;
|
||||||
|
|
||||||
|
: computing-dependencies ( quot -- dependencies )
|
||||||
|
H{ } clone [ dependencies rot with-variable ] keep ;
|
||||||
|
inline
|
||||||
|
|
||||||
SYMBOL: a
|
SYMBOL: a
|
||||||
SYMBOL: b
|
SYMBOL: b
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,6 @@ SYMBOL: dependencies
|
||||||
2dup at +inlined+ eq? [ 3drop ] [ set-at ] if
|
2dup at +inlined+ eq? [ 3drop ] [ set-at ] if
|
||||||
] [ 3drop ] if ;
|
] [ 3drop ] if ;
|
||||||
|
|
||||||
: computing-dependencies ( quot -- dependencies )
|
|
||||||
H{ } clone [ dependencies rot with-variable ] keep ;
|
|
||||||
inline
|
|
||||||
|
|
||||||
! Did the current control-flow path throw an error?
|
! Did the current control-flow path throw an error?
|
||||||
SYMBOL: terminated?
|
SYMBOL: terminated?
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue