]> gitweb.factorcode.org Git - factor.git/commitdiff
stack-checker.known-words: docs and tests
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 5 Feb 2015 10:35:35 +0000 (10:35 +0000)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 5 Feb 2015 11:01:05 +0000 (11:01 +0000)
basis/stack-checker/known-words/known-words-docs.factor
basis/stack-checker/known-words/known-words-tests.factor [new file with mode: 0644]
basis/stack-checker/known-words/known-words.factor

index 95bbbc87b3135407233a6839eafea9973d6ac734..4b25149d3475668fe7e1ec76e33b7bd76f3a724d 100644 (file)
@@ -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
 
-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 } }
-{ $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
 { $values { "word" word } { "n" "the dip depth" } }
 { $description "Performs inferencing for one of the dip words." } ;
 
-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-special
+{ $values { "word" word } }
+{ $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"
diff --git a/basis/stack-checker/known-words/known-words-tests.factor b/basis/stack-checker/known-words/known-words-tests.factor
new file mode 100644 (file)
index 0000000..96e54a7
--- /dev/null
@@ -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
index 10297eb071171459a91180730f5540b168347005..8075206fe010d8c957ab6d0fd3041315d0f95fb4 100644 (file)
@@ -40,7 +40,6 @@ IN: stack-checker.known-words
 : infer-shuffle-word ( word -- )
     "shuffle" word-prop infer-shuffle ;
 
-! This is a hack for combinators combinators.short-circuit.smart.
 : infer-local-reader ( word -- )
     ( -- value ) apply-word/effect ;