Walker cleanup
parent
1a8fa73bdd
commit
9c509d4b99
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2004, 2006 Slava Pestov.
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: inference
|
IN: inference
|
||||||
USING: arrays errors generic hashtables interpreter kernel math
|
USING: arrays errors generic hashtables kernel math
|
||||||
namespaces parser prettyprint sequences strings vectors words ;
|
namespaces parser prettyprint sequences strings vectors words ;
|
||||||
|
|
||||||
: unify-lengths ( seq -- newseq )
|
: unify-lengths ( seq -- newseq )
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,21 @@
|
||||||
! Copyright (C) 2004, 2006 Slava Pestov.
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: inference
|
IN: inference
|
||||||
USING: arrays generic hashtables interpreter kernel math
|
USING: arrays generic hashtables kernel math
|
||||||
namespaces parser sequences words ;
|
namespaces parser sequences words ;
|
||||||
|
|
||||||
|
SYMBOL: d-in
|
||||||
|
SYMBOL: meta-d
|
||||||
|
SYMBOL: meta-r
|
||||||
|
|
||||||
|
: push-d meta-d get push ;
|
||||||
|
: pop-d meta-d get pop ;
|
||||||
|
: peek-d meta-d get peek ;
|
||||||
|
|
||||||
|
: push-r meta-r get push ;
|
||||||
|
: pop-r meta-r get pop ;
|
||||||
|
: peek-r meta-r get peek ;
|
||||||
|
|
||||||
TUPLE: node param shuffle
|
TUPLE: node param shuffle
|
||||||
classes literals history
|
classes literals history
|
||||||
successor children ;
|
successor children ;
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,6 @@ HELP: current-node
|
||||||
HELP: remember-node
|
HELP: remember-node
|
||||||
{ $values { "word" "a word" } { "node" "a dataflow node" } }
|
{ $values { "word" "a word" } { "node" "a dataflow node" } }
|
||||||
{ $description "Annotates all nodes starting from " { $snippet "node" } " with the fact that they were inlined from " { $snippet "word" } ". This prevents infinite loops when the optimizer inlines words." } ;
|
{ $description "Annotates all nodes starting from " { $snippet "node" } " with the fact that they were inlined from " { $snippet "word" } ". This prevents infinite loops when the optimizer inlines words." } ;
|
||||||
|
|
||||||
|
HELP: d-in
|
||||||
|
{ $var-description "During inference, holds the number of inputs which the quotation has been inferred to require so far." } ;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2004, 2006 Slava Pestov.
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: inference
|
IN: inference
|
||||||
USING: arrays errors generic inspector interpreter io kernel
|
USING: arrays errors generic inspector io kernel
|
||||||
math namespaces parser prettyprint sequences strings
|
math namespaces parser prettyprint sequences strings
|
||||||
vectors words ;
|
vectors words ;
|
||||||
|
|
||||||
|
|
@ -19,8 +19,6 @@ TUPLE: literal-expected ;
|
||||||
M: object value-literal
|
M: object value-literal
|
||||||
<literal-expected> inference-error ;
|
<literal-expected> inference-error ;
|
||||||
|
|
||||||
SYMBOL: d-in
|
|
||||||
|
|
||||||
: pop-literal ( -- rstate obj )
|
: pop-literal ( -- rstate obj )
|
||||||
1 #drop node,
|
1 #drop node,
|
||||||
pop-d dup value-recursion swap value-literal ;
|
pop-d dup value-recursion swap value-literal ;
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,6 @@ HELP: literal-expected
|
||||||
{ $error-description "Thrown when inference encounters a " { $link call } " or " { $link if } " being applied to a value which is not known to be a literal. Such a form can have an arbitrary stack effect, and does not compile." }
|
{ $error-description "Thrown when inference encounters a " { $link call } " or " { $link if } " being applied to a value which is not known to be a literal. Such a form can have an arbitrary stack effect, and does not compile." }
|
||||||
{ $notes "This error will be thrown when compiling any combinator, such as " { $link each } ". However, words calling combinators can compile of the combinator is declared " { $link POSTPONE: inline } " and the quotation being passed in is a literal." } ;
|
{ $notes "This error will be thrown when compiling any combinator, such as " { $link each } ". However, words calling combinators can compile of the combinator is declared " { $link POSTPONE: inline } " and the quotation being passed in is a literal." } ;
|
||||||
|
|
||||||
HELP: d-in
|
|
||||||
{ $var-description "During inference, holds the number of inputs which the quotation has been inferred to require so far." } ;
|
|
||||||
|
|
||||||
HELP: terminated?
|
HELP: terminated?
|
||||||
{ $var-description "During inference, a flag set to " { $link t } " if the current control flow path unconditionally throws an error." } ;
|
{ $var-description "During inference, a flag set to " { $link t } " if the current control flow path unconditionally throws an error." } ;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
IN: inference
|
IN: inference
|
||||||
USING: arrays alien assembler errors generic hashtables
|
USING: arrays alien assembler errors generic hashtables
|
||||||
hashtables-internals interpreter io io-internals kernel
|
hashtables-internals io io-internals kernel
|
||||||
kernel-internals math math-internals memory parser
|
kernel-internals math math-internals memory parser
|
||||||
sequences strings vectors words prettyprint ;
|
sequences strings vectors words prettyprint ;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
IN: inference
|
IN: inference
|
||||||
USING: arrays generic interpreter kernel math namespaces
|
USING: arrays generic kernel math namespaces
|
||||||
sequences words parser ;
|
sequences words parser ;
|
||||||
|
|
||||||
: infer-shuffle-inputs ( shuffle node -- )
|
: infer-shuffle-inputs ( shuffle node -- )
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2004, 2006 Slava Pestov.
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays errors generic hashtables interpreter kernel
|
USING: arrays errors generic hashtables kernel
|
||||||
math math-internals namespaces parser prettyprint sequences
|
math math-internals namespaces parser prettyprint sequences
|
||||||
strings vectors words ;
|
strings vectors words ;
|
||||||
IN: inference
|
IN: inference
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,11 @@ namespaces prettyprint sequences test ;
|
||||||
: run ( -- ) done? [ step-in run ] unless ;
|
: run ( -- ) done? [ step-in run ] unless ;
|
||||||
|
|
||||||
: init-interpreter ( -- )
|
: init-interpreter ( -- )
|
||||||
V{ } clone meta-d set
|
V{ } clone V{ } clone V{ } clone namestack catchstack
|
||||||
V{ } clone meta-r set
|
<continuation> meta-interp set ;
|
||||||
V{ } clone meta-c set
|
|
||||||
namestack meta-name set
|
|
||||||
catchstack meta-catch set ;
|
|
||||||
|
|
||||||
: test-interpreter
|
: test-interpreter
|
||||||
init-interpreter (meta-call) run meta-d get ;
|
init-interpreter (meta-call) run meta-d ;
|
||||||
|
|
||||||
[ V{ } ] [
|
[ V{ } ] [
|
||||||
[ ] test-interpreter
|
[ ] test-interpreter
|
||||||
|
|
@ -42,6 +39,36 @@ namespaces prettyprint sequences test ;
|
||||||
[ 2 2 fixnum+ ] test-interpreter
|
[ 2 2 fixnum+ ] test-interpreter
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
: foo 2 2 fixnum+ ;
|
||||||
|
|
||||||
|
[ V{ 8 } ] [
|
||||||
|
[ foo 4 fixnum+ ] test-interpreter
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ V{ C{ 1 1.5 } { } C{ 1 1.5 } { } } ] [
|
||||||
|
[ C{ 1 1.5 } { } 2dup ] test-interpreter
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ V{ 3 4 1 2 } ] [
|
||||||
|
[ 1 2 3 4 2swap ] test-interpreter
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ V{ t } ] [
|
||||||
|
[ 5 5 number= ] test-interpreter
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ V{ f } ] [
|
||||||
|
[ 5 6 number= ] test-interpreter
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ V{ -1 } ] [
|
||||||
|
[ "XYZ" "XYZ" 3 (mismatch) ] test-interpreter
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ V{ t } ] [
|
||||||
|
[ "XYZ" "XYZ" sequence= ] test-interpreter
|
||||||
|
] unit-test
|
||||||
|
|
||||||
[ V{ t } ] [
|
[ V{ t } ] [
|
||||||
[ "XYZ" "XYZ" = ] test-interpreter
|
[ "XYZ" "XYZ" = ] test-interpreter
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
@ -50,10 +77,6 @@ namespaces prettyprint sequences test ;
|
||||||
[ "XYZ" "XuZ" = ] test-interpreter
|
[ "XYZ" "XuZ" = ] test-interpreter
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ V{ C{ 1 1.5 } { } C{ 1 1.5 } { } } ] [
|
|
||||||
[ C{ 1 1.5 } { } 2dup ] test-interpreter
|
|
||||||
] unit-test
|
|
||||||
|
|
||||||
[ V{ 4 } ] [
|
[ V{ 4 } ] [
|
||||||
[ 2 2 + ] test-interpreter
|
[ 2 2 + ] test-interpreter
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,23 @@ namespaces prettyprint sequences strings threads vectors words ;
|
||||||
! continuation to and from the primary interpreter. Used by
|
! continuation to and from the primary interpreter. Used by
|
||||||
! compiler for partial evaluation, also by the walker.
|
! compiler for partial evaluation, also by the walker.
|
||||||
|
|
||||||
|
SYMBOL: meta-interp
|
||||||
|
|
||||||
! Meta-stacks;
|
! Meta-stacks;
|
||||||
SYMBOL: meta-d
|
: meta-d meta-interp get continuation-data ;
|
||||||
: push-d meta-d get push ;
|
: push-d meta-d push ;
|
||||||
: pop-d meta-d get pop ;
|
: pop-d meta-d pop ;
|
||||||
: peek-d meta-d get peek ;
|
: peek-d meta-d peek ;
|
||||||
SYMBOL: meta-r
|
|
||||||
: push-r meta-r get push ;
|
: meta-r meta-interp get continuation-retain ;
|
||||||
: pop-r meta-r get pop ;
|
: push-r meta-r push ;
|
||||||
: peek-r meta-r get peek ;
|
: pop-r meta-r pop ;
|
||||||
SYMBOL: meta-c
|
: peek-r meta-r peek ;
|
||||||
: push-c meta-c get push ;
|
|
||||||
: pop-c meta-c get pop ;
|
: meta-c meta-interp get continuation-call ;
|
||||||
: peek-c meta-c get peek ;
|
: push-c meta-c push ;
|
||||||
SYMBOL: meta-name
|
: pop-c meta-c pop ;
|
||||||
SYMBOL: meta-catch
|
: peek-c meta-c peek ;
|
||||||
|
|
||||||
! Call frame
|
! Call frame
|
||||||
SYMBOL: callframe
|
SYMBOL: callframe
|
||||||
|
|
@ -45,7 +47,7 @@ SYMBOL: callframe-end
|
||||||
|
|
||||||
: done-cf? ( -- ? ) callframe-scan get callframe-end get >= ;
|
: done-cf? ( -- ? ) callframe-scan get callframe-end get >= ;
|
||||||
|
|
||||||
: done? ( -- ? ) done-cf? meta-c get empty? and ;
|
: done? ( -- ? ) done-cf? meta-c empty? and ;
|
||||||
|
|
||||||
: (next)
|
: (next)
|
||||||
callframe-scan get callframe get nth callframe-scan inc ;
|
callframe-scan get callframe get nth callframe-scan inc ;
|
||||||
|
|
@ -57,24 +59,8 @@ SYMBOL: callframe-end
|
||||||
{ [ t ] [ >r (next) r> call ] }
|
{ [ t ] [ >r (next) r> call ] }
|
||||||
} cond ; inline
|
} cond ; inline
|
||||||
|
|
||||||
: meta-interp ( -- interp )
|
|
||||||
meta-d get meta-r get meta-c get
|
|
||||||
meta-name get meta-catch get <continuation> ;
|
|
||||||
|
|
||||||
: init-meta-interp ( -- )
|
: init-meta-interp ( -- )
|
||||||
V{ } clone meta-catch set
|
<empty-continuation> meta-interp set ;
|
||||||
V{ } clone meta-name set
|
|
||||||
V{ } clone meta-c set
|
|
||||||
V{ } clone meta-r set
|
|
||||||
V{ } clone meta-d set ;
|
|
||||||
|
|
||||||
: set-meta-interp ( interp -- )
|
|
||||||
>continuation<
|
|
||||||
meta-catch set
|
|
||||||
meta-name set
|
|
||||||
meta-c set
|
|
||||||
meta-r set
|
|
||||||
meta-d set ;
|
|
||||||
|
|
||||||
: save-callframe ( -- )
|
: save-callframe ( -- )
|
||||||
done-cf? [
|
done-cf? [
|
||||||
|
|
@ -103,17 +89,18 @@ SYMBOL: callframe-end
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
||||||
: restore-harness ( obj -- )
|
: restore-harness ( obj -- )
|
||||||
|
#! Error handler
|
||||||
dup array? [
|
dup array? [
|
||||||
init-meta-interp [ ] (meta-call)
|
init-meta-interp [ ] (meta-call)
|
||||||
first2 schedule-thread-with
|
first2 schedule-thread-with
|
||||||
] [
|
] [
|
||||||
set-meta-interp
|
meta-interp set
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: host-quot ( quot -- )
|
: host-quot ( quot -- )
|
||||||
[
|
[
|
||||||
host-harness <callframe> meta-c get swap nappend
|
host-harness <callframe> meta-c swap nappend
|
||||||
meta-interp continue
|
meta-interp get continue
|
||||||
] callcc1 restore-harness drop ;
|
] callcc1 restore-harness drop ;
|
||||||
|
|
||||||
: host-word ( word -- ) unit host-quot ;
|
: host-word ( word -- ) unit host-quot ;
|
||||||
|
|
@ -162,6 +149,6 @@ M: object do do-1 ;
|
||||||
: step-all ( -- )
|
: step-all ( -- )
|
||||||
save-callframe
|
save-callframe
|
||||||
meta-c [ V{ [ stop ] 0 1 } swap append ] change
|
meta-c [ V{ [ stop ] 0 1 } swap append ] change
|
||||||
meta-interp schedule-thread yield
|
meta-interp get schedule-thread yield
|
||||||
V{ } clone meta-c set
|
V{ } clone meta-c set
|
||||||
[ ] (meta-call) ;
|
[ ] (meta-call) ;
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ TUPLE: walker-gadget track ds rs cs quot ns ;
|
||||||
: walker-gadget-input walker-gadget-track walker-track-input ;
|
: walker-gadget-input walker-gadget-track walker-track-input ;
|
||||||
|
|
||||||
: update-stacks ( walker -- )
|
: update-stacks ( walker -- )
|
||||||
meta-d get over walker-gadget-ds set-model
|
meta-d over walker-gadget-ds set-model
|
||||||
meta-r get over walker-gadget-rs set-model
|
meta-r over walker-gadget-rs set-model
|
||||||
meta-c get over walker-gadget-cs set-model
|
meta-c over walker-gadget-cs set-model
|
||||||
meta-callframe swap walker-gadget-quot set-model ;
|
meta-callframe swap walker-gadget-quot set-model ;
|
||||||
|
|
||||||
: with-walker ( walker quot -- )
|
: with-walker ( walker quot -- )
|
||||||
|
|
@ -98,7 +98,7 @@ M: walker-gadget focusable-child*
|
||||||
: init-walker ( walker -- )
|
: init-walker ( walker -- )
|
||||||
H{ } clone over set-walker-gadget-ns
|
H{ } clone over set-walker-gadget-ns
|
||||||
walker-continuation swap [
|
walker-continuation swap [
|
||||||
set-meta-interp
|
meta-interp set
|
||||||
[ ] (meta-call)
|
[ ] (meta-call)
|
||||||
] with-walker ;
|
] with-walker ;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue