stack-checker.known-words: docs and tests
parent
086dffc53a
commit
f99c03d023
|
@ -1,14 +1,31 @@
|
||||||
USING: help.markup help.syntax sequences words ;
|
USING: help.markup help.syntax kernel kernel.private sequences words ;
|
||||||
IN: stack-checker.known-words
|
IN: stack-checker.known-words
|
||||||
|
|
||||||
HELP: infer-special
|
HELP: check-declaration
|
||||||
|
{ $values { "declaration" sequence } }
|
||||||
|
{ $description "Checks that a declaration sequence as inputted to a " { $link declare } " word is well-formed." } ;
|
||||||
|
|
||||||
|
HELP: define-primitive
|
||||||
|
{ $values { "word" word } { "inputs" sequence } { "outputs" sequence } }
|
||||||
|
{ $description "Marks the word as a primitive whose input and output types must be the given ones." } ;
|
||||||
|
|
||||||
|
HELP: infer-call
|
||||||
|
{ $description "Performs inferencing for the " { $link call } " word." } ;
|
||||||
|
|
||||||
|
HELP: infer-local-reader
|
||||||
{ $values { "word" word } }
|
{ $values { "word" word } }
|
||||||
{ $description "Performs inferencing of a word with the \"special\" property set." } ;
|
{ $description "This is a hack for combinators " { $vocab-link "combinators.short-circuit.smart" } "." } ;
|
||||||
|
|
||||||
HELP: infer-ndip
|
HELP: infer-ndip
|
||||||
{ $values { "word" word } { "n" "the dip depth" } }
|
{ $values { "word" word } { "n" "the dip depth" } }
|
||||||
{ $description "Performs inferencing for one of the dip words." } ;
|
{ $description "Performs inferencing for one of the dip words." } ;
|
||||||
|
|
||||||
HELP: define-primitive
|
HELP: infer-special
|
||||||
{ $values { "word" word } { "inputs" sequence } { "outputs" sequence } }
|
{ $values { "word" word } }
|
||||||
{ $description "Marks the word as a primitive whose input and output types must be the given ones." } ;
|
{ $description "Performs inferencing of a word with the \"special\" property set." } ;
|
||||||
|
|
||||||
|
|
||||||
|
ARTICLE: "stack-checker.known-words" "Hard-coded stack effects for primitive words"
|
||||||
|
"This vocab declares primitive and shuffle words." ;
|
||||||
|
|
||||||
|
ABOUT: "stack-checker.known-words"
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
USING: accessors classes.tuple compiler.tree kernel namespaces sequences
|
||||||
|
stack-checker.backend stack-checker.known-words stack-checker.recursive-state
|
||||||
|
stack-checker.state stack-checker.values stack-checker.visitor tools.test
|
||||||
|
words ;
|
||||||
|
IN: stack-checker.known-words.tests
|
||||||
|
|
||||||
|
! Because node is an identity-tuple
|
||||||
|
: node-seqs-eq? ( seq1 seq2 -- ? )
|
||||||
|
[ [ tuple-slots ] map concat ] bi@ = ;
|
||||||
|
|
||||||
|
{ t } [
|
||||||
|
0 \ <value> set-global [
|
||||||
|
V{ } clone stack-visitor set
|
||||||
|
\ swap "shuffle" word-prop infer-shuffle
|
||||||
|
] with-infer nip V{
|
||||||
|
T{ #introduce { out-d { 1 2 } } }
|
||||||
|
T{ #shuffle
|
||||||
|
{ mapping { { 3 2 } { 4 1 } } }
|
||||||
|
{ in-d V{ 1 2 } }
|
||||||
|
{ out-d V{ 3 4 } }
|
||||||
|
}
|
||||||
|
T{ #return { in-d V{ 3 4 } } }
|
||||||
|
} node-seqs-eq?
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
: foo ( x -- )
|
||||||
|
drop ;
|
||||||
|
|
||||||
|
{ t } [
|
||||||
|
0 \ <value> set-global [
|
||||||
|
V{ } clone stack-visitor set
|
||||||
|
1234
|
||||||
|
T{ literal-tuple
|
||||||
|
{ value [ foo ] }
|
||||||
|
{ recursion T{ recursive-state } }
|
||||||
|
} infer-call*
|
||||||
|
] with-infer nip V{
|
||||||
|
T{ #shuffle
|
||||||
|
{ mapping { } }
|
||||||
|
{ in-d { 1234 } }
|
||||||
|
{ out-d { } }
|
||||||
|
}
|
||||||
|
T{ #introduce { out-d { 1 } } }
|
||||||
|
T{ #call { word foo } { in-d V{ 1 } } { out-d { } } }
|
||||||
|
T{ #return { in-d V{ } } }
|
||||||
|
} node-seqs-eq?
|
||||||
|
] unit-test
|
|
@ -40,7 +40,6 @@ IN: stack-checker.known-words
|
||||||
: infer-shuffle-word ( word -- )
|
: infer-shuffle-word ( word -- )
|
||||||
"shuffle" word-prop infer-shuffle ;
|
"shuffle" word-prop infer-shuffle ;
|
||||||
|
|
||||||
! This is a hack for combinators combinators.short-circuit.smart.
|
|
||||||
: infer-local-reader ( word -- )
|
: infer-local-reader ( word -- )
|
||||||
( -- value ) apply-word/effect ;
|
( -- value ) apply-word/effect ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue