]> gitweb.factorcode.org Git - factor.git/commitdiff
Fixing various test failures caused by C type parser change, and clarify C type docs...
authorSlava Pestov <slava@shill.local>
Mon, 28 Sep 2009 13:48:39 +0000 (08:48 -0500)
committerSlava Pestov <slava@shill.local>
Mon, 28 Sep 2009 13:48:39 +0000 (08:48 -0500)
17 files changed:
basis/alien/c-types/c-types-docs.factor
basis/classes/struct/struct-docs.factor
basis/compiler/tests/alien.factor
basis/cpu/x86/x86.factor
basis/math/vectors/specialization/specialization-tests.factor
basis/math/vectors/vectors-docs.factor
basis/math/vectors/vectors-tests.factor
basis/pango/layouts/layouts-tests.factor
basis/sequences/complex/complex-docs.factor
basis/serialize/serialize-tests.factor
basis/specialized-arrays/specialized-arrays-tests.factor
basis/specialized-vectors/specialized-vectors-tests.factor
basis/unix/linux/linux.factor
core/alien/alien-docs.factor
core/assocs/assocs-tests.factor
extra/id3/id3.factor
extra/jamshred/tunnel/tunnel-tests.factor

index eb4be08764c767bffe9c9e9e01ecd2debbc097c8..ea5016e563ddbcc56024f932017ce3f1725ab08b 100755 (executable)
@@ -3,6 +3,7 @@ byte-arrays strings hashtables alien.syntax alien.strings sequences
 io.encodings.string debugger destructors vocabs.loader
 classes.struct ;
 QUALIFIED: math
+QUALIFIED: sequences
 IN: alien.c-types
 
 HELP: byte-length
@@ -164,10 +165,8 @@ $nl
 { $subsection *void* }
 "Note that while structure and union types do not get these words defined for them, there is no loss of generality since " { $link <void*> } " and " { $link *void* } " may be used." ;
 
-ARTICLE: "c-types-specs" "C type specifiers"
-"C types are identified by special words, and type names occur as parameters to the " { $link alien-invoke } ", " { $link alien-indirect } " and " { $link alien-callback } " words. New C types can be defined by the words " { $link POSTPONE: STRUCT: } ", " { $link POSTPONE: UNION-STRUCT: } ", " { $link POSTPONE: CALLBACK: } ", and " { $link POSTPONE: TYPEDEF: } "."
-$nl
-"The following numerical types are available; a " { $snippet "u" } " prefix denotes an unsigned type:"
+ARTICLE: "c-types.primitives" "Primitive C types"
+"The following numerical types are defined in the " { $vocab-link "alien.c-types" } " vocabulary; a " { $snippet "u" } " prefix denotes an unsigned type:"
 { $table
     { "C type" "Notes" }
     { { $link char } "always 1 byte" }
@@ -182,15 +181,57 @@ $nl
     { { $link ulonglong } { } }
     { { $link float } { "single-precision float (not the same as Factor's " { $link math:float } " class!)" } }
     { { $link double } { "double-precision float (the same format as Factor's " { $link math:float } " objects)" } }
+}
+"The following C99 complex number types are defined in the " { $vocab-link "alien.complex" } " vocabulary:"
+{ $table
     { { $link complex-float } { "C99 or Fortran " { $snippet "complex float" } " type, converted to and from Factor " { $link math:complex } " values" } }
     { { $link complex-double } { "C99 or Fortran " { $snippet "complex double" } " type, converted to and from Factor " { $link math:complex } " values" } }
 }
-"When making alien calls, Factor numbers are converted to and from the above types in a canonical way. Converting a Factor number to a C value may result in a loss of precision."
-$nl
+"When making alien calls, Factor numbers are converted to and from the above types in a canonical way. Converting a Factor number to a C value may result in a loss of precision." ;
+
+ARTICLE: "c-types.pointers" "Pointer and array types"
 "Pointer types are specified by suffixing a C type with " { $snippet "*" } ", for example " { $snippet "float*" } ". One special case is " { $link void* } ", which denotes a generic pointer; " { $link void } " by itself is not a valid C type specifier. With the exception of strings (see " { $link "c-strings" } "), all pointer types are identical to " { $snippet "void*" } " as far as the C library interface is concerned."
 $nl
 "Fixed-size array types are supported; the syntax consists of a C type name followed by dimension sizes in brackets; the following denotes a 3 by 4 array of integers:"
 { $code "int[3][4]" }
-"Fixed-size arrays differ from pointers in that they are allocated inside structures and unions; however when used as function parameters they behave exactly like pointers and thus the dimensions only serve as documentation."
-$nl
-"Structure and union types are specified by the name of the structure or union." ;
+"Fixed-size arrays differ from pointers in that they are allocated inside structures and unions; however when used as function parameters they behave exactly like pointers and thus the dimensions only serve as documentation." ;
+
+ARTICLE: "c-types.ambiguity" "Word name clashes with C types"
+"Note that some of the C type word names clash with commonly-used Factor words:"
+{ $list
+  { { $link short } " clashes with the " { $link sequences:short } " word in the " { $vocab-link "sequences" } " vocabulary" }
+  { { $link float } " clashes with the " { $link math:float } " word in the " { $vocab-link "math" } " vocabulary" }
+}
+"If you use the wrong vocabulary, you will see a " { $link no-c-type } " error. For example, the following is " { $strong "not" } " valid, and will raise an error because the " { $link math:float } " word from the " { $vocab-link "math" } " vocabulary is not a C type:"
+{ $code
+  "USING: alien.syntax math prettyprint ;"
+  "FUNCTION: float magic_number ( ) ;"
+  "magic_number 3.0 + ."
+}
+"The following won't work either; now the problem is that there are two vocabularies in the search path that define a word named " { $snippet "float" } ":"
+{ $code
+  "USING: alien.c-types alien.syntax math prettyprint ;"
+  "FUNCTION: float magic_number ( ) ;"
+  "magic_number 3.0 + ."
+}
+"The correct solution is to use one of " { $link POSTPONE: FROM: } ", " { $link POSTPONE: QUALIFIED: } " or " { $link POSTPONE: QUALIFIED-WITH: } " to disambiguate word lookup:"
+{ $code
+  "USING: alien.syntax math prettyprint ;"
+  "QUALIFIED-WITH: alien.c-types c"
+  "FUNCTION: c:float magic_number ( ) ;"
+  "magic_number 3.0 + ."
+}
+"See " { $link "word-search-semantics" } " for details." ;
+
+ARTICLE: "c-types.structs" "Struct and union types"
+"Struct and union types are identified by their class word. See " { $link "classes.struct" } "." ;
+
+ARTICLE: "c-types-specs" "C type specifiers"
+"C types are identified by special words, and type names occur as parameters to the " { $link alien-invoke } ", " { $link alien-indirect } " and " { $link alien-callback } " words. New C types can be defined by the words " { $link POSTPONE: STRUCT: } ", " { $link POSTPONE: UNION-STRUCT: } ", " { $link POSTPONE: CALLBACK: } ", and " { $link POSTPONE: TYPEDEF: } "."
+{ $subsection "c-types.primitives" }
+{ $subsection "c-types.pointers" }
+{ $subsection "c-types.ambiguity" }
+{ $subsection "c-types.structs" }
+;
+
+ABOUT: "c-types-specs"
index a38bd3c588c2920cb7c82de0ffa9bfbc2103a6ab..5eff4c077eec87663a45d4cbc8b584cc59c6ccd7 100644 (file)
@@ -163,7 +163,7 @@ $nl
 } ;
 
 ARTICLE: "classes.struct" "Struct classes"
-{ $link struct } " classes are similar to " { $link tuple } "s, but their slots exhibit value semantics, and they are backed by a contiguous structured block of memory. Structs can be used for structured access to C memory or Factor byte arrays and for passing struct values in and out of the FFI."
+"The " { $vocab-link "classes.struct" } " vocabulary implements " { $link struct } " classes. They are similar to " { $link tuple } " classes, but their slots exhibit value semantics, and they are backed by a contiguous structured block of memory. Structs can be used for space-efficient storage of data in the Factor heap, as well as for passing data to and from C libraries using the " { $link "alien" } "."
 { $subsection "classes.struct.examples" }
 { $subsection "classes.struct.define" }
 { $subsection "classes.struct.create" }
index 9d3a66df5bb0978096d449b7b46aa2e0ae3a1401..eaa8be72f0ed8a3f3bbb0c2978550f7bd6b6d4ea 100755 (executable)
@@ -4,7 +4,7 @@ compiler continuations effects io io.backend io.pathnames
 io.streams.string kernel math memory namespaces
 namespaces.private parser quotations sequences
 specialized-arrays stack-checker stack-checker.errors
-system threads tools.test words ;
+system threads tools.test words alien.complex ;
 FROM: alien.c-types => float short ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-ARRAY: char
index 63356aa5bbbdffe4366e214d562f141990182016..a4597dc861fd32ad51cc905d331bb181448a66c8 100644 (file)
@@ -101,7 +101,7 @@ M: x86 %set-slot ( src obj slot -- ) [+] swap MOV ;
 M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ;
 
 :: two-operand ( dst src1 src2 rep -- dst src )
-    dst src2 eq? [ "Cannot handle this case" throw ] when
+    dst src2 eq? dst src1 eq? not and [ "Cannot handle this case" throw ] when
     dst src1 rep %copy
     dst src2 ; inline
 
index 649685b8985b012cde8208e022fadcea8500cc76..f4d4fd93e84277e1b3f945583073f8f207dcd8c8 100644 (file)
@@ -1,9 +1,11 @@
 IN: math.vectors.specialization.tests
 USING: compiler.tree.debugger math.vectors tools.test kernel
 kernel.private math specialized-arrays ;
-SPECIALIZED-ARRAY: double
-SPECIALIZED-ARRAY: complex-float
-SPECIALIZED-ARRAY: float
+QUALIFIED-WITH: alien.c-types c
+QUALIFIED-WITH: alien.complex c
+SPECIALIZED-ARRAY: c:double
+SPECIALIZED-ARRAY: c:complex-float
+SPECIALIZED-ARRAY: c:float
 
 [ V{ t } ] [
     [ { double-array double-array } declare distance 0.0 < not ] final-literals
index 32c354354f8e8837140de431175f7a92f15f0499..34b2c0bec61fcaa69f4f53108aa2ecec63977b2e 100644 (file)
@@ -171,14 +171,14 @@ HELP: vs+
 { $examples
     "With saturation:"
     { $example
-        "USING: math.vectors prettyprint specialized-arrays ;"
+        "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
         "SPECIALIZED-ARRAY: uchar"
         "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } vs+ ."
         "uchar-array{ 170 255 220 }"
     }
     "Without saturation:"
     { $example
-        "USING: math.vectors prettyprint specialized-arrays ;"
+        "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
         "SPECIALIZED-ARRAY: uchar"
         "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } v+ ."
         "uchar-array{ 170 14 220 }"
index 91c5c0326f4d420e7d625aa27b7a69d9c463621e..54ffc924811b54e2cf375006e9eb9fc39b66947f 100644 (file)
@@ -1,6 +1,6 @@
 IN: math.vectors.tests
 USING: math.vectors tools.test kernel specialized-arrays compiler
-kernel.private ;
+kernel.private alien.c-types ;
 SPECIALIZED-ARRAY: int
 
 [ { 1 2 3 } ] [ 1/2 { 2 4 6 } n*v ] unit-test
index 5959eddb07c1a294973698c4e2c71e37701dea56..a4a83f79a8ece652ebb3289c00f5093b0bc2820c 100644 (file)
@@ -1,5 +1,5 @@
 IN: pango.layouts.tests
-USING: pango.layouts tools.test glib fonts accessors
+USING: pango.layouts pango.cairo tools.test glib fonts accessors
 sequences combinators.short-circuit math destructors ;
 
 [ t ] [
index a2f508648da97b36daa3158cd907a3bf9987627e..c2fd27ec5df89d7179f843be444b3c842f63df62 100644 (file)
@@ -12,7 +12,7 @@ ABOUT: "sequences.complex"
 HELP: complex-sequence
 { $class-description "Sequence wrapper class that transforms a sequence of " { $link real } " number values into a sequence of " { $link complex } " values, treating the underlying sequence as pairs of alternating real and imaginary values."  }
 { $examples { $example """USING: prettyprint specialized-arrays
-sequences.complex sequences arrays ;
+sequences.complex sequences alien.c-types arrays ;
 SPECIALIZED-ARRAY: double
 double-array{ 1.0 -1.0 -2.0 2.0 3.0 0.0 } <complex-sequence> >array ."""
 "{ C{ 1.0 -1.0 } C{ -2.0 2.0 } C{ 3.0 0.0 } }" } } ;
@@ -21,7 +21,7 @@ HELP: <complex-sequence>
 { $values { "sequence" sequence } { "complex-sequence" complex-sequence } }
 { $description "Wraps " { $snippet "sequence" } " in a " { $link complex-sequence } "." }
 { $examples { $example """USING: prettyprint specialized-arrays
-sequences.complex sequences arrays ;
+sequences.complex sequences alien.c-types arrays ;
 SPECIALIZED-ARRAY: double
 double-array{ 1.0 -1.0 -2.0 2.0 3.0 0.0 } <complex-sequence> second ."""
 "C{ -2.0 2.0 }" } } ;
index 99c8adefb65a5e337403b6ca50468974b5513ba8..cebf69595f523ff91b61c90d186cbed939e8330b 100644 (file)
@@ -4,7 +4,7 @@
 USING: tools.test kernel serialize io io.streams.byte-array
 alien arrays byte-arrays bit-arrays specialized-arrays
 sequences math prettyprint parser classes math.constants
-io.encodings.binary random assocs serialize.private ;
+io.encodings.binary random assocs serialize.private alien.c-types ;
 SPECIALIZED-ARRAY: double
 IN: serialize.tests
 
index 070323a5d695433ae6897c1fcffbb01d97707918..b7d3371f45b5aaa499d1f68f874853672d34f88a 100755 (executable)
@@ -138,7 +138,7 @@ SPECIALIZED-ARRAY: __does_not_exist__ """ eval( -- )
 [ ] [
     """
 IN: specialized-arrays.tests
-USING: classes.struct specialized-arrays ;
+USING: alien.c-types classes.struct specialized-arrays ;
 
 STRUCT: __does_not_exist__ { x int } ;
 
index edff828b13dda9c0a5b24ddb066808190d6224f9..c7a045a7e1ed98f80a1756f6a8159317ee26e97a 100644 (file)
@@ -1,6 +1,6 @@
 IN: specialized-vectors.tests
 USING: specialized-arrays specialized-vectors
-tools.test kernel sequences ;
+tools.test kernel sequences alien.c-types ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-VECTOR: float
 SPECIALIZED-VECTOR: double
index 4035dbb3070ecbbd91fa7b70fb2df07b1a552fb4..93bf621acd9e168de4592df9b7ce34537f2a2e5c 100644 (file)
@@ -61,7 +61,7 @@ CONSTANT: max-un-path 108
 
 STRUCT: sockaddr-un
     { family ushort }
-    { path { "char" max-un-path } } ;
+    { path { char max-un-path } } ;
 
 CONSTANT: SOCK_STREAM 1
 CONSTANT: SOCK_DGRAM 2
index 7bbd8542e531a4bfd9cd06548759b45ee95a7705..70ce13b0e6748b3d34e8bde608b4af6ff1c2b7f5 100644 (file)
@@ -258,12 +258,13 @@ ARTICLE: "alien" "C library interface"
 $nl
 "The C library interface is entirely self-contained; there is no C code which one must write in order to wrap a library."
 $nl
-"C library interface words are found in the " { $vocab-link "alien" } " vocabulary."
+"C library interface words are found in the " { $vocab-link "alien" } " vocabulary and its subvocabularies."
 { $warning "C does not perform runtime type checking, automatic memory management or array bounds checks. Incorrect usage of C library functions can lead to crashes, data corruption, and security exploits." }
 { $subsection "loading-libs" }
 { $subsection "alien-invoke" }
 { $subsection "alien-callback" }
 { $subsection "c-data" }
+{ $subsection "classes.struct" }
 { $subsection "dll.private" }
 { $subsection "embedding" } ;
 
index 78c17a1cc0acad1e9e218208c138885c65d1e25e..53c3adcf3e6d0370cf1c0dbe225ece5373a8bc10 100644 (file)
@@ -1,6 +1,6 @@
 USING: kernel math namespaces make tools.test vectors sequences
 sequences.private hashtables io prettyprint assocs
-continuations specialized-arrays ;
+continuations specialized-arrays alien.c-types ;
 SPECIALIZED-ARRAY: double
 IN: assocs.tests
 
index 22474a75264efb18585a0514b26a84d31919419f..6a14280e6e8b7915864562d409af1d757d06a010 100644 (file)
@@ -7,6 +7,7 @@ io.encodings.utf16 assocs math.parser combinators.short-circuit
 fry namespaces combinators.smart splitting io.encodings.ascii
 arrays io.files.info unicode.case io.directories.search literals
 math.functions continuations ;
+FROM: alien.c-types => uchar ;
 IN: id3
 
 <PRIVATE
@@ -209,7 +210,7 @@ PRIVATE>
 
 : mp3>id3 ( path -- id3/f )
     [
-        [ <id3> ] dip "uchar" <mapped-array>
+        [ <id3> ] dip uchar <mapped-array>
         [ dup id3v1? [ read-v1-tags merge-id3v1 ] [ drop ] if ]
         [ dup id3v1+? [ read-v1+-tags merge-id3v1 ] [ drop ] if ]
         [ dup id3v2? [ read-v2-tags ] [ drop ] if ]
index 6f85389099c7c1f56637a09b5225f423593cfb44..e2e1c2012254509d31cefa8cff5aa0912e4f32cf 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2007, 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays jamshred.oint jamshred.tunnel kernel
-math.vectors sequences specialized-arrays tools.test ;
+math.vectors sequences specialized-arrays tools.test
+alien.c-types ;
 SPECIALIZED-ARRAY: float
 IN: jamshred.tunnel.tests