]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge Phil Dawes' VM work
authorSlava Pestov <slava@shill.local>
Sun, 20 Sep 2009 08:48:08 +0000 (03:48 -0500)
committerSlava Pestov <slava@shill.local>
Sun, 20 Sep 2009 08:48:08 +0000 (03:48 -0500)
153 files changed:
basis/alien/arrays/arrays-docs.factor
basis/alien/arrays/arrays.factor
basis/alien/c-types/c-types-docs.factor
basis/alien/c-types/c-types-tests.factor
basis/alien/c-types/c-types.factor
basis/alien/data/authors.txt [new file with mode: 0644]
basis/alien/data/data-docs.factor [new file with mode: 0644]
basis/alien/data/data.factor [new file with mode: 0644]
basis/alien/data/summary.txt [new file with mode: 0644]
basis/alien/fortran/fortran-tests.factor
basis/alien/fortran/fortran.factor
basis/alien/parser/parser.factor
basis/alien/prettyprint/prettyprint.factor
basis/alien/remote-control/remote-control.factor
basis/alien/structs/structs-docs.factor
basis/alien/structs/structs-tests.factor
basis/alien/structs/structs.factor
basis/alien/syntax/syntax.factor
basis/bit-arrays/bit-arrays.factor
basis/cairo/ffi/ffi.factor
basis/checksums/openssl/openssl.factor
basis/classes/struct/prettyprint/prettyprint.factor
basis/classes/struct/struct-tests.factor
basis/classes/struct/struct.factor
basis/cocoa/enumeration/enumeration.factor
basis/cocoa/plists/plists.factor
basis/compiler/codegen/codegen.factor
basis/compiler/tests/alien.factor
basis/compiler/tests/codegen.factor
basis/compiler/tests/intrinsics.factor
basis/compiler/tree/cleanup/cleanup-tests.factor
basis/compiler/tree/propagation/propagation-tests.factor
basis/core-foundation/numbers/numbers.factor
basis/cpu/ppc/ppc.factor
basis/cpu/x86/64/unix/unix.factor
basis/cpu/x86/64/winnt/winnt.factor
basis/cpu/x86/features/features.factor
basis/cpu/x86/x86.factor
basis/db/postgresql/lib/lib.factor
basis/db/sqlite/lib/lib.factor
basis/debugger/debugger.factor
basis/environment/unix/unix.factor
basis/environment/winnt/winnt.factor
basis/functors/functors-tests.factor
basis/furnace/recaptcha/authors.txt [new file with mode: 0644]
basis/furnace/recaptcha/example/authors.txt [new file with mode: 0644]
basis/furnace/recaptcha/example/example.factor [new file with mode: 0644]
basis/furnace/recaptcha/example/example.xml [new file with mode: 0644]
basis/furnace/recaptcha/recaptcha-docs.factor [new file with mode: 0644]
basis/furnace/recaptcha/recaptcha.factor [new file with mode: 0644]
basis/furnace/recaptcha/recaptcha.xml [new file with mode: 0644]
basis/furnace/recaptcha/summary.txt [new file with mode: 0644]
basis/furnace/recaptcha/tags.txt [new file with mode: 0644]
basis/game-input/dinput/dinput.factor
basis/game-input/dinput/keys-array/keys-array.factor
basis/game-input/iokit/iokit.factor
basis/html/templates/chloe/chloe-docs.factor
basis/images/memory/memory.factor
basis/io/backend/windows/nt/privileges/privileges.factor
basis/io/buffers/buffers-tests.factor
basis/io/buffers/buffers.factor
basis/io/files/info/windows/windows.factor
basis/io/files/windows/windows.factor
basis/io/mmap/mmap.factor
basis/io/monitors/windows/nt/nt.factor
basis/io/sockets/secure/openssl/openssl.factor
basis/io/sockets/sockets.factor
basis/io/sockets/unix/unix.factor
basis/io/sockets/windows/nt/nt.factor
basis/libc/libc.factor
basis/math/blas/matrices/matrices.factor
basis/math/blas/vectors/vectors.factor
basis/math/libm/libm.factor
basis/math/vectors/simd/functor/functor.factor
basis/math/vectors/simd/intrinsics/intrinsics.factor
basis/math/vectors/simd/simd.factor
basis/opengl/opengl.factor
basis/opengl/shaders/shaders.factor
basis/openssl/libcrypto/libcrypto.factor
basis/prettyprint/config/config-docs.factor
basis/prettyprint/prettyprint-docs.factor
basis/random/windows/windows.factor
basis/specialized-arrays/specialized-arrays-tests.factor
basis/specialized-arrays/specialized-arrays.factor
basis/stack-checker/alien/alien.factor
basis/stack-checker/errors/errors-docs.factor
basis/tools/deploy/config/config-docs.factor
basis/tools/disassembler/disassembler.factor
basis/tools/disassembler/udis/udis.factor
basis/ui/backend/cocoa/views/views.factor
basis/ui/backend/windows/windows.factor
basis/ui/gadgets/buttons/buttons.factor
basis/unix/bsd/macosx/macosx.factor
basis/unix/bsd/netbsd/structs/structs.factor
basis/unix/process/process.factor
basis/unix/utilities/utilities.factor
basis/unix/utmpx/utmpx.factor
basis/windows/advapi32/advapi32.factor
basis/windows/com/com.factor
basis/windows/com/syntax/syntax.factor
basis/windows/com/wrapper/wrapper.factor
basis/windows/dinput/constants/constants.factor
basis/windows/dragdrop-listener/dragdrop-listener.factor
basis/windows/errors/errors.factor
basis/windows/kernel32/kernel32.factor
basis/windows/offscreen/offscreen.factor
basis/windows/ole32/ole32.factor
basis/windows/types/types.factor
basis/windows/usp10/usp10.factor
basis/windows/winsock/winsock.factor
basis/x11/xlib/xlib.factor
core/alien/strings/strings-tests.factor
core/bootstrap/stage1.factor
core/classes/tuple/parser/parser.factor
core/combinators/combinators-docs.factor
core/math/parser/parser-docs.factor
core/syntax/syntax-docs.factor
extra/alien/inline/inline.factor
extra/alien/inline/syntax/syntax-tests.factor
extra/alien/inline/types/types.factor
extra/alien/marshall/marshall-docs.factor
extra/alien/marshall/marshall.factor
extra/alien/marshall/private/private.factor
extra/alien/marshall/structs/structs.factor
extra/audio/wav/wav.factor
extra/benchmark/spectral-norm/spectral-norm.factor
extra/benchmark/yuv-to-rgb/yuv-to-rgb.factor
extra/bunny/model/model.factor
extra/curses/curses.factor
extra/curses/ffi/ffi.factor
extra/ecdsa/ecdsa.factor
extra/freetype/freetype.factor
extra/gpu/demos/bunny/bunny.factor
extra/gpu/render/render.factor
extra/gpu/shaders/shaders.factor
extra/gpu/state/state.factor
extra/gpu/textures/textures.factor
extra/half-floats/half-floats-tests.factor
extra/half-floats/half-floats.factor
extra/io/serial/unix/termios/bsd/bsd.factor
extra/io/serial/unix/termios/linux/linux.factor
extra/io/serial/unix/unix.factor
extra/irc/client/internals/internals-tests.factor
extra/irc/client/internals/internals.factor
extra/jamshred/gl/gl.factor
extra/memory/piles/piles.factor
extra/openal/openal.factor
extra/qtkit/qtkit.factor
extra/slides/slides.factor
extra/synth/buffers/buffers.factor
extra/system-info/windows/ce/ce.factor
extra/tokyo/alien/tcrdb/tcrdb.factor
extra/websites/concatenative/concatenative.factor

index db4a7bf5958daa9910b75fcf9c50fa6ac4c801a2..74174485fe08f043284b7786f7b3b47435c88421 100755 (executable)
@@ -1,5 +1,5 @@
+USING: help.syntax help.markup byte-arrays alien.c-types alien.data ;\r
 IN: alien.arrays\r
-USING: help.syntax help.markup byte-arrays alien.c-types ;\r
 \r
 ARTICLE: "c-arrays" "C arrays"\r
 "C arrays are allocated in the same manner as other C data; see " { $link "c-byte-arrays" } " and " { $link "malloc" } "."\r
index a69f7609b1847ad54f89ae83148d63ed7d11be7c..ee75d22c2c74618c0775fc5337551dd063210c1d 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.strings alien.c-types alien.accessors
-arrays words sequences math kernel namespaces fry libc cpu.architecture
+USING: alien alien.strings alien.c-types alien.data alien.accessors
+arrays words sequences math kernel namespaces fry cpu.architecture
 io.encodings.utf8 accessors ;
 IN: alien.arrays
 
@@ -22,15 +22,15 @@ M: array c-type-align first c-type-align ;
 
 M: array c-type-stack-align? drop f ;
 
-M: array unbox-parameter drop "void*" unbox-parameter ;
+M: array unbox-parameter drop void* unbox-parameter ;
 
-M: array unbox-return drop "void*" unbox-return ;
+M: array unbox-return drop void* unbox-return ;
 
-M: array box-parameter drop "void*" box-parameter ;
+M: array box-parameter drop void* box-parameter ;
 
-M: array box-return drop "void*" box-return ;
+M: array box-return drop void* box-return ;
 
-M: array stack-size drop "void*" stack-size ;
+M: array stack-size drop void* stack-size ;
 
 M: array c-type-boxer-quot
     unclip
@@ -41,7 +41,7 @@ M: array c-type-boxer-quot
 M: array c-type-unboxer-quot drop [ >c-ptr ] ;
 
 PREDICATE: string-type < pair
-    first2 [ "char*" = ] [ word? ] bi* and ;
+    first2 [ char* = ] [ word? ] bi* and ;
 
 M: string-type c-type ;
 
@@ -50,37 +50,37 @@ M: string-type c-type-class drop object ;
 M: string-type c-type-boxed-class drop object ;
 
 M: string-type heap-size
-    drop "void*" heap-size ;
+    drop void* heap-size ;
 
 M: string-type c-type-align
-    drop "void*" c-type-align ;
+    drop void* c-type-align ;
 
 M: string-type c-type-stack-align?
-    drop "void*" c-type-stack-align? ;
+    drop void* c-type-stack-align? ;
 
 M: string-type unbox-parameter
-    drop "void*" unbox-parameter ;
+    drop void* unbox-parameter ;
 
 M: string-type unbox-return
-    drop "void*" unbox-return ;
+    drop void* unbox-return ;
 
 M: string-type box-parameter
-    drop "void*" box-parameter ;
+    drop void* box-parameter ;
 
 M: string-type box-return
-    drop "void*" box-return ;
+    drop void* box-return ;
 
 M: string-type stack-size
-    drop "void*" stack-size ;
+    drop void* stack-size ;
 
 M: string-type c-type-rep
     drop int-rep ;
 
 M: string-type c-type-boxer
-    drop "void*" c-type-boxer ;
+    drop void* c-type-boxer ;
 
 M: string-type c-type-unboxer
-    drop "void*" c-type-unboxer ;
+    drop void* c-type-unboxer ;
 
 M: string-type c-type-boxer-quot
     second '[ _ alien>string ] ;
@@ -94,6 +94,8 @@ M: string-type c-type-getter
 M: string-type c-type-setter
     drop [ set-alien-cell ] ;
 
-{ "char*" utf8 } "char*" typedef
-"char*" "uchar*" typedef
+{ char* utf8 } char* typedef
+char* uchar* typedef
 
+char  char*  "pointer-c-type" set-word-prop
+uchar uchar* "pointer-c-type" set-word-prop
index d9e1f7124accd7a86747cd7cc214bf21fd0bf11a..a9613d2c9fac49797f52aeb7d0d99e16000c10c7 100755 (executable)
@@ -1,7 +1,25 @@
-IN: alien.c-types
 USING: alien help.syntax help.markup libc kernel.private
 byte-arrays math strings hashtables alien.syntax alien.strings sequences
 io.encodings.string debugger destructors vocabs.loader ;
+IN: alien.c-types
+
+HELP: byte-length
+{ $values { "seq" "A byte array or float array" } { "n" "a non-negative integer" } }
+{ $contract "Outputs the size of the byte array, struct, or specialized array data in bytes." } ;
+
+HELP: heap-size
+{ $values { "type" string } { "size" integer } }
+{ $description "Outputs the number of bytes needed for a heap-allocated value of this C type." }
+{ $examples
+    "On a 32-bit system, you will get the following output:"
+    { $unchecked-example "USE: alien\n\"void*\" heap-size ." "4" }
+}
+{ $errors "Throws a " { $link no-c-type } " error if the type does not exist." } ;
+
+HELP: stack-size
+{ $values { "type" string } { "size" integer } }
+{ $description "Outputs the number of bytes to reserve on the C stack by a value of this C type. In most cases this is equal to " { $link heap-size } ", except on some platforms where C structs are passed by invisible reference, in which case a C struct type only uses as much space as a pointer on the C stack." }
+{ $errors "Throws a " { $link no-c-type } " error if the type does not exist." } ;
 
 HELP: <c-type>
 { $values { "type" hashtable } }
@@ -20,24 +38,6 @@ HELP: c-type
 { $description "Looks up a C type by name." }
 { $errors "Throws a " { $link no-c-type } " error if the type does not exist." } ;
 
-HELP: heap-size
-{ $values { "type" string } { "size" integer } }
-{ $description "Outputs the number of bytes needed for a heap-allocated value of this C type." }
-{ $examples
-    "On a 32-bit system, you will get the following output:"
-    { $unchecked-example "USE: alien\n\"void*\" heap-size ." "4" }
-}
-{ $errors "Throws a " { $link no-c-type } " error if the type does not exist." } ;
-
-HELP: stack-size
-{ $values { "type" string } { "size" integer } }
-{ $description "Outputs the number of bytes to reserve on the C stack by a value of this C type. In most cases this is equal to " { $link heap-size } ", except on some platforms where C structs are passed by invisible reference, in which case a C struct type only uses as much space as a pointer on the C stack." }
-{ $errors "Throws a " { $link no-c-type } " error if the type does not exist." } ;
-
-HELP: byte-length
-{ $values { "seq" "A byte array or float array" } { "n" "a non-negative integer" } }
-{ $contract "Outputs the size of the byte array or float array data in bytes as presented to the C library interface." } ;
-
 HELP: c-getter
 { $values { "name" string } { "quot" { $quotation "( c-ptr n -- obj )" } } }
 { $description "Outputs a quotation which reads values of this C type from a C structure." }
@@ -48,49 +48,6 @@ HELP: c-setter
 { $description "Outputs a quotation which writes values of this C type to a C structure." }
 { $errors "Throws an error if the type does not exist." } ;
 
-HELP: <c-array>
-{ $values { "len" "a non-negative integer" } { "c-type" "a C type" } { "array" byte-array } }
-{ $description "Creates a byte array large enough to hold " { $snippet "n" } " values of a C type." }
-{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." }
-{ $errors "Throws an error if the type does not exist, the necessary specialized array vocabulary is not loaded, or the requested size is negative." } ;
-
-HELP: <c-object>
-{ $values { "type" "a C type" } { "array" byte-array } }
-{ $description "Creates a byte array suitable for holding a value with the given C type." }
-{ $errors "Throws an " { $link no-c-type } " error if the type does not exist." } ;
-
-{ <c-object> malloc-object } related-words
-
-HELP: memory>byte-array
-{ $values { "alien" c-ptr } { "len" "a non-negative integer" } { "byte-array" byte-array } }
-{ $description "Reads " { $snippet "len" } " bytes starting from " { $snippet "base" } " and stores them in a new byte array." } ;
-
-HELP: byte-array>memory
-{ $values { "byte-array" byte-array } { "base" c-ptr } }
-{ $description "Writes a byte array to memory starting from the " { $snippet "base" } " address." }
-{ $warning "This word is unsafe. Improper use can corrupt memory." } ;
-
-HELP: malloc-array
-{ $values { "n" "a non-negative integer" } { "type" "a C type" } { "alien" alien } }
-{ $description "Allocates an unmanaged memory block large enough to hold " { $snippet "n" } " values of a C type, then wraps the memory in a sequence object using " { $link <c-direct-array> } "." }
-{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." }
-{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
-{ $errors "Throws an error if the type does not exist, if the requested size is negative, if a direct specialized array class appropriate to the type is not loaded, or if memory allocation fails." } ;
-
-HELP: malloc-object
-{ $values { "type" "a C type" } { "alien" alien } }
-{ $description "Allocates an unmanaged memory block large enough to hold a value of a C type." }
-{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
-{ $errors "Throws an error if the type does not exist or if memory allocation fails." } ;
-
-HELP: malloc-byte-array
-{ $values { "byte-array" byte-array } { "alien" alien } }
-{ $description "Allocates an unmanaged memory block of the same size as the byte array, and copies the contents of the byte array there." }
-{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
-{ $errors "Throws an error if memory allocation fails." } ;
-
-{ <c-array> <c-direct-array> malloc-array } related-words
-
 HELP: box-parameter
 { $values { "n" integer } { "ctype" string } }
 { $description "Generates code for converting a C value stored at  offset " { $snippet "n" } " from the top of the stack into a Factor object to be pushed on the data stack." }
@@ -116,48 +73,6 @@ HELP: define-out
 { $description "Defines a word " { $snippet "<" { $emphasis "name" } ">" } " with stack effect " { $snippet "( value -- array )" } ". This word allocates a byte array large enough to hold a value with C type " { $snippet "name" } ", and writes the value at the top of the stack to the array." }
 { $notes "This is an internal word called when defining C types, there is no need to call it on your own." } ;
 
-{ string>alien alien>string malloc-string } related-words
-
-HELP: malloc-string
-{ $values { "string" string } { "encoding" "an encoding descriptor" } { "alien" c-ptr } }
-{ $description "Encodes a string together with a trailing null code point using the given encoding, and stores the resulting bytes in a freshly-allocated unmanaged memory block." }
-{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
-{ $errors "Throws an error if one of the following conditions occurs:"
-    { $list
-        "the string contains null code points"
-        "the string contains characters not representable using the encoding specified"
-        "memory allocation fails"
-    }
-} ;
-
-HELP: require-c-array
-{ $values { "c-type" "a C type" } }
-{ $description "Generates a specialized array of " { $snippet "c-type" } " using the " { $link <c-array> } " or " { $link <c-direct-array> } " vocabularies." }
-{ $notes "This word must be called inside a compilation unit. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence types loaded." } ;
-
-HELP: <c-direct-array>
-{ $values { "alien" c-ptr } { "len" integer } { "c-type" "a C type" } { "array" "a specialized direct array" } }
-{ $description "Constructs a new specialized array of length " { $snippet "len" } " and element type " { $snippet "c-type" } " over the range of memory referenced by " { $snippet "alien" } "." }
-{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } ;
-
-ARTICLE: "c-strings" "C strings"
-"C string types are arrays with shape " { $snippet "{ \"char*\" encoding }" } ", where " { $snippet "encoding" } " is an encoding descriptor. The type " { $snippet "\"char*\"" } " is an alias for " { $snippet "{ \"char*\" utf8 }" } ". See " { $link "encodings-descriptors" } " for information about encoding descriptors."
-$nl
-"Passing a Factor string to a C function expecting a C string allocates a " { $link byte-array } " in the Factor heap; the string is then converted to the requested format and a raw pointer is passed to the function."
-$nl
-"If the conversion fails, for example if the string contains null bytes or characters with values higher than 255, a " { $link c-string-error. } " is thrown."
-$nl
-"Care must be taken if the C function expects a " { $snippet "char*" } " with a length in bytes, rather than a null-terminated " { $snippet "char*" } "; passing the result of calling " { $link length } " on the string object will not suffice. This is because a Factor string of " { $emphasis "n" } " characters will not necessarily encode to " { $emphasis "n" } " bytes. The correct idiom for C functions which take a string with a length is to first encode the string using " { $link encode } ", and then pass the resulting byte array together with the length of this byte array."
-$nl
-"Sometimes a C function has a parameter type of " { $snippet "void*" } ", and various data types, among them strings, can be passed in. In this case, strings are not automatically converted to aliens, and instead you must call one of these words:"
-{ $subsection string>alien }
-{ $subsection malloc-string }
-"The first allocates " { $link byte-array } "s, and the latter allocates manually-managed memory which is not moved by the garbage collector and has to be explicitly freed by calling " { $link free } ". See " { $link "byte-arrays-gc" } " for a discussion of the two approaches."
-$nl
-"A word to read strings from arbitrary addresses:"
-{ $subsection alien>string }
-"For example, if a C function returns a " { $snippet "char*" } " but stipulates that the caller must deallocate the memory afterward, you must define the function as returning " { $snippet "void*" } ", and call one of the above words before passing the pointer to " { $link free } "." ;
-
 ARTICLE: "byte-arrays-gc" "Byte arrays and the garbage collector"
 "The Factor garbage collector can move byte arrays around, and it is only safe to pass byte arrays to C functions if the garbage collector will not run while C code still has a reference to the data."
 $nl
@@ -234,61 +149,3 @@ $nl
 "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." ;
-
-ARTICLE: "c-byte-arrays" "Passing data in byte arrays"
-"Instances of the " { $link byte-array } " class can be passed to C functions; the C function receives a pointer to the first element of the array."
-$nl
-"Byte arrays can be allocated directly with a byte count using the " { $link <byte-array> } " word. However in most cases, instead of computing a size in bytes directly, it is easier to use a higher-level word which expects C type and outputs a byte array large enough to hold that type:"
-{ $subsection <c-object> }
-{ $subsection <c-array> }
-{ $warning
-"The Factor garbage collector can move byte arrays around, and code passing byte arrays to C must obey important guidelines. See " { $link "byte-arrays-gc" } "." }
-{ $see-also "c-arrays" } ;
-
-ARTICLE: "malloc" "Manual memory management"
-"Sometimes data passed to C functions must be allocated at a fixed address. See " { $link "byte-arrays-gc" } " for an explanation of when this is the case."
-$nl
-"Allocating a C datum with a fixed address:"
-{ $subsection malloc-object }
-{ $subsection malloc-array }
-{ $subsection malloc-byte-array }
-"There is a set of words in the " { $vocab-link "libc" } " vocabulary which directly call C standard library memory management functions:"
-{ $subsection malloc }
-{ $subsection calloc }
-{ $subsection realloc }
-"You must always free pointers returned by any of the above words when the block of memory is no longer in use:"
-{ $subsection free }
-"Utilities for automatically freeing memory in conjunction with " { $link with-destructors } ":"
-{ $subsection &free }
-{ $subsection |free }
-"The " { $link &free } " and " { $link |free } " words are generated using " { $link "alien.destructors" } "."
-$nl
-"You can unsafely copy a range of bytes from one memory location to another:"
-{ $subsection memcpy }
-"You can copy a range of bytes from memory into a byte array:"
-{ $subsection memory>byte-array }
-"You can copy a byte array to memory unsafely:"
-{ $subsection byte-array>memory } ;
-
-ARTICLE: "c-data" "Passing data between Factor and C"
-"Two defining characteristics of Factor are dynamic typing and automatic memory management, which are somewhat incompatible with the machine-level data model exposed by C. Factor's C library interface defines its own set of C data types, distinct from Factor language types, together with automatic conversion between Factor values and C types. For example, C integer types must be declared and are fixed-width, whereas Factor supports arbitrary-precision integers."
-$nl
-"Furthermore, Factor's garbage collector can move objects in memory; for a discussion of the consequences, see " { $link "byte-arrays-gc" } "."
-{ $subsection "c-types-specs" }
-{ $subsection "c-byte-arrays" }
-{ $subsection "malloc" }
-{ $subsection "c-strings" }
-{ $subsection "c-arrays" }
-{ $subsection "c-out-params" }
-"Important guidelines for passing data in byte arrays:"
-{ $subsection "byte-arrays-gc" }
-"C-style enumerated types are supported:"
-{ $subsection POSTPONE: C-ENUM: }
-"C types can be aliased for convenience and consitency with native library documentation:"
-{ $subsection POSTPONE: TYPEDEF: }
-"New C types can be defined:"
-{ $subsection "c-structs" }
-{ $subsection "c-unions" }
-"A utility for defining " { $link "destructors" } " for deallocating memory:"
-{ $subsection "alien.destructors" }
-{ $see-also "aliens" } ;
index bfeff5f1de2bc0186006b5621a39f44de4c5136b..792e7d416acf1aa86f1c5762a7e7142dcb429f4c 100644 (file)
@@ -43,7 +43,7 @@ TYPEDEF: int* MyIntArray
 
 TYPEDEF: uchar* MyLPBYTE
 
-[ t ] [ { "char*" utf8 } c-type "MyLPBYTE" c-type = ] unit-test
+[ t ] [ { char* utf8 } c-type "MyLPBYTE" c-type = ] unit-test
 
 [
     0 B{ 1 2 3 4 } <displaced-alien> <void*>
index 35a9627d503b63c9474c6dbd7a12a86a2a20be50..fa27e29c0419a401a5bc36f3374ac2a83d799782 100755 (executable)
@@ -1,18 +1,27 @@
 ! Copyright (C) 2004, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: byte-arrays arrays assocs kernel kernel.private libc math
+USING: byte-arrays arrays assocs kernel kernel.private math
 namespaces make parser sequences strings words splitting math.parser
 cpu.architecture alien alien.accessors alien.strings quotations
 layouts system compiler.units io io.files io.encodings.binary
 io.streams.memory accessors combinators effects continuations fry
-classes vocabs vocabs.loader ;
+classes vocabs vocabs.loader words.symbol ;
+QUALIFIED: math
 IN: alien.c-types
 
+SYMBOLS:
+    char uchar
+    short ushort
+    int uint
+    long ulong
+    longlong ulonglong
+    float double
+    void* bool
+    void ;
+
 DEFER: <int>
 DEFER: *char
 
-: little-endian? ( -- ? ) 1 <int> *char 1 = ; foldable
-
 TUPLE: abstract-c-type
 { class class initial: object }
 { boxed-class class initial: object }
@@ -40,149 +49,124 @@ global [
 
 ERROR: no-c-type name ;
 
-: (c-type) ( name -- type/f )
-    c-types get-global at dup [
-        dup string? [ (c-type) ] when
-    ] when ;
+PREDICATE: c-type-word < word
+    "c-type" word-prop ;
+
+UNION: c-type-name string c-type-word ;
 
 ! C type protocol
 GENERIC: c-type ( name -- type ) foldable
 
-: resolve-pointer-type ( name -- name )
-    c-types get at dup string?
-    [ "*" append ] [ drop "void*" ] if
-    c-type ;
+GENERIC: resolve-pointer-type ( name -- c-type )
+
+M: word resolve-pointer-type
+    dup "pointer-c-type" word-prop
+    [ ] [ drop void* ] ?if ;
+M: string resolve-pointer-type
+    dup "*" append dup c-types get at
+    [ nip ] [
+        drop
+        c-types get at dup c-type-name?
+        [ resolve-pointer-type ] [ drop void* ] if
+    ] if ;
 
 : resolve-typedef ( name -- type )
-    dup string? [ c-type ] when ;
+    dup c-type-name? [ c-type ] when ;
 
-: parse-array-type ( name -- array )
+: parse-array-type ( name -- dims type )
     "[" split unclip
-    [ [ "]" ?tail drop string>number ] map ] dip prefix ;
+    [ [ "]" ?tail drop string>number ] map ] dip ;
 
 M: string c-type ( name -- type )
     CHAR: ] over member? [
-        parse-array-type
+        parse-array-type prefix
     ] [
-        dup c-types get at [
-            resolve-typedef
-        ] [
+        dup c-types get at [ ] [
             "*" ?tail [ resolve-pointer-type ] [ no-c-type ] if
-        ] ?if
+        ] ?if resolve-typedef
     ] if ;
 
+M: word c-type
+    "c-type" word-prop resolve-typedef ;
+
+: void? ( c-type -- ? )
+    { void "void" } member? ;
+
 GENERIC: c-struct? ( type -- ? )
 
 M: object c-struct?
     drop f ;
-M: string c-struct?
-    dup "void" = [ drop f ] [ c-type c-struct? ] if ;
+M: c-type-name c-struct?
+    dup void? [ drop f ] [ c-type c-struct? ] if ;
 
 ! These words being foldable means that words need to be
 ! recompiled if a C type is redefined. Even so, folding the
 ! size facilitates some optimizations.
-GENERIC: heap-size ( type -- size ) foldable
-
-M: string heap-size c-type heap-size ;
-
-M: abstract-c-type heap-size size>> ;
-
-GENERIC: require-c-array ( c-type -- )
-
-M: array require-c-array first require-c-array ;
-
-GENERIC: c-array-constructor ( c-type -- word )
-
-GENERIC: c-(array)-constructor ( c-type -- word )
-
-GENERIC: c-direct-array-constructor ( c-type -- word )
-
-GENERIC: <c-array> ( len c-type -- array )
-
-M: string <c-array>
-    c-array-constructor execute( len -- array ) ; inline
-
-GENERIC: (c-array) ( len c-type -- array )
-
-M: string (c-array)
-    c-(array)-constructor execute( len -- array ) ; inline
-
-GENERIC: <c-direct-array> ( alien len c-type -- array )
-
-M: string <c-direct-array>
-    c-direct-array-constructor execute( alien len -- array ) ; inline
-
-: malloc-array ( n type -- alien )
-    [ heap-size calloc ] [ <c-direct-array> ] 2bi ; inline
-
-: (malloc-array) ( n type -- alien )
-    [ heap-size * malloc ] [ <c-direct-array> ] 2bi ; inline
-
 GENERIC: c-type-class ( name -- class )
 
 M: abstract-c-type c-type-class class>> ;
 
-M: string c-type-class c-type c-type-class ;
+M: c-type-name c-type-class c-type c-type-class ;
 
 GENERIC: c-type-boxed-class ( name -- class )
 
 M: abstract-c-type c-type-boxed-class boxed-class>> ;
 
-M: string c-type-boxed-class c-type c-type-boxed-class ;
+M: c-type-name c-type-boxed-class c-type c-type-boxed-class ;
 
 GENERIC: c-type-boxer ( name -- boxer )
 
 M: c-type c-type-boxer boxer>> ;
 
-M: string c-type-boxer c-type c-type-boxer ;
+M: c-type-name c-type-boxer c-type c-type-boxer ;
 
 GENERIC: c-type-boxer-quot ( name -- quot )
 
 M: abstract-c-type c-type-boxer-quot boxer-quot>> ;
 
-M: string c-type-boxer-quot c-type c-type-boxer-quot ;
+M: c-type-name c-type-boxer-quot c-type c-type-boxer-quot ;
 
 GENERIC: c-type-unboxer ( name -- boxer )
 
 M: c-type c-type-unboxer unboxer>> ;
 
-M: string c-type-unboxer c-type c-type-unboxer ;
+M: c-type-name c-type-unboxer c-type c-type-unboxer ;
 
 GENERIC: c-type-unboxer-quot ( name -- quot )
 
 M: abstract-c-type c-type-unboxer-quot unboxer-quot>> ;
 
-M: string c-type-unboxer-quot c-type c-type-unboxer-quot ;
+M: c-type-name c-type-unboxer-quot c-type c-type-unboxer-quot ;
 
 GENERIC: c-type-rep ( name -- rep )
 
 M: c-type c-type-rep rep>> ;
 
-M: string c-type-rep c-type c-type-rep ;
+M: c-type-name c-type-rep c-type c-type-rep ;
 
 GENERIC: c-type-getter ( name -- quot )
 
 M: c-type c-type-getter getter>> ;
 
-M: string c-type-getter c-type c-type-getter ;
+M: c-type-name c-type-getter c-type c-type-getter ;
 
 GENERIC: c-type-setter ( name -- quot )
 
 M: c-type c-type-setter setter>> ;
 
-M: string c-type-setter c-type c-type-setter ;
+M: c-type-name c-type-setter c-type c-type-setter ;
 
 GENERIC: c-type-align ( name -- n )
 
 M: abstract-c-type c-type-align align>> ;
 
-M: string c-type-align c-type c-type-align ;
+M: c-type-name c-type-align c-type c-type-align ;
 
 GENERIC: c-type-stack-align? ( name -- ? )
 
 M: c-type c-type-stack-align? stack-align?>> ;
 
-M: string c-type-stack-align? c-type c-type-stack-align? ;
+M: c-type-name c-type-stack-align? c-type c-type-stack-align? ;
 
 : c-type-box ( n type -- )
     [ c-type-rep ] [ c-type-boxer [ "No boxer" throw ] unless* ] bi
@@ -196,42 +180,39 @@ GENERIC: box-parameter ( n ctype -- )
 
 M: c-type box-parameter c-type-box ;
 
-M: string box-parameter c-type box-parameter ;
+M: c-type-name box-parameter c-type box-parameter ;
 
 GENERIC: box-return ( ctype -- )
 
 M: c-type box-return f swap c-type-box ;
 
-M: string box-return c-type box-return ;
+M: c-type-name box-return c-type box-return ;
 
 GENERIC: unbox-parameter ( n ctype -- )
 
 M: c-type unbox-parameter c-type-unbox ;
 
-M: string unbox-parameter c-type unbox-parameter ;
+M: c-type-name unbox-parameter c-type unbox-parameter ;
 
 GENERIC: unbox-return ( ctype -- )
 
 M: c-type unbox-return f swap c-type-unbox ;
 
-M: string unbox-return c-type unbox-return ;
+M: c-type-name unbox-return c-type unbox-return ;
 
-GENERIC: stack-size ( type -- size ) foldable
+: little-endian? ( -- ? ) 1 <int> *char 1 = ; foldable
 
-M: string stack-size c-type stack-size ;
+GENERIC: heap-size ( type -- size ) foldable
 
-M: c-type stack-size size>> cell align ;
+M: c-type-name heap-size c-type heap-size ;
 
-MIXIN: value-type
+M: abstract-c-type heap-size size>> ;
 
-M: value-type c-type-rep drop int-rep ;
+GENERIC: stack-size ( type -- size ) foldable
 
-M: value-type c-type-getter
-    drop [ swap <displaced-alien> ] ;
+M: c-type-name stack-size c-type stack-size ;
 
-M: value-type c-type-setter ( type -- quot )
-    [ c-type-getter ] [ c-type-unboxer-quot ] [ heap-size ] tri
-    '[ @ swap @ _ memcpy ] ;
+M: c-type stack-size size>> cell align ;
 
 GENERIC: byte-length ( seq -- n ) flushable
 
@@ -239,6 +220,8 @@ M: byte-array byte-length length ; inline
 
 M: f byte-length drop 0 ; inline
 
+MIXIN: value-type
+
 : c-getter ( name -- quot )
     c-type-getter [
         [ "Cannot read struct fields with this type" throw ]
@@ -252,42 +235,29 @@ M: f byte-length drop 0 ; inline
         [ "Cannot write struct fields with this type" throw ]
     ] unless* ;
 
-: <c-object> ( type -- array )
-    heap-size <byte-array> ; inline
-
-: (c-object) ( type -- array )
-    heap-size (byte-array) ; inline
-
-: malloc-object ( type -- alien )
-    1 swap heap-size calloc ; inline
-
-: (malloc-object) ( type -- alien )
-    heap-size malloc ; inline
-
-: malloc-byte-array ( byte-array -- alien )
-    dup byte-length [ nip malloc dup ] 2keep memcpy ;
-
-: memory>byte-array ( alien len -- byte-array )
-    [ nip (byte-array) dup ] 2keep memcpy ;
-
-: malloc-string ( string encoding -- alien )
-    string>alien malloc-byte-array ;
-
-M: memory-stream stream-read
-    [
-        [ index>> ] [ alien>> ] bi <displaced-alien>
-        swap memory>byte-array
-    ] [ [ + ] change-index drop ] 2bi ;
-
-: byte-array>memory ( byte-array base -- )
-    swap dup byte-length memcpy ; inline
-
 : array-accessor ( type quot -- def )
     [
         \ swap , [ heap-size , [ * >fixnum ] % ] [ % ] bi*
     ] [ ] make ;
 
-: typedef ( old new -- ) c-types get set-at ;
+GENERIC: typedef ( old new -- )
+
+PREDICATE: typedef-word < c-type-word
+    "c-type" word-prop c-type-name? ;
+
+M: string typedef ( old new -- ) c-types get set-at ;
+M: word typedef ( old new -- )
+    {
+        [ nip define-symbol ]
+        [ name>> typedef ]
+        [ swap "c-type" set-word-prop ]
+        [
+            swap dup c-type-name? [
+                resolve-pointer-type
+                "pointer-c-type" set-word-prop
+            ] [ 2drop ] if
+        ]
+    } 2cleave ;
 
 TUPLE: long-long-type < c-type ;
 
@@ -312,36 +282,33 @@ M: long-long-type box-return ( type -- )
 
 : define-out ( name -- )
     [ "alien.c-types" constructor-word ]
-    [ dup c-setter '[ _ <c-object> [ 0 @ ] keep ] ] bi
+    [ dup c-setter '[ _ heap-size <byte-array> [ 0 @ ] keep ] ] bi
     (( value -- c-ptr )) define-inline ;
 
-: >c-bool ( ? -- int ) 1 0 ? ; inline
-
-: c-bool> ( int -- ? ) 0 = not ; inline
-
 : define-primitive-type ( type name -- )
     [ typedef ]
-    [ define-deref ]
-    [ define-out ]
+    [ name>> define-deref ]
+    [ name>> define-out ]
     tri ;
 
-: malloc-file-contents ( path -- alien len )
-    binary file-contents [ malloc-byte-array ] [ length ] bi ;
-
 : if-void ( type true false -- )
-    pick "void" = [ drop nip call ] [ nip call ] if ; inline
+    pick void? [ drop nip call ] [ nip call ] if ; inline
 
 CONSTANT: primitive-types
     {
-        "char" "uchar"
-        "short" "ushort"
-        "int" "uint"
-        "long" "ulong"
-        "longlong" "ulonglong"
-        "float" "double"
-        "void*" "bool"
+        char uchar
+        short ushort
+        int uint
+        long ulong
+        longlong ulonglong
+        float double
+        void* bool
     }
 
+SYMBOLS:
+    ptrdiff_t intptr_t size_t
+    char* uchar* ;
+
 [
     <c-type>
         c-ptr >>class
@@ -353,7 +320,7 @@ CONSTANT: primitive-types
         [ >c-ptr ] >>unboxer-quot
         "box_alien" >>boxer
         "alien_offset" >>unboxer
-    "void*" define-primitive-type
+    \ void* define-primitive-type
 
     <long-long-type>
         integer >>class
@@ -364,7 +331,7 @@ CONSTANT: primitive-types
         8 >>align
         "box_signed_8" >>boxer
         "to_signed_8" >>unboxer
-    "longlong" define-primitive-type
+    \ longlong define-primitive-type
 
     <long-long-type>
         integer >>class
@@ -375,7 +342,7 @@ CONSTANT: primitive-types
         8 >>align
         "box_unsigned_8" >>boxer
         "to_unsigned_8" >>unboxer
-    "ulonglong" define-primitive-type
+    \ ulonglong define-primitive-type
 
     <c-type>
         integer >>class
@@ -386,7 +353,7 @@ CONSTANT: primitive-types
         bootstrap-cell >>align
         "box_signed_cell" >>boxer
         "to_fixnum" >>unboxer
-    "long" define-primitive-type
+    \ long define-primitive-type
 
     <c-type>
         integer >>class
@@ -397,7 +364,7 @@ CONSTANT: primitive-types
         bootstrap-cell >>align
         "box_unsigned_cell" >>boxer
         "to_cell" >>unboxer
-    "ulong" define-primitive-type
+    \ ulong define-primitive-type
 
     <c-type>
         integer >>class
@@ -408,7 +375,7 @@ CONSTANT: primitive-types
         4 >>align
         "box_signed_4" >>boxer
         "to_fixnum" >>unboxer
-    "int" define-primitive-type
+    \ int define-primitive-type
 
     <c-type>
         integer >>class
@@ -419,7 +386,7 @@ CONSTANT: primitive-types
         4 >>align
         "box_unsigned_4" >>boxer
         "to_cell" >>unboxer
-    "uint" define-primitive-type
+    \ uint define-primitive-type
 
     <c-type>
         fixnum >>class
@@ -430,7 +397,7 @@ CONSTANT: primitive-types
         2 >>align
         "box_signed_2" >>boxer
         "to_fixnum" >>unboxer
-    "short" define-primitive-type
+    \ short define-primitive-type
 
     <c-type>
         fixnum >>class
@@ -441,7 +408,7 @@ CONSTANT: primitive-types
         2 >>align
         "box_unsigned_2" >>boxer
         "to_cell" >>unboxer
-    "ushort" define-primitive-type
+    \ ushort define-primitive-type
 
     <c-type>
         fixnum >>class
@@ -452,7 +419,7 @@ CONSTANT: primitive-types
         1 >>align
         "box_signed_1" >>boxer
         "to_fixnum" >>unboxer
-    "char" define-primitive-type
+    \ char define-primitive-type
 
     <c-type>
         fixnum >>class
@@ -463,20 +430,20 @@ CONSTANT: primitive-types
         1 >>align
         "box_unsigned_1" >>boxer
         "to_cell" >>unboxer
-    "uchar" define-primitive-type
+    \ uchar define-primitive-type
 
     <c-type>
-        [ alien-unsigned-1 c-bool> ] >>getter
-        [ [ >c-bool ] 2dip set-alien-unsigned-1 ] >>setter
+        [ alien-unsigned-1 0 = not ] >>getter
+        [ [ 1 0 ? ] 2dip set-alien-unsigned-1 ] >>setter
         1 >>size
         1 >>align
         "box_boolean" >>boxer
         "to_boolean" >>unboxer
-    "bool" define-primitive-type
+    \ bool define-primitive-type
 
     <c-type>
-        float >>class
-        float >>boxed-class
+        math:float >>class
+        math:float >>boxed-class
         [ alien-float ] >>getter
         [ [ >float ] 2dip set-alien-float ] >>setter
         4 >>size
@@ -485,11 +452,11 @@ CONSTANT: primitive-types
         "to_float" >>unboxer
         float-rep >>rep
         [ >float ] >>unboxer-quot
-    "float" define-primitive-type
+    \ float define-primitive-type
 
     <c-type>
-        float >>class
-        float >>boxed-class
+        math:float >>class
+        math:float >>boxed-class
         [ alien-double ] >>getter
         [ [ >float ] 2dip set-alien-double ] >>setter
         8 >>size
@@ -498,10 +465,10 @@ CONSTANT: primitive-types
         "to_double" >>unboxer
         double-rep >>rep
         [ >float ] >>unboxer-quot
-    "double" define-primitive-type
+    \ double define-primitive-type
 
-    "long" "ptrdiff_t" typedef
-    "long" "intptr_t" typedef
-    "ulong" "size_t" typedef
+    \ long \ ptrdiff_t typedef
+    \ long \ intptr_t typedef
+    \ ulong \ size_t typedef
 ] with-compilation-unit
 
diff --git a/basis/alien/data/authors.txt b/basis/alien/data/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/basis/alien/data/data-docs.factor b/basis/alien/data/data-docs.factor
new file mode 100644 (file)
index 0000000..19bfaaa
--- /dev/null
@@ -0,0 +1,148 @@
+USING: alien alien.c-types help.syntax help.markup libc kernel.private
+byte-arrays math strings hashtables alien.syntax alien.strings sequences
+io.encodings.string debugger destructors vocabs.loader ;
+IN: alien.data
+
+HELP: <c-array>
+{ $values { "len" "a non-negative integer" } { "c-type" "a C type" } { "array" byte-array } }
+{ $description "Creates a byte array large enough to hold " { $snippet "n" } " values of a C type." }
+{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." }
+{ $errors "Throws an error if the type does not exist, the necessary specialized array vocabulary is not loaded, or the requested size is negative." } ;
+
+HELP: <c-object>
+{ $values { "type" "a C type" } { "array" byte-array } }
+{ $description "Creates a byte array suitable for holding a value with the given C type." }
+{ $errors "Throws an " { $link no-c-type } " error if the type does not exist." } ;
+
+{ <c-object> malloc-object } related-words
+
+HELP: memory>byte-array
+{ $values { "alien" c-ptr } { "len" "a non-negative integer" } { "byte-array" byte-array } }
+{ $description "Reads " { $snippet "len" } " bytes starting from " { $snippet "base" } " and stores them in a new byte array." } ;
+
+HELP: byte-array>memory
+{ $values { "byte-array" byte-array } { "base" c-ptr } }
+{ $description "Writes a byte array to memory starting from the " { $snippet "base" } " address." }
+{ $warning "This word is unsafe. Improper use can corrupt memory." } ;
+
+HELP: malloc-array
+{ $values { "n" "a non-negative integer" } { "type" "a C type" } { "alien" alien } }
+{ $description "Allocates an unmanaged memory block large enough to hold " { $snippet "n" } " values of a C type, then wraps the memory in a sequence object using " { $link <c-direct-array> } "." }
+{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." }
+{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
+{ $errors "Throws an error if the type does not exist, if the requested size is negative, if a direct specialized array class appropriate to the type is not loaded, or if memory allocation fails." } ;
+
+HELP: malloc-object
+{ $values { "type" "a C type" } { "alien" alien } }
+{ $description "Allocates an unmanaged memory block large enough to hold a value of a C type." }
+{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
+{ $errors "Throws an error if the type does not exist or if memory allocation fails." } ;
+
+HELP: malloc-byte-array
+{ $values { "byte-array" byte-array } { "alien" alien } }
+{ $description "Allocates an unmanaged memory block of the same size as the byte array, and copies the contents of the byte array there." }
+{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
+{ $errors "Throws an error if memory allocation fails." } ;
+
+{ <c-array> <c-direct-array> malloc-array } related-words
+
+{ string>alien alien>string malloc-string } related-words
+
+ARTICLE: "malloc" "Manual memory management"
+"Sometimes data passed to C functions must be allocated at a fixed address. See " { $link "byte-arrays-gc" } " for an explanation of when this is the case."
+$nl
+"Allocating a C datum with a fixed address:"
+{ $subsection malloc-object }
+{ $subsection malloc-array }
+{ $subsection malloc-byte-array }
+"There is a set of words in the " { $vocab-link "libc" } " vocabulary which directly call C standard library memory management functions:"
+{ $subsection malloc }
+{ $subsection calloc }
+{ $subsection realloc }
+"You must always free pointers returned by any of the above words when the block of memory is no longer in use:"
+{ $subsection free }
+"Utilities for automatically freeing memory in conjunction with " { $link with-destructors } ":"
+{ $subsection &free }
+{ $subsection |free }
+"The " { $link &free } " and " { $link |free } " words are generated using " { $link "alien.destructors" } "."
+$nl
+"You can unsafely copy a range of bytes from one memory location to another:"
+{ $subsection memcpy }
+"You can copy a range of bytes from memory into a byte array:"
+{ $subsection memory>byte-array }
+"You can copy a byte array to memory unsafely:"
+{ $subsection byte-array>memory } ;
+
+
+ARTICLE: "c-byte-arrays" "Passing data in byte arrays"
+"Instances of the " { $link byte-array } " class can be passed to C functions; the C function receives a pointer to the first element of the array."
+$nl
+"Byte arrays can be allocated directly with a byte count using the " { $link <byte-array> } " word. However in most cases, instead of computing a size in bytes directly, it is easier to use a higher-level word which expects C type and outputs a byte array large enough to hold that type:"
+{ $subsection <c-object> }
+{ $subsection <c-array> }
+{ $warning
+"The Factor garbage collector can move byte arrays around, and code passing byte arrays to C must obey important guidelines. See " { $link "byte-arrays-gc" } "." }
+{ $see-also "c-arrays" } ;
+
+ARTICLE: "c-data" "Passing data between Factor and C"
+"Two defining characteristics of Factor are dynamic typing and automatic memory management, which are somewhat incompatible with the machine-level data model exposed by C. Factor's C library interface defines its own set of C data types, distinct from Factor language types, together with automatic conversion between Factor values and C types. For example, C integer types must be declared and are fixed-width, whereas Factor supports arbitrary-precision integers."
+$nl
+"Furthermore, Factor's garbage collector can move objects in memory; for a discussion of the consequences, see " { $link "byte-arrays-gc" } "."
+{ $subsection "c-types-specs" }
+{ $subsection "c-byte-arrays" }
+{ $subsection "malloc" }
+{ $subsection "c-strings" }
+{ $subsection "c-arrays" }
+{ $subsection "c-out-params" }
+"Important guidelines for passing data in byte arrays:"
+{ $subsection "byte-arrays-gc" }
+"C-style enumerated types are supported:"
+{ $subsection POSTPONE: C-ENUM: }
+"C types can be aliased for convenience and consitency with native library documentation:"
+{ $subsection POSTPONE: TYPEDEF: }
+"New C types can be defined:"
+{ $subsection "c-structs" }
+{ $subsection "c-unions" }
+"A utility for defining " { $link "destructors" } " for deallocating memory:"
+{ $subsection "alien.destructors" }
+{ $see-also "aliens" } ;
+HELP: malloc-string
+{ $values { "string" string } { "encoding" "an encoding descriptor" } { "alien" c-ptr } }
+{ $description "Encodes a string together with a trailing null code point using the given encoding, and stores the resulting bytes in a freshly-allocated unmanaged memory block." }
+{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
+{ $errors "Throws an error if one of the following conditions occurs:"
+    { $list
+        "the string contains null code points"
+        "the string contains characters not representable using the encoding specified"
+        "memory allocation fails"
+    }
+} ;
+
+HELP: require-c-array
+{ $values { "c-type" "a C type" } }
+{ $description "Generates a specialized array of " { $snippet "c-type" } " using the " { $link <c-array> } " or " { $link <c-direct-array> } " vocabularies." }
+{ $notes "This word must be called inside a compilation unit. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence types loaded." } ;
+
+HELP: <c-direct-array>
+{ $values { "alien" c-ptr } { "len" integer } { "c-type" "a C type" } { "array" "a specialized direct array" } }
+{ $description "Constructs a new specialized array of length " { $snippet "len" } " and element type " { $snippet "c-type" } " over the range of memory referenced by " { $snippet "alien" } "." }
+{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } ;
+
+ARTICLE: "c-strings" "C strings"
+"C string types are arrays with shape " { $snippet "{ \"char*\" encoding }" } ", where " { $snippet "encoding" } " is an encoding descriptor. The type " { $snippet "\"char*\"" } " is an alias for " { $snippet "{ \"char*\" utf8 }" } ". See " { $link "encodings-descriptors" } " for information about encoding descriptors."
+$nl
+"Passing a Factor string to a C function expecting a C string allocates a " { $link byte-array } " in the Factor heap; the string is then converted to the requested format and a raw pointer is passed to the function."
+$nl
+"If the conversion fails, for example if the string contains null bytes or characters with values higher than 255, a " { $link c-string-error. } " is thrown."
+$nl
+"Care must be taken if the C function expects a " { $snippet "char*" } " with a length in bytes, rather than a null-terminated " { $snippet "char*" } "; passing the result of calling " { $link length } " on the string object will not suffice. This is because a Factor string of " { $emphasis "n" } " characters will not necessarily encode to " { $emphasis "n" } " bytes. The correct idiom for C functions which take a string with a length is to first encode the string using " { $link encode } ", and then pass the resulting byte array together with the length of this byte array."
+$nl
+"Sometimes a C function has a parameter type of " { $snippet "void*" } ", and various data types, among them strings, can be passed in. In this case, strings are not automatically converted to aliens, and instead you must call one of these words:"
+{ $subsection string>alien }
+{ $subsection malloc-string }
+"The first allocates " { $link byte-array } "s, and the latter allocates manually-managed memory which is not moved by the garbage collector and has to be explicitly freed by calling " { $link free } ". See " { $link "byte-arrays-gc" } " for a discussion of the two approaches."
+$nl
+"A word to read strings from arbitrary addresses:"
+{ $subsection alien>string }
+"For example, if a C function returns a " { $snippet "char*" } " but stipulates that the caller must deallocate the memory afterward, you must define the function as returning " { $snippet "void*" } ", and call one of the above words before passing the pointer to " { $link free } "." ;
+
diff --git a/basis/alien/data/data.factor b/basis/alien/data/data.factor
new file mode 100644 (file)
index 0000000..1f2c516
--- /dev/null
@@ -0,0 +1,83 @@
+! (c)2009 Slava Pestov, Joe Groff bsd license
+USING: accessors alien alien.c-types alien.strings arrays
+byte-arrays cpu.architecture fry io io.encodings.binary
+io.files io.streams.memory kernel libc math sequences ;
+IN: alien.data
+
+GENERIC: require-c-array ( c-type -- )
+
+M: array require-c-array first require-c-array ;
+
+GENERIC: c-array-constructor ( c-type -- word )
+
+GENERIC: c-(array)-constructor ( c-type -- word )
+
+GENERIC: c-direct-array-constructor ( c-type -- word )
+
+GENERIC: <c-array> ( len c-type -- array )
+
+M: c-type-name <c-array>
+    c-array-constructor execute( len -- array ) ; inline
+
+GENERIC: (c-array) ( len c-type -- array )
+
+M: c-type-name (c-array)
+    c-(array)-constructor execute( len -- array ) ; inline
+
+GENERIC: <c-direct-array> ( alien len c-type -- array )
+
+M: c-type-name <c-direct-array>
+    c-direct-array-constructor execute( alien len -- array ) ; inline
+
+: malloc-array ( n type -- alien )
+    [ heap-size calloc ] [ <c-direct-array> ] 2bi ; inline
+
+: (malloc-array) ( n type -- alien )
+    [ heap-size * malloc ] [ <c-direct-array> ] 2bi ; inline
+
+: <c-object> ( type -- array )
+    heap-size <byte-array> ; inline
+
+: (c-object) ( type -- array )
+    heap-size (byte-array) ; inline
+
+: malloc-object ( type -- alien )
+    1 swap heap-size calloc ; inline
+
+: (malloc-object) ( type -- alien )
+    heap-size malloc ; inline
+
+: malloc-byte-array ( byte-array -- alien )
+    dup byte-length [ nip malloc dup ] 2keep memcpy ;
+
+: memory>byte-array ( alien len -- byte-array )
+    [ nip (byte-array) dup ] 2keep memcpy ;
+
+: malloc-string ( string encoding -- alien )
+    string>alien malloc-byte-array ;
+
+: malloc-file-contents ( path -- alien len )
+    binary file-contents [ malloc-byte-array ] [ length ] bi ;
+
+M: memory-stream stream-read
+    [
+        [ index>> ] [ alien>> ] bi <displaced-alien>
+        swap memory>byte-array
+    ] [ [ + ] change-index drop ] 2bi ;
+
+: byte-array>memory ( byte-array base -- )
+    swap dup byte-length memcpy ; inline
+
+: >c-bool ( ? -- int ) 1 0 ? ; inline
+
+: c-bool> ( int -- ? ) 0 = not ; inline
+
+M: value-type c-type-rep drop int-rep ;
+
+M: value-type c-type-getter
+    drop [ swap <displaced-alien> ] ;
+
+M: value-type c-type-setter ( type -- quot )
+    [ c-type-getter ] [ c-type-unboxer-quot ] [ heap-size ] tri
+    '[ @ swap @ _ memcpy ] ;
+
diff --git a/basis/alien/data/summary.txt b/basis/alien/data/summary.txt
new file mode 100644 (file)
index 0000000..addddb2
--- /dev/null
@@ -0,0 +1 @@
+Words for allocating objects and arrays of C types
index 9d893b95c4648311c11830d12fb3fcf29ae9b8b0..238207f192a7a8f9648c7030314b6efb88e9954a 100644 (file)
@@ -1,7 +1,7 @@
 ! (c) 2009 Joe Groff, see BSD license
 USING: accessors alien alien.c-types alien.complex
-alien.fortran alien.fortran.private alien.strings classes.struct
-arrays assocs byte-arrays combinators fry
+alien.data alien.fortran alien.fortran.private alien.strings
+classes.struct arrays assocs byte-arrays combinators fry
 generalizations io.encodings.ascii kernel macros
 macros.expander namespaces sequences shuffle tools.test ;
 IN: alien.fortran.tests
index 52d69fd193871d323b289ba266bb28edc7d6d272..bf8721b549497b43eee9b977724f1979ce9aba43 100644 (file)
@@ -1,5 +1,5 @@
 ! (c) 2009 Joe Groff, see BSD license
-USING: accessors alien alien.c-types alien.complex alien.parser
+USING: accessors alien alien.c-types alien.complex alien.data grouping
 alien.strings alien.syntax arrays ascii assocs
 byte-arrays combinators combinators.short-circuit fry generalizations
 kernel lexer macros math math.parser namespaces parser sequences
@@ -429,6 +429,11 @@ PRIVATE>
 MACRO: fortran-invoke ( return library function parameters -- )
     { [ 2drop nip set-fortran-abi ] [ (fortran-invoke) ] } 4 ncleave ;
 
+: parse-arglist ( parameters return -- types effect )
+    [ 2 group unzip [ "," ?tail drop ] map ]
+    [ [ { } ] [ 1array ] if-void ]
+    bi* <effect> ;
+
 :: define-fortran-function ( return library function parameters -- )
     function create-in dup reset-generic 
     return library function parameters return [ "void" ] unless* parse-arglist
index 19ab08c03ca801930f0be6b6f968e855f599dfc7..9a24f7cd4d0ac9359cc49c192196e8f13c6b9e93 100644 (file)
@@ -1,16 +1,42 @@
 ! Copyright (C) 2008, 2009 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types arrays assocs effects grouping kernel
-parser sequences splitting words fry locals lexer namespaces
-summary math ;
+USING: accessors alien alien.c-types arrays assocs
+combinators combinators.short-circuit effects grouping
+kernel parser sequences splitting words fry locals lexer
+namespaces summary math vocabs.parser ;
 IN: alien.parser
 
+: parse-c-type-name ( name -- word/string )
+    [ search ] keep or ;
+
+: parse-c-type ( string -- array )
+    {
+        { [ dup "void" =            ] [ drop void ] }
+        { [ CHAR: ] over member?    ] [ parse-array-type parse-c-type-name prefix ] }
+        { [ dup search c-type-word? ] [ parse-c-type-name ] }
+        { [ dup c-types get at      ] [ ] }
+        { [ "*" ?tail               ] [ parse-c-type-name resolve-pointer-type ] }
+        [ no-c-type ]
+    } cond ;
+
+: scan-c-type ( -- c-type )
+    scan dup "{" =
+    [ drop \ } parse-until >array ]
+    [ parse-c-type ] if ; 
+
+: reset-c-type ( word -- )
+    { "c-type" "pointer-c-type" } reset-props ;
+
+: CREATE-C-TYPE ( -- word )
+    scan current-vocab create dup reset-c-type ;
+
 : normalize-c-arg ( type name -- type' name' )
     [ length ]
     [
         [ CHAR: * = ] trim-head
         [ length - CHAR: * <array> append ] keep
-    ] bi ;
+    ] bi
+    [ parse-c-type ] dip ;
 
 : parse-arglist ( parameters return -- types effect )
     [
@@ -36,3 +62,9 @@ IN: alien.parser
 
 : define-function ( return library function parameters -- )
     make-function define-declared ;
+
+PREDICATE: alien-function-word < word
+    def>> {
+        [ length 5 = ]
+        [ last \ alien-invoke eq? ]
+    } 1&& ;
index 0ffd5023a74b403e422c844ff12a3fceefd5cbf7..4586c0854292f278a931bad17bbca53917e02346 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel combinators alien alien.strings alien.syntax
-math.parser prettyprint.backend prettyprint.custom
-prettyprint.sections ;
+USING: accessors kernel combinators alien alien.strings alien.c-types
+alien.parser alien.syntax arrays assocs effects math.parser
+prettyprint.backend prettyprint.custom prettyprint.sections
+definitions see see.private sequences strings words ;
 IN: alien.prettyprint
 
 M: alien pprint*
@@ -13,3 +14,39 @@ M: alien pprint*
     } cond ;
 
 M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
+
+M: c-type-word definer drop \ C-TYPE: f ;
+M: c-type-word definition drop f ;
+M: typedef-word declarations. drop ;
+
+GENERIC: pprint-c-type ( c-type -- )
+M: word pprint-c-type pprint-word ;
+M: wrapper pprint-c-type wrapped>> pprint-word ;
+M: string pprint-c-type text ;
+M: array pprint-c-type pprint* ;
+
+M: typedef-word definer drop \ TYPEDEF: f ;
+
+M: typedef-word synopsis*
+    \ TYPEDEF: pprint-word
+    dup "c-type" word-prop pprint-c-type
+    pprint-word ;
+
+: pprint-function-arg ( type name -- )
+    [ pprint-c-type ] [ text ] bi* ;
+
+: pprint-function-args ( word -- )
+    [ def>> fourth ] [ stack-effect in>> ] bi zip [ ] [
+        unclip-last
+        [ [ first2 "," append pprint-function-arg ] each ] dip
+        first2 pprint-function-arg
+    ] if-empty ;
+
+M: alien-function-word definer
+    drop \ FUNCTION: \ ; ;
+M: alien-function-word definition drop f ;
+M: alien-function-word synopsis*
+    \ FUNCTION: pprint-word
+    [ def>> first pprint-c-type ]
+    [ pprint-word ]
+    [ <block "(" text pprint-function-args ")" text block> ] tri ;
index b72c79e47818a8be27331e26d887e14996ee047e..4ccd0e7488792a743cde60eb07ff8a068833d7b0 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.strings parser
+USING: accessors alien alien.data alien.strings parser
 threads words kernel.private kernel io.encodings.utf8 eval ;
 IN: alien.remote-control
 
index 62a3817feca954f8bdb484333398f1e7edaf6813..d0485ae4bac3f1d07cce7408481c4f4ee8d12539 100644 (file)
@@ -1,4 +1,4 @@
-USING: alien.c-types strings help.markup help.syntax alien.syntax
+USING: alien.c-types alien.data strings help.markup help.syntax alien.syntax
 sequences io arrays kernel words assocs namespaces ;
 IN: alien.structs
 
index 3f84377d5c8164a22e2ac4518b826d8620832132..d22aa5ee452e1312c8f5d4cc913e890d42842c8e 100755 (executable)
@@ -1,4 +1,4 @@
-USING: alien alien.syntax alien.c-types kernel tools.test
+USING: alien alien.syntax alien.c-types alien.data kernel tools.test
 sequences system libc words vocabs namespaces layouts ;
 IN: alien.structs.tests
 
index 80837e9a0135cc9012fac6469d4dfda2c60f5c23..9478f98c6360d64f5e3078cfd935c8a6b4ff7c6b 100755 (executable)
@@ -15,7 +15,7 @@ M: struct-type c-type ;
 M: struct-type c-type-stack-align? drop f ;
 
 : if-value-struct ( ctype true false -- )
-    [ dup value-struct? ] 2dip '[ drop "void*" @ ] if ; inline
+    [ dup value-struct? ] 2dip '[ drop void* @ ] if ; inline
 
 M: struct-type unbox-parameter
     [ %unbox-large-struct ] [ unbox-parameter ] if-value-struct ;
index e8206c6968fd993d11b30c3cc2ca737aa017c4f9..0e3b569fffa753b497269ad79d5d502528746b4a 100644 (file)
@@ -19,7 +19,7 @@ SYNTAX: FUNCTION:
     (FUNCTION:) define-declared ;
 
 SYNTAX: TYPEDEF:
-    scan scan typedef ;
+    scan-c-type CREATE-C-TYPE typedef ;
 
 SYNTAX: C-STRUCT:
     scan current-vocab parse-definition define-struct ; deprecated
@@ -31,6 +31,9 @@ SYNTAX: C-ENUM:
     ";" parse-tokens
     [ [ create-in ] dip define-constant ] each-index ;
 
+SYNTAX: C-TYPE:
+    "Primitive C type definition not supported" throw ;
+
 ERROR: no-such-symbol name library ;
 
 : address-of ( name library -- value )
index 0f87cf4cb6dddea6dd1fb4a690e45991eb9a2ee6..f5613da6b552126b3edf31b7e494179c0246a9c0 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types accessors math alien.accessors kernel
+USING: alien.c-types alien.data accessors math alien.accessors kernel
 kernel.private sequences sequences.private byte-arrays
 parser prettyprint.custom fry ;
 IN: bit-arrays
index ce5f0cc233f0021eaed8490af3ae3655c952382f..947869e357149a7f9aa1b31a49aab918dc9f0257 100644 (file)
@@ -6,7 +6,7 @@
 
 USING: system combinators alien alien.syntax alien.c-types
 alien.destructors kernel accessors sequences arrays ui.gadgets
-alien.libraries ;
+alien.libraries classes.struct ;
 
 IN: cairo.ffi
 << {
@@ -26,23 +26,23 @@ TYPEDEF: int cairo_bool_t
 TYPEDEF: void* cairo_t
 TYPEDEF: void* cairo_surface_t
 
-C-STRUCT: cairo_matrix_t
-    { "double" "xx" }
-    { "double" "yx" }
-    { "double" "xy" }
-    { "double" "yy" }
-    { "double" "x0" }
-    { "double" "y0" } ;
+STRUCT: cairo_matrix_t
+    { xx double }
+    { yx double }
+    { xy double }
+    { yy double }
+    { x0 double }
+    { y0 double } ;
 
 TYPEDEF: void* cairo_pattern_t
 
 TYPEDEF: void* cairo_destroy_func_t
 : cairo-destroy-func ( quot -- callback )
-    [ "void" { "void*" } "cdecl" ] dip alien-callback ; inline
+    [ void { void* } "cdecl" ] dip alien-callback ; inline
 
 ! See cairo.h for details
-C-STRUCT: cairo_user_data_key_t
-    { "int" "unused" } ;
+STRUCT: cairo_user_data_key_t
+    { unused int } ;
 
 TYPEDEF: int cairo_status_t
 C-ENUM:
@@ -79,11 +79,11 @@ CONSTANT: CAIRO_CONTENT_COLOR_ALPHA HEX: 3000
 
 TYPEDEF: void* cairo_write_func_t
 : cairo-write-func ( quot -- callback )
-    [ "cairo_status_t" { "void*" "uchar*" "int" } "cdecl" ] dip alien-callback ; inline
+    [ cairo_status_t { void* uchar* int } "cdecl" ] dip alien-callback ; inline
                           
 TYPEDEF: void* cairo_read_func_t
 : cairo-read-func ( quot -- callback )
-    [ "cairo_status_t" { "void*" "uchar*" "int" } "cdecl" ] dip alien-callback ; inline
+    [ cairo_status_t { void* uchar* int } "cdecl" ] dip alien-callback ; inline
 
 ! Functions for manipulating state objects
 FUNCTION: cairo_t*
@@ -336,16 +336,16 @@ cairo_clip_preserve ( cairo_t* cr ) ;
 FUNCTION: void
 cairo_clip_extents ( cairo_t* cr, double* x1, double* y1, double* x2, double* y2 ) ;
 
-C-STRUCT: cairo_rectangle_t
-    { "double" "x" }
-    { "double" "y" }
-    { "double" "width" }
-    { "double" "height" } ;
+STRUCT: cairo_rectangle_t
+    { x      double }
+    { y      double }
+    { width  double }
+    { height double } ;
     
-C-STRUCT: cairo_rectangle_list_t
-    { "cairo_status_t"     "status" }
-    { "cairo_rectangle_t*" "rectangles" }
-    { "int"                "num_rectangles" } ;
+STRUCT: cairo_rectangle_list_t
+    { status         cairo_status_t     }
+    { rectangles     cairo_rectangle_t* }
+    { num_rectangles int                } ;
 
 FUNCTION: cairo_rectangle_list_t*
 cairo_copy_clip_rectangle_list ( cairo_t* cr ) ;
@@ -359,25 +359,25 @@ TYPEDEF: void* cairo_scaled_font_t
 
 TYPEDEF: void* cairo_font_face_t
 
-C-STRUCT: cairo_glyph_t
-  { "ulong"     "index" }
-  { "double"    "x" }
-  { "double"    "y" } ;
-
-C-STRUCT: cairo_text_extents_t
-    { "double" "x_bearing" }
-    { "double" "y_bearing" }
-    { "double" "width" }
-    { "double" "height" }
-    { "double" "x_advance" }
-    { "double" "y_advance" } ;
-
-C-STRUCT: cairo_font_extents_t
-    { "double" "ascent" }
-    { "double" "descent" }
-    { "double" "height" }
-    { "double" "max_x_advance" }
-    { "double" "max_y_advance" } ;
+STRUCT: cairo_glyph_t
+  { index ulong     }
+  { x     double    }
+  { y     double    } ;
+
+STRUCT: cairo_text_extents_t
+    { x_bearing double }
+    { y_bearing double }
+    { width     double }
+    { height    double }
+    { x_advance double }
+    { y_advance double } ;
+
+STRUCT: cairo_font_extents_t
+    { ascent double }
+    { descent double }
+    { height double }
+    { max_x_advance double }
+    { max_y_advance double } ;
 
 TYPEDEF: int cairo_font_slant_t
 C-ENUM:
@@ -648,20 +648,22 @@ C-ENUM:
     CAIRO_PATH_CLOSE_PATH ;
 
 ! NEED TO DO UNION HERE
-C-STRUCT: cairo_path_data_t-point
-    { "double" "x" }
-    { "double" "y" } ;
-
-C-STRUCT: cairo_path_data_t-header
-    { "cairo_path_data_type_t" "type" }
-    { "int" "length" } ;
-
-C-UNION: cairo_path_data_t "cairo_path_data_t-point" "cairo_path_data_t-header" ;
-
-C-STRUCT: cairo_path_t
-    { "cairo_status_t"      "status" }
-    { "cairo_path_data_t*"  "data" }
-    { "int"                 "num_data" } ;
+STRUCT: cairo_path_data_t-point
+    { x double }
+    { y double } ;
+
+STRUCT: cairo_path_data_t-header
+    { type cairo_path_data_type_t }
+    { length int } ;
+
+UNION-STRUCT: cairo_path_data_t 
+    { point  cairo_path_data_t-point }
+    { header cairo_path_data_t-header } ;
+
+STRUCT: cairo_path_t
+    { status   cairo_status_t      }
+    { data     cairo_path_data_t*  }
+    { num_data int                 } ;
 
 FUNCTION: cairo_path_t*
 cairo_copy_path ( cairo_t* cr ) ;
index 6f21d96e86192e4310516a1cf1fcd746d3ddaa06..bc70230fd0004c12e0a65909d84fef495b6e5c81 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays alien.c-types kernel continuations
-destructors sequences io openssl openssl.libcrypto checksums
-checksums.stream ;
+USING: accessors byte-arrays alien.c-types alien.data kernel
+continuations destructors sequences io openssl openssl.libcrypto
+checksums checksums.stream classes.struct ;
 IN: checksums.openssl
 
 ERROR: unknown-digest name ;
@@ -23,7 +23,7 @@ TUPLE: evp-md-context < disposable handle ;
 
 : <evp-md-context> ( -- ctx )
     evp-md-context new-disposable
-    "EVP_MD_CTX" <c-object> dup EVP_MD_CTX_init >>handle ;
+    EVP_MD_CTX <struct> dup EVP_MD_CTX_init >>handle ;
 
 M: evp-md-context dispose*
     handle>> EVP_MD_CTX_cleanup drop ;
index 2c969531e80285b58b60c453723f737e4a7feae0..43d24e57164b83cd9c7d8ccbc8d4a005e456e412 100644 (file)
@@ -1,9 +1,9 @@
 ! (c)Joe Groff bsd license
-USING: accessors alien alien.c-types arrays assocs classes
-classes.struct combinators combinators.short-circuit continuations
-fry kernel libc make math math.parser mirrors prettyprint.backend
-prettyprint.custom prettyprint.sections see.private sequences
-slots strings summary words ;
+USING: accessors alien alien.c-types alien.data alien.prettyprint arrays
+assocs classes classes.struct combinators combinators.short-circuit
+continuations fry kernel libc make math math.parser mirrors
+prettyprint.backend prettyprint.custom prettyprint.sections
+see.private sequences slots strings summary words ;
 IN: classes.struct.prettyprint
 
 <PRIVATE
@@ -20,7 +20,7 @@ IN: classes.struct.prettyprint
     <flow \ { pprint-word
     f <inset {
         [ name>> text ]
-        [ type>> dup string? [ text ] [ pprint* ] if ]
+        [ type>> pprint-c-type ]
         [ read-only>> [ \ read-only pprint-word ] when ]
         [ initial>> [ \ initial: pprint-word pprint* ] when* ]
     } cleave block>
index bbbaf4f1d57983bab04add14f770a468fb55fc19..b60bfa375bef10fc4ea9735f71d8e52b6890860d 100755 (executable)
@@ -1,11 +1,13 @@
 ! (c)Joe Groff bsd license
-USING: accessors alien alien.c-types ascii
+USING: accessors alien alien.c-types alien.data ascii
 assocs byte-arrays classes.struct classes.tuple.private
 combinators compiler.tree.debugger compiler.units destructors
 io.encodings.utf8 io.pathnames io.streams.string kernel libc
 literals math mirrors multiline namespaces prettyprint
 prettyprint.config see sequences specialized-arrays system
 tools.test parser lexer eval layouts ;
+FROM: math => float ;
+QUALIFIED-WITH: alien.c-types c
 SPECIALIZED-ARRAY: char
 SPECIALIZED-ARRAY: int
 SPECIALIZED-ARRAY: ushort
@@ -46,9 +48,9 @@ STRUCT: struct-test-bar
 
 [ {
     { "underlying" B{ 98 0 0 98 127 0 0 127 0 0 0 0 } }
-    { { "x" "char" } 98            }
-    { { "y" "int"  } HEX: 7F00007F }
-    { { "z" "bool" } f             }
+    { { "x" char } 98            }
+    { { "y" int  } HEX: 7F00007F }
+    { { "z" bool } f             }
 } ] [
     B{ 98 0 0 98 127 0 0 127 0 0 0 0 } struct-test-foo memory>struct
     make-mirror >alist
@@ -128,7 +130,7 @@ STRUCT: struct-test-bar
 ] unit-test
 
 UNION-STRUCT: struct-test-float-and-bits
-    { f float }
+    { f c:float }
     { bits uint } ;
 
 [ 1.0 ] [ struct-test-float-and-bits <struct> 1.0 float>bits >>bits f>> ] unit-test
@@ -181,14 +183,14 @@ STRUCT: struct-test-string-ptr
     ] with-scope
 ] unit-test
 
-[ <" USING: classes.struct ;
+[ <" USING: alien.c-types classes.struct ;
 IN: classes.struct.tests
 STRUCT: struct-test-foo
     { x char initial: 0 } { y int initial: 123 } { z bool } ;
 "> ]
 [ [ struct-test-foo see ] with-string-writer ] unit-test
 
-[ <" USING: classes.struct ;
+[ <" USING: alien.c-types classes.struct ;
 IN: classes.struct.tests
 UNION-STRUCT: struct-test-float-and-bits
     { f float initial: 0.0 } { bits uint initial: 0 } ;
@@ -201,20 +203,20 @@ UNION-STRUCT: struct-test-float-and-bits
         { offset 0 }
         { initial 0 }
         { class fixnum }
-        { type "char" }
+        { type char }
     }
     T{ struct-slot-spec
         { name "y" }
         { offset 4 }
         { initial 123 }
         { class integer }
-        { type "int" }
+        { type int }
     }
     T{ struct-slot-spec
         { name "z" }
         { offset 8 }
         { initial f }
-        { type "bool" }
+        { type bool }
         { class object }
     }
 } ] [ "struct-test-foo" c-type fields>> ] unit-test
@@ -223,14 +225,14 @@ UNION-STRUCT: struct-test-float-and-bits
     T{ struct-slot-spec
         { name "f" }
         { offset 0 }
-        { type "float" }
+        { type c:float }
         { class float }
         { initial 0.0 }
     }
     T{ struct-slot-spec
         { name "bits" }
         { offset 0 }
-        { type "uint" }
+        { type uint }
         { class integer }
         { initial 0 }
     }
@@ -277,7 +279,7 @@ STRUCT: struct-test-array-slots
 ] unit-test
 
 STRUCT: struct-test-optimization
-    { x { "int" 3 } } { y int } ;
+    { x { int 3 } } { y int } ;
 
 SPECIALIZED-ARRAY: struct-test-optimization
 
index 1de221d2aa61d20ce2dabe4d46eced4602cfb1f5..7e993286525d94a7275c207404c1ea17ea6ff6c4 100755 (executable)
@@ -1,12 +1,12 @@
 ! (c)Joe Groff bsd license
-USING: accessors alien alien.c-types arrays byte-arrays classes
-classes.parser classes.tuple classes.tuple.parser
+USING: accessors alien alien.c-types alien.data alien.parser arrays
+byte-arrays classes classes.parser classes.tuple classes.tuple.parser
 classes.tuple.private combinators combinators.short-circuit
 combinators.smart cpu.architecture definitions functors.backend
 fry generalizations generic.parser kernel kernel.private lexer
 libc locals macros make math math.order parser quotations
 sequences slots slots.private specialized-arrays vectors words
-summary namespaces assocs ;
+summary namespaces assocs vocabs.parser ;
 IN: classes.struct
 
 SPECIALIZED-ARRAY: uchar
@@ -126,7 +126,7 @@ M: struct-c-type c-type ;
 M: struct-c-type c-type-stack-align? drop f ;
 
 : if-value-struct ( ctype true false -- )
-    [ dup value-struct? ] 2dip '[ drop "void*" @ ] if ; inline
+    [ dup value-struct? ] 2dip '[ drop void* @ ] if ; inline
 
 M: struct-c-type unbox-parameter
     [ %unbox-large-struct ] [ unbox-parameter ] if-value-struct ;
@@ -197,20 +197,6 @@ M: struct-c-type c-struct? drop t ;
     [ type>> c-type-align ] [ max ] map-reduce ;
 PRIVATE>
 
-M: struct-class c-type name>> c-type ;
-
-M: struct-class c-type-align c-type c-type-align ;
-
-M: struct-class c-type-getter c-type c-type-getter ;
-
-M: struct-class c-type-setter c-type c-type-setter ;
-
-M: struct-class c-type-boxer-quot c-type c-type-boxer-quot ;
-
-M: struct-class c-type-unboxer-quot c-type c-type-boxer-quot ;
-
-M: struct-class heap-size c-type heap-size ;
-
 M: struct byte-length class "struct-size" word-prop ; foldable
 
 ! class definition
@@ -259,7 +245,7 @@ M: struct byte-length class "struct-size" word-prop ; foldable
         [ check-struct-slots ] _ [ struct-align [ align ] keep ] tri
         (struct-word-props)
     ]
-    [ drop [ c-type-for-class ] [ name>> ] bi typedef ] 2tri ; inline
+    [ drop [ c-type-for-class ] keep typedef ] 2tri ; inline
 PRIVATE>
 
 : define-struct-class ( class slots -- )
@@ -284,9 +270,6 @@ ERROR: invalid-struct-slot token ;
     [ [ dup empty? ] [ peel-off-attributes ] until drop ] tri* ;
 
 <PRIVATE
-: scan-c-type ( -- c-type )
-    scan dup "{" = [ drop \ } parse-until >array ] when ;
-
 : parse-struct-slot ( -- slot )
     scan scan-c-type \ } parse-until <struct-slot-spec> ;
     
@@ -317,7 +300,7 @@ SYNTAX: S@
 
 <PRIVATE
 : scan-c-type` ( -- c-type/param )
-    scan dup "{" = [ drop \ } parse-until >array ] [ >string-param ] if ;
+    scan dup "{" = [ drop \ } parse-until >array ] [ search ] if ;
 
 : parse-struct-slot` ( accum -- accum )
     scan-string-param scan-c-type` \ } parse-until
index caa83331ab8de7f3c0ebe3141ed7d0328c8b37e5..c7bdf625d9e0c5debf04d8c83660fc771037a65a 100755 (executable)
@@ -1,17 +1,16 @@
 ! Copyright (C) 2008 Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel classes.struct cocoa cocoa.types alien.c-types
-locals math sequences vectors fry libc destructors ;
+USING: accessors kernel classes.struct cocoa cocoa.runtime cocoa.types alien.data
+locals math sequences vectors fry libc destructors specialized-arrays ;
+SPECIALIZED-ARRAY: id
 IN: cocoa.enumeration
 
-<< "id" require-c-array >>
-
 CONSTANT: NS-EACH-BUFFER-SIZE 16
 
 : with-enumeration-buffers ( quot -- )
     '[
         NSFastEnumerationState malloc-struct &free
-        NS-EACH-BUFFER-SIZE "id" malloc-array &free
+        NS-EACH-BUFFER-SIZE id malloc-array &free
         NS-EACH-BUFFER-SIZE
         @
     ] with-destructors ; inline
@@ -19,7 +18,7 @@ CONSTANT: NS-EACH-BUFFER-SIZE 16
 :: (NSFastEnumeration-each) ( object quot: ( elt -- ) state stackbuf count -- )
     object state stackbuf count -> countByEnumeratingWithState:objects:count: :> items-count
     items-count 0 = [
-        state itemsPtr>> [ items-count "id" <c-direct-array> ] [ stackbuf ] if* :> items
+        state itemsPtr>> [ items-count id <c-direct-array> ] [ stackbuf ] if* :> items
         items-count iota [ items nth quot call ] each
         object quot state stackbuf count (NSFastEnumeration-each)
     ] unless ; inline recursive
index ceb097bb3adc50749915272b3d82af74b8a56a80..86b13b2ddc2e83341c83480bad3b81b16e20ea17 100644 (file)
@@ -4,8 +4,8 @@
 USING: strings arrays hashtables assocs sequences fry macros
 cocoa.messages cocoa.classes cocoa.application cocoa kernel
 namespaces io.backend math cocoa.enumeration byte-arrays
-combinators alien.c-types words core-foundation quotations
-core-foundation.data core-foundation.utilities ;
+combinators alien.c-types alien.data words core-foundation
+quotations core-foundation.data core-foundation.utilities ;
 IN: cocoa.plists
 
 : >plist ( value -- plist ) >cf -> autorelease ;
index f41bc853b53f507dfde54a6e6ac3266c218453ec..e1551f54c0fca0f728701f0fb471f85929227328 100755 (executable)
@@ -459,7 +459,7 @@ TUPLE: callback-context ;
 
 : callback-return-quot ( ctype -- quot )
     return>> {
-        { [ dup "void" = ] [ drop [ ] ] }
+        { [ dup void? ] [ drop [ ] ] }
         { [ dup large-struct? ] [ heap-size '[ _ memcpy ] ] }
         [ c-type c-type-unboxer-quot ]
     } cond ;
index 484b1f4f2f8d49a60eb5c41845e7098bb50c45df..e21e13dc1325569c18d896f85115aedf791cdbe3 100755 (executable)
@@ -5,6 +5,7 @@ io.streams.string kernel math memory namespaces
 namespaces.private parser quotations sequences
 specialized-arrays stack-checker stack-checker.errors
 system threads tools.test words ;
+FROM: alien.c-types => float short ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-ARRAY: char
 IN: compiler.tests.alien
index fcbac304442048509ad86c24cbfc2c8b80bcf0dc..56e368e3209d46e738bac6accd80eb7fc1476fd0 100644 (file)
@@ -4,6 +4,7 @@ namespaces.private slots.private sequences.private byte-arrays alien
 alien.accessors layouts words definitions compiler.units io
 combinators vectors grouping make alien.c-types combinators.short-circuit
 math.order math.libm math.parser ;
+FROM: math => float ;
 QUALIFIED: namespaces.private
 IN: compiler.tests.codegen
 
@@ -414,4 +415,4 @@ cell 4 = [
 [ "0.169967142900241" "0.9854497299884601" ] [ 1.4 [ [ fcos ] [ fsin ] bi ] compile-call [ number>string ] bi@ ] unit-test
 [ 1 "0.169967142900241" "0.9854497299884601" ] [ 1.4 1 [ swap >float [ fcos ] [ fsin ] bi ] compile-call [ number>string ] bi@ ] unit-test
 
-[ 6.0 ] [ 1.0 [ >float 3.0 + [ B{ 0 0 0 0 } 0 set-alien-float ] [ 2.0 + ] bi ] compile-call ] unit-test
\ No newline at end of file
+[ 6.0 ] [ 1.0 [ >float 3.0 + [ B{ 0 0 0 0 } 0 set-alien-float ] [ 2.0 + ] bi ] compile-call ] unit-test
index ad2d2c8be5c0ec2cd28997056507b39a4b89c85d..24114e0ccbb9e46f9017b34f2f93474d5f30983f 100644 (file)
@@ -3,8 +3,9 @@ math math.constants math.private math.integers.private sequences
 strings tools.test words continuations sequences.private
 hashtables.private byte-arrays system random layouts vectors
 sbufs strings.private slots.private alien math.order
-alien.accessors alien.c-types alien.syntax alien.strings
+alien.accessors alien.c-types alien.data alien.syntax alien.strings
 namespaces libc io.encodings.ascii classes compiler ;
+FROM: math => float ;
 IN: compiler.tests.intrinsics
 
 ! Make sure that intrinsic ops compile to correct code.
index faf69686702c78adec3493422e10c30a42b252e4..02e7409c24aa3fd02da25f84977dd8910ed73ba8 100755 (executable)
@@ -16,6 +16,7 @@ compiler.tree.propagation
 compiler.tree.propagation.info
 compiler.tree.checker
 compiler.tree.debugger ;
+FROM: math => float ;
 IN: compiler.tree.cleanup.tests
 
 [ t ] [ [ [ 1 ] [ 2 ] if ] cleaned-up-tree [ #if? ] contains-node? ] unit-test
index 0c220542ca64da1d6ff45bf84878933d681e1f76..0da234791b8d707a6c769b28a435f086829d225f 100644 (file)
@@ -10,6 +10,7 @@ compiler.tree.debugger compiler.tree.checker
 slots.private words hashtables classes assocs locals
 specialized-arrays system sorting math.libm
 math.intervals quotations effects alien ;
+FROM: math => float ;
 SPECIALIZED-ARRAY: double
 IN: compiler.tree.propagation.tests
 
index f01f522d61bd309bbd2d1fa32d3787a718a50b75..ae061cb4eb8e0e3dcf560e5f87700b7158cf63a3 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.c-types alien.syntax kernel math core-foundation ;
+FROM: math => float ;
 IN: core-foundation.numbers
 
 TYPEDEF: void* CFNumberRef
index 83f1bc9a74357f043c8bbd55ef020d45a58bd9a5..2a16a8b6df8511549bb39cf683881a50f2d3f93e 100644 (file)
@@ -2,13 +2,14 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs sequences kernel combinators make math
 math.order math.ranges system namespaces locals layouts words
-alien alien.accessors alien.c-types literals cpu.architecture
+alien alien.accessors alien.c-types alien.data literals cpu.architecture
 cpu.ppc.assembler cpu.ppc.assembler.backend compiler.cfg.registers
 compiler.cfg.instructions compiler.cfg.comparisons
 compiler.codegen.fixup compiler.cfg.intrinsics
 compiler.cfg.stack-frame compiler.cfg.build-stack-frame
 compiler.units compiler.constants compiler.codegen vm ;
 FROM: cpu.ppc.assembler => B ;
+FROM: math => float ;
 IN: cpu.ppc
 
 ! PowerPC register assignments:
@@ -782,5 +783,5 @@ USE: vocabs.loader
         4 >>align
         "box_boolean" >>boxer
         "to_boolean" >>unboxer
-    "bool" define-primitive-type
+    bool define-primitive-type
 ] with-compilation-unit
index 17cc0e3f8042ff40274cad621b243f790585aa52..13e91a87a4709656ac6a8444e56c79c6998295ca 100644 (file)
@@ -16,9 +16,10 @@ M: float-regs param-regs
 
 M: x86.64 reserved-area-size 0 ;
 
-! The ABI for passing structs by value is pretty messed up
-<< "void*" c-type clone "__stack_value" define-primitive-type
-stack-params "__stack_value" c-type (>>rep) >>
+SYMBOL: (stack-value)
+! The ABI for passing structs by value is pretty great
+<< void* c-type clone \ (stack-value) define-primitive-type
+stack-params \ (stack-value) c-type (>>rep) >>
 
 : struct-types&offset ( struct-type -- pairs )
     fields>> [
@@ -33,12 +34,12 @@ stack-params "__stack_value" c-type (>>rep) >>
 : flatten-small-struct ( c-type -- seq )
     struct-types&offset split-struct [
         [ c-type c-type-rep reg-class-of ] map
-        int-regs swap member? "void*" "double" ? c-type
+        int-regs swap member? void* double ? c-type
     ] map ;
 
 : flatten-large-struct ( c-type -- seq )
     heap-size cell align
-    cell /i "__stack_value" c-type <repetition> ;
+    cell /i \ (stack-value) c-type <repetition> ;
 
 : flatten-struct ( c-type -- seq )
     dup heap-size 16 > [
index d9f83612e60394729cc9bda88fc8701fb21de26d..bbe943e06ba2419b26cfa8ac34933c9e4ba78ce0 100644 (file)
@@ -25,8 +25,8 @@ M: x86.64 dummy-fp-params? t ;
 M: x86.64 temp-reg RAX ;
 
 <<
-"longlong" "ptrdiff_t" typedef
-"longlong" "intptr_t" typedef
-"int" c-type "long" define-primitive-type
-"uint" c-type "ulong" define-primitive-type
+longlong ptrdiff_t typedef
+longlong intptr_t  typedef
+int  c-type long  define-primitive-type
+uint c-type ulong define-primitive-type
 >>
index 02235bb62ea58ad2854c120334208edfbc753b84..c5cf2d470abd4dbd65fbf1e984ba5f7e79d27736 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: system kernel math math.order math.parser namespaces
-alien.syntax combinators locals init io cpu.x86 compiler
-compiler.units accessors ;
+alien.c-types alien.syntax combinators locals init io cpu.x86
+compiler compiler.units accessors ;
 IN: cpu.x86.features
 
 <PRIVATE
index 91705efec6d46a39e367d90a6a15bde6bdff46b6..97bd2f78ded9c8ef7a4699b9562f42e25c814b46 100644 (file)
@@ -4,14 +4,14 @@ USING: accessors assocs alien alien.c-types arrays strings
 cpu.x86.assembler cpu.x86.assembler.private cpu.x86.assembler.operands
 cpu.architecture kernel kernel.private math memory namespaces make
 sequences words system layouts combinators math.order fry locals
-compiler.constants byte-arrays
+compiler.constants vm byte-arrays
 compiler.cfg.registers
 compiler.cfg.instructions
 compiler.cfg.intrinsics
 compiler.cfg.comparisons
 compiler.cfg.stack-frame
-compiler.codegen
-compiler.codegen.fixup vm ;
+compiler.codegen.fixup ;
+FROM: math => float ;
 IN: cpu.x86
 
 << enable-fixnum-log2 >>
index 2278afe4edb8d821892062ada4013fba6d2f8ea4..5398e669ed6af622ef341dbbf27164afbc52dc20 100644 (file)
@@ -2,11 +2,11 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays continuations db io kernel math namespaces
 quotations sequences db.postgresql.ffi alien alien.c-types
-db.types tools.walker ascii splitting math.parser combinators
-libc calendar.format byte-arrays destructors prettyprint
-accessors strings serialize io.encodings.binary io.encodings.utf8
-alien.strings io.streams.byte-array summary present urls
-specialized-arrays db.private ;
+alien.data db.types tools.walker ascii splitting math.parser
+combinators libc calendar.format byte-arrays destructors
+prettyprint accessors strings serialize io.encodings.binary
+io.encodings.utf8 alien.strings io.streams.byte-array summary
+present urls specialized-arrays db.private ;
 SPECIALIZED-ARRAY: uint
 SPECIALIZED-ARRAY: void*
 IN: db.postgresql.lib
index 3565b098564b95c150e65c7260f244c84ef6ab28..163026f5ff2031bd3158b0db4135845a71a904e7 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Chris Double, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types arrays assocs kernel math math.parser
+USING: alien.c-types alien.data arrays assocs kernel math math.parser
 namespaces sequences db.sqlite.ffi db combinators
 continuations db.types calendar.format serialize
 io.streams.byte-array byte-arrays io.encodings.binary
index 2fad0e4c2e96de400fd43e26f9343c3a665b54d1..1e08896e8d585aba24c1b0fd73f947a87b6d24d8 100644 (file)
@@ -174,6 +174,8 @@ M: no-method error.
 
 M: bad-slot-value summary drop "Bad store to specialized slot" ;
 
+M: bad-slot-name summary drop "Bad slot name in object literal" ;
+
 M: no-math-method summary
     drop "No suitable arithmetic method" ;
 
index 84dfbbd43e68906717bb819169c3556ce7f56ec3..3fc8c2f79bc54671e5e58585aa3a20a4e89ca197 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings alien.syntax kernel
-layouts sequences system unix environment io.encodings.utf8
-unix.utilities vocabs.loader combinators alien.accessors ;
+USING: alien alien.c-types alien.data alien.strings
+alien.syntax kernel layouts sequences system unix
+environment io.encodings.utf8 unix.utilities vocabs.loader
+combinators alien.accessors ;
 IN: environment.unix
 
 HOOK: environ os ( -- void* )
index 518a7d5d7a29d44be485cfe9438354f958ce3aa6..894415ace898e706e69281e241c41d193693dfe1 100755 (executable)
@@ -1,15 +1,14 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.strings fry io.encodings.utf16n kernel
-splitting windows windows.kernel32 system environment
-alien.c-types sequences windows.errors io.streams.memory
-io.encodings io ;
+splitting windows windows.kernel32 windows.types system
+environment alien.data sequences windows.errors
+io.streams.memory io.encodings io specialized-arrays ;
+SPECIALIZED-ARRAY: TCHAR
 IN: environment.winnt
 
-<< "TCHAR" require-c-array >>
-
 M: winnt os-env ( key -- value )
-    MAX_UNICODE_PATH "TCHAR" <c-array>
+    MAX_UNICODE_PATH TCHAR <c-array>
     [ dup length GetEnvironmentVariable ] keep over 0 = [
         2drop f
     ] [
index bcdc1bae740bc23c96836a836f3d531670293682..58da96aa171279efbb15692ac4158075b1ba04b8 100644 (file)
@@ -1,5 +1,6 @@
 USING: classes.struct functors tools.test math words kernel
 multiline parser io.streams.string generic ;
+QUALIFIED-WITH: alien.c-types c
 IN: functors.tests
 
 <<
@@ -160,15 +161,15 @@ T-class DEFINES-CLASS ${T}
 WHERE
 
 STRUCT: T-class
-    { NAME int }
+    { NAME c:int }
     { x { TYPE 4 } }
-    { y { "short" N } }
+    { y { c:short N } }
     { z TYPE initial: 5 }
-    { float { "float" 2 } } ;
+    { float { c:float 2 } } ;
 
 ;FUNCTOR
 
-"a-struct" "nemo" "char" 2 define-a-struct
+"a-struct" "nemo" c:char 2 define-a-struct
 
 >>
 
@@ -179,35 +180,35 @@ STRUCT: T-class
             { offset 0 }
             { class integer }
             { initial 0 } 
-            { c-type "int" }
+            { type c:int }
         }
         T{ struct-slot-spec
             { name "x" }
             { offset 4 }
             { class object }
             { initial f } 
-            { c-type { "char" 4 } }
+            { type { c:char 4 } }
         }
         T{ struct-slot-spec
             { name "y" }
             { offset 8 }
             { class object }
             { initial f } 
-            { c-type { "short" 2 } }
+            { type { c:short 2 } }
         }
         T{ struct-slot-spec
             { name "z" }
             { offset 12 }
             { class fixnum }
             { initial 5 } 
-            { c-type "char" }
+            { type c:char }
         }
         T{ struct-slot-spec
             { name "float" }
             { offset 16 }
             { class object }
             { initial f } 
-            { c-type { "float" 2 } }
+            { type { c:float 2 } }
         }
     }
 ] [ a-struct struct-slots ] unit-test
diff --git a/basis/furnace/recaptcha/authors.txt b/basis/furnace/recaptcha/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/furnace/recaptcha/example/authors.txt b/basis/furnace/recaptcha/example/authors.txt
new file mode 100644 (file)
index 0000000..b4bd0e7
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
\ No newline at end of file
diff --git a/basis/furnace/recaptcha/example/example.factor b/basis/furnace/recaptcha/example/example.factor
new file mode 100644 (file)
index 0000000..264be67
--- /dev/null
@@ -0,0 +1,31 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors db.sqlite furnace.actions furnace.alloy
+furnace.conversations furnace.recaptcha furnace.redirection
+html.templates.chloe.compiler http.server
+http.server.dispatchers http.server.responses io.streams.string
+kernel urls xml.syntax ;
+IN: furnace.recaptcha.example
+
+TUPLE: recaptcha-app < dispatcher recaptcha ;
+
+: recaptcha-db ( -- obj ) "recaptcha-example" <sqlite-db> ;
+
+: <recaptcha-challenge> ( -- obj )
+    <page-action>
+        [
+            begin-conversation
+            validate-recaptcha
+            recaptcha-valid? cget
+            "?good" "?bad" ? >url <continue-conversation>
+        ] >>submit
+        { recaptcha-app "example" } >>template ;
+
+: <recaptcha-app> ( -- obj )
+    \ recaptcha-app new-dispatcher
+        <recaptcha-challenge> "" add-responder
+        <recaptcha>
+        "concatenative.org" >>domain
+        "6LeJWQgAAAAAAFlYV7SuBClE9uSpGtV_ZS-qVON7" >>public-key
+        "6LeJWQgAAAAAALh-XJgSSQ6xKygRgJ8-029Ip2Xv" >>private-key
+        recaptcha-db <alloy> ;
diff --git a/basis/furnace/recaptcha/example/example.xml b/basis/furnace/recaptcha/example/example.xml
new file mode 100644 (file)
index 0000000..e59f441
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version='1.0' ?>
+<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
+<html><body><form submit="" method="post"><t:recaptcha/></form></body></html>
+</t:chloe>
diff --git a/basis/furnace/recaptcha/recaptcha-docs.factor b/basis/furnace/recaptcha/recaptcha-docs.factor
new file mode 100644 (file)
index 0000000..e6473a4
--- /dev/null
@@ -0,0 +1,55 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax http.server.filters kernel
+multiline furnace.actions furnace.alloy furnace.conversations ;
+IN: furnace.recaptcha
+
+HELP: <recaptcha>
+{ $values
+    { "responder" "a responder" }
+    { "obj" object }
+}
+{ $description "A " { $link filter-responder } " wrapping another responder. Set the domain, public, and private keys using the key you get by registering with Recaptcha." } ;
+
+HELP: recaptcha-error
+{ $var-description "Set to the error string returned by the Recaptcha server." } ;
+
+HELP: recaptcha-valid?
+{ $var-description "Set to " { $link t } " if the user solved the last Recaptcha correctly." } ;
+
+HELP: validate-recaptcha
+{ $description "Validates a Recaptcha using the Recaptcha web service API." } ;
+
+ARTICLE: "recaptcha-example" "Recaptcha example"
+"There are several steps to using the Recaptcha library."
+{ $list
+    { "Wrap the responder in a " { $link <recaptcha> } }
+    { "Wrap the responder in a " { $link <conversations> } " if it is not already" }
+    { "Ensure that there is a database connected, with the " { $link <alloy> } " word" }
+    { "Start a conversation to move values between requests" }
+    { "Add a handler calling " { $link validate-recaptcha } " in the " { $slot "submit" } " of the " { $link page-action } }
+    { "Pass the conversation from your submit action using " { $link <continue-conversation> } }
+    { "Put the chloe tag " { $snippet "<recaptcha/>" } " inside a form tag in the template for your " { $link page-action } }
+}
+$nl
+"Run this example vocabulary:"
+{ $code
+    "USE: furnace.recaptcha.example"
+    "<recaptcha-app> main-responder set-global"
+} ;
+
+ARTICLE: "furnace.recaptcha" "Recaptcha"
+"The " { $vocab-link "furnace.recaptcha" } " vocabulary implements support for the Recaptcha. Recaptcha is a web service that provides the user with a captcha, a test that is easy to solve by visual inspection, but hard to solve by writing a computer program. Use a captcha to protect forms from abusive users." $nl
+
+"The recaptcha responder is a " { $link filter-responder } " that wraps another responder. Set the " { $slot "domain" } ", " { $slot "public-key" } ", and " { $slot "private-key" } " slots of this responder to your Recaptcha account information." $nl
+
+"Wrapping a responder with Recaptcha:"
+{ $subsection <recaptcha> }
+"Validating recaptcha:"
+{ $subsection validate-recaptcha }
+"Symbols set after validation:"
+{ $subsection recaptcha-valid? }
+{ $subsection recaptcha-error }
+{ $subsection "recaptcha-example" } ;
+
+ABOUT: "furnace.recaptcha"
diff --git a/basis/furnace/recaptcha/recaptcha.factor b/basis/furnace/recaptcha/recaptcha.factor
new file mode 100644 (file)
index 0000000..99b223b
--- /dev/null
@@ -0,0 +1,76 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors furnace.actions furnace.redirection html.forms
+html.templates.chloe.compiler html.templates.chloe.syntax
+http.client http.server http.server.filters io.sockets kernel
+locals namespaces sequences splitting urls validators
+xml.syntax furnace.conversations ;
+IN: furnace.recaptcha
+
+TUPLE: recaptcha < filter-responder domain public-key private-key ;
+
+SYMBOLS: recaptcha-valid? recaptcha-error ;
+
+: <recaptcha> ( responder -- obj )
+    recaptcha new
+        swap >>responder ;
+
+M: recaptcha call-responder*
+    dup \ recaptcha set
+    responder>> call-responder ;
+
+<PRIVATE
+
+: (render-recaptcha) ( private-key -- xml )
+    dup
+[XML <script type="text/javascript"
+   src=<->>
+</script>
+
+<noscript>
+   <iframe src=<->
+       height="300" width="500" frameborder="0"></iframe><br/>
+   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
+   </textarea>
+   <input type="hidden" name="recaptcha_response_field" 
+       value="manual_challenge"/>
+</noscript>
+XML] ;
+
+: recaptcha-url ( secure? -- ? )
+    [ "https://api.recaptcha.net/challenge" ]
+    [ "http://api.recaptcha.net/challenge" ] if
+    recaptcha-error cget [ "?error=" glue ] when* >url ;
+
+: render-recaptcha ( -- xml )
+    secure-connection? recaptcha-url
+    recaptcha get public-key>> "k" set-query-param (render-recaptcha) ;
+
+: parse-recaptcha-response ( string -- valid? error )
+    "\n" split first2 [ "true" = ] dip ;
+
+:: (validate-recaptcha) ( challenge response recaptcha -- valid? error )
+    recaptcha private-key>> :> private-key
+    remote-address get host>> :> remote-ip
+    H{
+        { "challenge" challenge }
+        { "response" response }
+        { "privatekey" private-key }
+        { "remoteip" remote-ip }
+    } URL" http://api-verify.recaptcha.net/verify"
+    <post-request> http-request nip parse-recaptcha-response ;
+
+CHLOE: recaptcha
+    drop [ render-recaptcha ] [xml-code] ;
+
+PRIVATE>
+
+: validate-recaptcha ( -- )
+    {
+        { "recaptcha_challenge_field" [ v-required ] }
+        { "recaptcha_response_field" [ v-required ] }
+    } validate-params
+    "recaptcha_challenge_field" value
+    "recaptcha_response_field" value
+    \ recaptcha get (validate-recaptcha)
+    [ recaptcha-valid? cset ] [ recaptcha-error cset ] bi* ;
diff --git a/basis/furnace/recaptcha/recaptcha.xml b/basis/furnace/recaptcha/recaptcha.xml
new file mode 100644 (file)
index 0000000..6cbf795
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version='1.0' ?>
+<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
+<html>
+       <body><t:recaptcha/>
+       </body>
+</html>
+</t:chloe>
diff --git a/basis/furnace/recaptcha/summary.txt b/basis/furnace/recaptcha/summary.txt
new file mode 100644 (file)
index 0000000..909566f
--- /dev/null
@@ -0,0 +1 @@
+Recaptcha library
diff --git a/basis/furnace/recaptcha/tags.txt b/basis/furnace/recaptcha/tags.txt
new file mode 100644 (file)
index 0000000..c077218
--- /dev/null
@@ -0,0 +1 @@
+web
index ea3100f95f6f99a2dfb1d70a1de1e6d3b1e09fe3..16bea60ea5992380418a08eb249cd32d89ae3930 100755 (executable)
@@ -6,7 +6,7 @@ math.rectangles namespaces parser sequences shuffle
 specialized-arrays ui.backend.windows vectors windows.com
 windows.dinput windows.dinput.constants windows.errors
 windows.kernel32 windows.messages windows.ole32
-windows.user32 classes.struct ;
+windows.user32 classes.struct alien.data ;
 SPECIALIZED-ARRAY: DIDEVICEOBJECTDATA
 IN: game-input.dinput
 
@@ -160,19 +160,24 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+
     [ device-attached? not ] filter
     [ remove-controller ] each ;
 
-: device-interface? ( dbt-broadcast-hdr -- ? )
-    dbch_devicetype>> DBT_DEVTYP_DEVICEINTERFACE = ;
+: ?device-interface ( dbt-broadcast-hdr -- ? )
+    dup dbch_devicetype>> DBT_DEVTYP_DEVICEINTERFACE =
+    [ >c-ptr DEV_BROADCAST_DEVICEW memory>struct ]
+    [ drop f ] if ; inline
 
 : device-arrived ( dbt-broadcast-hdr -- )
-    device-interface? [ find-controllers ] when ;
+    ?device-interface [ find-controllers ] when ; inline
 
 : device-removed ( dbt-broadcast-hdr -- )
-    device-interface? [ find-and-remove-detached-devices ] when ;
+    ?device-interface [ find-and-remove-detached-devices ] when ; inline
+
+: <DEV_BROADCAST_HDR> ( wParam -- struct )
+    <alien> DEV_BROADCAST_HDR memory>struct ;
 
 : handle-wm-devicechange ( hWnd uMsg wParam lParam -- )
     [ 2drop ] 2dip swap {
-        { [ dup DBT_DEVICEARRIVAL = ]         [ drop <alien> device-arrived ] }
-        { [ dup DBT_DEVICEREMOVECOMPLETE = ]  [ drop <alien> device-removed ] }
+        { [ dup DBT_DEVICEARRIVAL = ]         [ drop <DEV_BROADCAST_HDR> device-arrived ] }
+        { [ dup DBT_DEVICEREMOVECOMPLETE = ]  [ drop <DEV_BROADCAST_HDR> device-removed ] }
         [ 2drop ]
     } cond ;
 
index 9a84747dd8fee521bd2b099f7e9b893a2d8d44a7..a8813b0397887d0511ad9980f1b72b6e256e2baf 100755 (executable)
@@ -1,5 +1,5 @@
-USING: sequences sequences.private math alien.c-types
-accessors ;
+USING: sequences sequences.private math
+accessors alien.data ;
 IN: game-input.dinput.keys-array
 
 TUPLE: keys-array
index 71d547ad29ed7521f7ac1c78678a524ea117cc9f..85f058f283df01f379931c5bcc9fde9b53aa1c87 100755 (executable)
@@ -3,7 +3,8 @@ kernel cocoa.enumeration destructors math.parser cocoa.application
 sequences locals combinators.short-circuit threads
 namespaces assocs arrays combinators hints alien
 core-foundation.run-loop accessors sequences.private
-alien.c-types math parser game-input vectors bit-arrays ;
+alien.c-types alien.data math parser game-input vectors
+bit-arrays ;
 IN: game-input.iokit
 
 SINGLETON: iokit-game-input-backend
index 9716407de880fadb9edd4af71628698427a1b722..61121bd769c191d3bc4af6afbeef4b83537e51fb 100644 (file)
@@ -24,7 +24,7 @@ HELP: compile-attr
 { $description "Compiles code which pushes an attribute value previously extracted by " { $link required-attr } " or " { $link optional-attr } " on the stack. If the attribute value begins with " { $snippet "@" } ", compiles into code which pushes the a form value." } ;
 
 HELP: CHLOE:
-{ $syntax "name definition... ;" }
+{ $syntax "CHLOE: name definition... ;" }
 { $values { "name" "the tag name" } { "definition" { $quotation "( tag -- )" } } }
 { $description "Defines compilation semantics for the Chloe tag named " { $snippet "tag" } ". The definition body receives a " { $link tag } " on the stack." } ;
 
index 1a977b604e1aff4cde43c4cbba0222a1ac8a9df4..ccf891d770f4458687d432dbdfdc6b543160ab35 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types destructors fry images kernel
-libc math sequences ;
+USING: accessors alien.c-types alien.data destructors fry images
+kernel libc math sequences ;
 IN: images.memory
 
 ! Some code shared by core-graphics and cairo for constructing
@@ -27,4 +27,4 @@ PRIVATE>
 : make-memory-bitmap ( dim quot -- image )
     '[
         [ malloc-bitmap-data ] keep _ [ <bitmap-image> ] 2bi
-    ] with-destructors ; inline
\ No newline at end of file
+    ] with-destructors ; inline
index 57878ba75bce142f74ad797387ee794d87598c43..6022e91efdcbf4c4e3280c659390d642bc646bee 100755 (executable)
@@ -1,52 +1,43 @@
-USING: alien alien.c-types alien.syntax arrays continuations\r
-destructors generic io.mmap io.ports io.backend.windows io.files.windows\r
-kernel libc math math.bitwise namespaces quotations sequences windows\r
-windows.advapi32 windows.kernel32 io.backend system accessors\r
-io.backend.windows.privileges windows.errors ;\r
-IN: io.backend.windows.nt.privileges\r
-\r
-TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES\r
-\r
-! Security tokens\r
-!  http://msdn.microsoft.com/msdnmag/issues/05/03/TokenPrivileges/\r
-\r
-: (open-process-token) ( handle -- handle )\r
-    { TOKEN_ADJUST_PRIVILEGES TOKEN_QUERY } flags "PHANDLE" <c-object>\r
-    [ OpenProcessToken win32-error=0/f ] keep *void* ;\r
-\r
-: open-process-token ( -- handle )\r
-    #! remember to CloseHandle\r
-    GetCurrentProcess (open-process-token) ;\r
-\r
-: with-process-token ( quot -- )\r
-    #! quot: ( token-handle -- token-handle )\r
-    [ open-process-token ] dip\r
-    [ keep ] curry\r
-    [ CloseHandle drop ] [ ] cleanup ; inline\r
-\r
-: lookup-privilege ( string -- luid )\r
-    [ f ] dip "LUID" <c-object>\r
-    [ LookupPrivilegeValue win32-error=0/f ] keep ;\r
-\r
-: make-token-privileges ( name ? -- obj )\r
-    "TOKEN_PRIVILEGES" <c-object>\r
-    1 over set-TOKEN_PRIVILEGES-PrivilegeCount\r
-    "LUID_AND_ATTRIBUTES" malloc-object &free\r
-    over set-TOKEN_PRIVILEGES-Privileges\r
-\r
-    swap [\r
-        SE_PRIVILEGE_ENABLED over TOKEN_PRIVILEGES-Privileges\r
-        set-LUID_AND_ATTRIBUTES-Attributes\r
-    ] when\r
-\r
-    [ lookup-privilege ] dip\r
-    [\r
-        TOKEN_PRIVILEGES-Privileges\r
-        set-LUID_AND_ATTRIBUTES-Luid\r
-    ] keep ;\r
-\r
-M: winnt set-privilege ( name ? -- )\r
-    [\r
-        -rot 0 -rot make-token-privileges\r
-        dup length f f AdjustTokenPrivileges win32-error=0/f\r
-    ] with-process-token ;\r
+USING: alien alien.c-types alien.data alien.syntax arrays continuations
+destructors generic io.mmap io.ports io.backend.windows io.files.windows
+kernel libc locals math math.bitwise namespaces quotations sequences windows
+windows.advapi32 windows.kernel32 windows.types io.backend system accessors
+io.backend.windows.privileges classes.struct windows.errors ;
+IN: io.backend.windows.nt.privileges
+
+TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES
+
+! Security tokens
+!  http://msdn.microsoft.com/msdnmag/issues/05/03/TokenPrivileges/
+
+: (open-process-token) ( handle -- handle )
+    { TOKEN_ADJUST_PRIVILEGES TOKEN_QUERY } flags PHANDLE <c-object>
+    [ OpenProcessToken win32-error=0/f ] keep *void* ;
+
+: open-process-token ( -- handle )
+    #! remember to CloseHandle
+    GetCurrentProcess (open-process-token) ;
+
+: with-process-token ( quot -- )
+    #! quot: ( token-handle -- token-handle )
+    [ open-process-token ] dip
+    [ keep ] curry
+    [ CloseHandle drop ] [ ] cleanup ; inline
+
+: lookup-privilege ( string -- luid )
+    [ f ] dip LUID <struct>
+    [ LookupPrivilegeValue win32-error=0/f ] keep ;
+
+:: make-token-privileges ( name enabled? -- obj )
+    TOKEN_PRIVILEGES <struct>
+        1 >>PrivilegeCount
+        LUID_AND_ATTRIBUTES malloc-struct &free
+            enabled? [ SE_PRIVILEGE_ENABLED >>Attributes ] when
+            name lookup-privilege >>Luid
+        >>Privileges ;
+
+M: winnt set-privilege ( name ? -- )
+    [
+        -rot 0 -rot make-token-privileges
+        dup byte-length f f AdjustTokenPrivileges win32-error=0/f
+    ] with-process-token ;
index 4425e081069a5e198578910cca2f7af95e009130..d366df7c54ff33aa97b696ff0796eec9ce3740dd 100644 (file)
@@ -1,7 +1,7 @@
 IN: io.buffers.tests
-USING: alien alien.c-types io.buffers kernel kernel.private libc
-sequences tools.test namespaces byte-arrays strings accessors
-destructors ;
+USING: alien alien.c-types alien.data io.buffers kernel
+kernel.private libc sequences tools.test namespaces byte-arrays
+strings accessors destructors ;
 
 : buffer-set ( string buffer -- )
     over >byte-array over ptr>> byte-array>memory
index 82c5326b1d95cdac7d5472d767940f9b94929b8b..aa9cedf3404e3fe147e14efa315f0c8529534784 100644 (file)
@@ -2,8 +2,8 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.accessors alien.c-types
-alien.syntax kernel libc math sequences byte-arrays strings
-hints math.order destructors combinators ;
+alien.data alien.syntax kernel libc math sequences byte-arrays
+strings hints math.order destructors combinators ;
 IN: io.buffers
 
 TUPLE: buffer
index bb3a412669ba304e13846bce8c946449d4d8bd09..5ae21fcfee111898ae48b66d7ddfefb177dcf998 100755 (executable)
@@ -6,7 +6,7 @@ windows.time windows accessors alien.c-types combinators
 generalizations system alien.strings io.encodings.utf16n
 sequences splitting windows.errors fry continuations destructors
 calendar ascii combinators.short-circuit locals classes.struct
-specialized-arrays ;
+specialized-arrays alien.data ;
 SPECIALIZED-ARRAY: ushort
 IN: io.files.info.windows
 
index 43463bd3f109d25f538f2da6c7d75ec78a42cc90..ca5c9b3c4aa35713dd64c2d5b147f9f91ccbc942 100755 (executable)
@@ -6,7 +6,7 @@ io.backend.windows kernel math splitting fry alien.strings
 windows windows.kernel32 windows.time calendar combinators
 math.functions sequences namespaces make words system
 destructors accessors math.bitwise continuations windows.errors
-arrays byte-arrays generalizations ;
+arrays byte-arrays generalizations alien.data ;
 IN: io.files.windows
 
 : open-file ( path access-mode create-mode flags -- handle )
index 704a585dd44da68c077ab67e33e74817e8642423..a86623276090882a4e075a9eea051089d7078bd0 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: continuations destructors io.files io.files.info
 io.backend kernel quotations system alien alien.accessors
-accessors vocabs.loader combinators alien.c-types
+accessors vocabs.loader combinators alien.c-types alien.data
 math ;
 IN: io.mmap
 
index 3d837d79d8bc67d2675b7e3e327a2f75620aefbd..9cd8bc4df8ff03001fd760ffa53a7551c6a0bc9a 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings libc destructors locals
-kernel math assocs namespaces make continuations sequences
+USING: alien alien.c-types alien.data alien.strings libc destructors
+locals kernel math assocs namespaces make continuations sequences
 hashtables sorting arrays combinators math.bitwise strings
 system accessors threads splitting io.backend io.backend.windows
 io.backend.windows.nt io.files.windows.nt io.monitors io.ports
index 8f596da0bdca579582964e900e62c62b59fff276..400a44ea020c78daa5e4d7165de773af5ac4f638 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors byte-arrays kernel sequences namespaces math
-math.order combinators init alien alien.c-types alien.strings
-libc continuations destructors summary splitting assocs random
-math.parser locals unicode.case openssl openssl.libcrypto
-openssl.libssl io.backend io.ports io.pathnames
+math.order combinators init alien alien.c-types alien.data
+alien.strings libc continuations destructors summary splitting
+assocs random math.parser locals unicode.case openssl
+openssl.libcrypto openssl.libssl io.backend io.ports io.pathnames
 io.encodings.8-bit io.timeouts io.sockets.secure ;
 IN: io.sockets.secure.openssl
 
@@ -31,7 +31,7 @@ TUPLE: openssl-context < secure-context aliens sessions ;
     ] [ drop ] if ;
 
 : password-callback ( -- alien )
-    "int" { "void*" "int" "bool" "void*" } "cdecl"
+    int { void* int bool void* } "cdecl"
     [| buf size rwflag password! |
         password [ B{ 0 } password! ] unless
 
index 601d269d5c4a5001f2d9a1bba12da3a9799ace5b..a542575446d4717ebc2339b841b55797f56565c6 100755 (executable)
@@ -6,7 +6,7 @@ arrays io.encodings io.ports io.streams.duplex io.encodings.ascii
 alien.strings io.binary accessors destructors classes byte-arrays
 parser alien.c-types math.parser splitting grouping math assocs
 summary system vocabs.loader combinators present fry vocabs.parser
-classes.struct ;
+classes.struct alien.data ;
 IN: io.sockets
 
 << {
index e892c6a7ef308749c1669176a7cfafcd1805c011..fa46a71ca087525c763e2e9ad73d34749cf09a82 100755 (executable)
@@ -5,7 +5,7 @@ threads sequences byte-arrays io.binary io.backend.unix
 io.streams.duplex io.backend io.pathnames io.sockets.private
 io.files.private io.encodings.utf8 math.parser continuations
 libc combinators system accessors destructors unix locals init
-classes.struct ;
+classes.struct alien.data ;
 
 EXCLUDE: namespaces => bind ;
 EXCLUDE: io => read write ;
index f423a42b6523e940f16669805403cdcf3875b46b..7cc21c961163511c4e94ca6cb0f271a95d3f4a6c 100755 (executable)
@@ -1,4 +1,4 @@
-USING: alien alien.accessors alien.c-types byte-arrays
+USING: alien alien.accessors alien.c-types alien.data byte-arrays
 continuations destructors io.ports io.timeouts io.sockets
 io.sockets.private io namespaces io.streams.duplex
 io.backend.windows io.sockets.windows io.backend.windows.nt
index 4142e40c6840671b653248e783e9844f76affa3d..fe56c83516eca532fedd5cc934ea64e24238fc3d 100644 (file)
@@ -2,29 +2,29 @@
 ! Copyright (C) 2007, 2009 Slava Pestov
 ! Copyright (C) 2007, 2008 Doug Coleman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien assocs continuations alien.destructors kernel
+USING: alien alien.c-types assocs continuations alien.destructors kernel
 namespaces accessors sets summary destructors destructors.private ;
 IN: libc
 
 : errno ( -- int )
-    "int" "factor" "err_no" { } alien-invoke ;
+    int "factor" "err_no" { } alien-invoke ;
 
 : clear-errno ( -- )
-    "void" "factor" "clear_err_no" { } alien-invoke ;
+    void "factor" "clear_err_no" { } alien-invoke ;
 
 <PRIVATE
 
 : (malloc) ( size -- alien )
-    "void*" "libc" "malloc" { "ulong" } alien-invoke ;
+    void* "libc" "malloc" { ulong } alien-invoke ;
 
 : (calloc) ( count size -- alien )
-    "void*" "libc" "calloc" { "ulong" "ulong" } alien-invoke ;
+    void* "libc" "calloc" { ulong ulong } alien-invoke ;
 
 : (free) ( alien -- )
-    "void" "libc" "free" { "void*" } alien-invoke ;
+    void "libc" "free" { void* } alien-invoke ;
 
 : (realloc) ( alien size -- newalien )
-    "void*" "libc" "realloc" { "void*" "ulong" } alien-invoke ;
+    void* "libc" "realloc" { void* ulong } alien-invoke ;
 
 ! We stick malloc-ptr instances in the global disposables set
 TUPLE: malloc-ptr value continuation ;
@@ -81,15 +81,15 @@ PRIVATE>
     >c-ptr [ delete-malloc ] [ (free) ] bi ;
 
 : memcpy ( dst src size -- )
-    "void" "libc" "memcpy" { "void*" "void*" "ulong" } alien-invoke ;
+    void "libc" "memcpy" { void* void* ulong } alien-invoke ;
 
 : memcmp ( a b size -- cmp )
-    "int" "libc" "memcmp" { "void*" "void*" "ulong" } alien-invoke ;
+    int "libc" "memcmp" { void* void* ulong } alien-invoke ;
 
 : memory= ( a b size -- ? )
     memcmp 0 = ;
 
 : strlen ( alien -- len )
-    "size_t" "libc" "strlen" { "char*" } alien-invoke ;
+    size_t "libc" "strlen" { char* } alien-invoke ;
 
 DESTRUCTOR: free
index a051fb250de2b53bb73d17cc8bdc2aea3b93c408..aa9681bb2e952360d1add249b10f14efedba6df5 100755 (executable)
@@ -1,10 +1,11 @@
-USING: accessors alien alien.c-types arrays byte-arrays combinators
-combinators.short-circuit fry kernel locals macros
-math math.blas.ffi math.blas.vectors math.blas.vectors.private
-math.complex math.functions math.order functors words
-sequences sequences.merged sequences.private shuffle
-parser prettyprint.backend prettyprint.custom ascii
-specialized-arrays ;
+USING: accessors alien alien.c-types alien.data arrays
+byte-arrays combinators combinators.short-circuit fry
+kernel locals macros math math.blas.ffi math.blas.vectors
+math.blas.vectors.private math.complex math.functions
+math.order functors words sequences sequences.merged
+sequences.private shuffle parser prettyprint.backend
+prettyprint.custom ascii specialized-arrays ;
+FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-ARRAY: double
 SPECIALIZED-ARRAY: complex-float
index c08fdb612081d0caa7410973a9d2250a9c631bf3..20ee7925b080a285d67838cb96859cf18962ab5b 100755 (executable)
@@ -3,6 +3,7 @@ combinators.short-circuit fry kernel math math.blas.ffi
 math.complex math.functions math.order sequences sequences.private
 functors words locals parser prettyprint.backend prettyprint.custom
 specialized-arrays ;
+FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-ARRAY: double
 SPECIALIZED-ARRAY: complex-float
index df8b36fd28c49377518c191a4ab4f12edb119f62..0288894081bf1006cdc4e5893d28166ed3926cd5 100644 (file)
@@ -1,62 +1,62 @@
 ! Copyright (C) 2006 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien ;
+USING: alien alien.c-types ;
 IN: math.libm
 
 : facos ( x -- y )
-    "double" "libm" "acos" { "double" } alien-invoke ;
+    double "libm" "acos" { double } alien-invoke ;
 
 : fasin ( x -- y )
-    "double" "libm" "asin" { "double" } alien-invoke ;
+    double "libm" "asin" { double } alien-invoke ;
 
 : fatan ( x -- y )
-    "double" "libm" "atan" { "double" } alien-invoke ;
+    double "libm" "atan" { double } alien-invoke ;
 
 : fatan2 ( x y -- z )
-    "double" "libm" "atan2" { "double" "double" } alien-invoke ;
+    double "libm" "atan2" { double double } alien-invoke ;
 
 : fcos ( x -- y )
-    "double" "libm" "cos" { "double" } alien-invoke ;
+    double "libm" "cos" { double } alien-invoke ;
 
 : fsin ( x -- y )
-    "double" "libm" "sin" { "double" } alien-invoke ;
+    double "libm" "sin" { double } alien-invoke ;
 
 : ftan ( x -- y )
-    "double" "libm" "tan" { "double" } alien-invoke ;
+    double "libm" "tan" { double } alien-invoke ;
 
 : fcosh ( x -- y )
-    "double" "libm" "cosh" { "double" } alien-invoke ;
+    double "libm" "cosh" { double } alien-invoke ;
 
 : fsinh ( x -- y )
-    "double" "libm" "sinh" { "double" } alien-invoke ;
+    double "libm" "sinh" { double } alien-invoke ;
 
 : ftanh ( x -- y )
-    "double" "libm" "tanh" { "double" } alien-invoke ;
+    double "libm" "tanh" { double } alien-invoke ;
 
 : fexp ( x -- y )
-    "double" "libm" "exp" { "double" } alien-invoke ;
+    double "libm" "exp" { double } alien-invoke ;
 
 : flog ( x -- y )
-    "double" "libm" "log" { "double" } alien-invoke ;
+    double "libm" "log" { double } alien-invoke ;
 
 : flog10 ( x -- y )
-    "double" "libm" "log10" { "double" } alien-invoke ;
+    double "libm" "log10" { double } alien-invoke ;
 
 : fpow ( x y -- z )
-    "double" "libm" "pow" { "double" "double" } alien-invoke ;
+    double "libm" "pow" { double double } alien-invoke ;
 
 : fsqrt ( x -- y )
-    "double" "libm" "sqrt" { "double" } alien-invoke ;
+    double "libm" "sqrt" { double } alien-invoke ;
     
 ! Windows doesn't have these...
 : flog1+ ( x -- y )
-    "double" "libm" "log1p" { "double" } alien-invoke ;
+    double "libm" "log1p" { double } alien-invoke ;
 
 : facosh ( x -- y )
-    "double" "libm" "acosh" { "double" } alien-invoke ;
+    double "libm" "acosh" { double } alien-invoke ;
 
 : fasinh ( x -- y )
-    "double" "libm" "asinh" { "double" } alien-invoke ;
+    double "libm" "asinh" { double } alien-invoke ;
 
 : fatanh ( x -- y )
-    "double" "libm" "atanh" { "double" } alien-invoke ;
+    double "libm" "atanh" { double } alien-invoke ;
index cabb731fefbfba55d9a3dcb24efd733f0bbb6ed4..641585a5d71379f7966caf2bd7524f552cebd94a 100644 (file)
@@ -9,14 +9,16 @@ ERROR: bad-length got expected ;
 
 FUNCTOR: define-simd-128 ( T -- )
 
-N            [ 16 T heap-size /i ]
+T-TYPE       IS ${T}
+
+N            [ 16 T-TYPE heap-size /i ]
 
 A            DEFINES-CLASS ${T}-${N}
 >A           DEFINES >${A}
 A{           DEFINES ${A}{
 
-NTH          [ T dup c-type-getter-boxer array-accessor ]
-SET-NTH      [ T dup c-setter array-accessor ]
+NTH          [ T-TYPE dup c-type-getter-boxer array-accessor ]
+SET-NTH      [ T-TYPE dup c-setter array-accessor ]
 
 A-rep        IS ${A}-rep
 A-vv->v-op   DEFINES-PRIVATE ${A}-vv->v-op
@@ -74,7 +76,9 @@ PRIVATE>
 ! Synthesize 256-bit vectors from a pair of 128-bit vectors
 FUNCTOR: define-simd-256 ( T -- )
 
-N            [ 32 T heap-size /i ]
+T-TYPE       IS ${T}
+
+N            [ 32 T-TYPE heap-size /i ]
 
 N/2          [ N 2 / ]
 A/2          IS ${T}-${N/2}
index 28547f8cf90f502108777e3c8c37981102d3f154..914d1ef169f308f5eafd0bd4809ab3a6961fdd54 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel alien alien.c-types cpu.architecture libc ;
+USING: kernel alien alien.data cpu.architecture libc ;
 IN: math.vectors.simd.intrinsics
 
 ERROR: bad-simd-call ;
index 7df9b2d8d2fc312c7d6065e6da69b7dc360462ce..a3c99ae217bda587b6cf3b218b13fa71b0801ca1 100644 (file)
@@ -5,6 +5,8 @@ kernel math math.functions math.vectors
 math.vectors.simd.functor math.vectors.simd.intrinsics
 math.vectors.specialization parser prettyprint.custom sequences
 sequences.private locals assocs words fry ;
+FROM: alien.c-types => float ;
+QUALIFIED-WITH: math m
 IN: math.vectors.simd
 
 <<
@@ -15,9 +17,9 @@ DEFER: float-8
 DEFER: double-4
 
 "double" define-simd-128
-"float" define-simd-128
+"float"  define-simd-128
 "double" define-simd-256
-"float" define-simd-256
+"float"  define-simd-256
 
 >>
 
@@ -136,7 +138,7 @@ DEFER: double-4
 
 PRIVATE>
 
-\ float-4 \ float-4-with float H{
+\ float-4 \ float-4-with m:float H{
     { v+ [ [ (simd-v+) ] float-4-vv->v-op ] }
     { v- [ [ (simd-v-) ] float-4-vv->v-op ] }
     { v* [ [ (simd-v*) ] float-4-vv->v-op ] }
@@ -146,7 +148,7 @@ PRIVATE>
     { sum [ [ (simd-sum) ] float-4-v->n-op ] }
 } simd-vector-words
 
-\ double-2 \ double-2-with float H{
+\ double-2 \ double-2-with m:float H{
     { v+ [ [ (simd-v+) ] double-2-vv->v-op ] }
     { v- [ [ (simd-v-) ] double-2-vv->v-op ] }
     { v* [ [ (simd-v*) ] double-2-vv->v-op ] }
@@ -156,7 +158,7 @@ PRIVATE>
     { sum [ [ (simd-sum) ] double-2-v->n-op ] }
 } simd-vector-words
 
-\ float-8 \ float-8-with float H{
+\ float-8 \ float-8-with m:float H{
     { v+ [ [ (simd-v+) ] float-8-vv->v-op ] }
     { v- [ [ (simd-v-) ] float-8-vv->v-op ] }
     { v* [ [ (simd-v*) ] float-8-vv->v-op ] }
@@ -166,7 +168,7 @@ PRIVATE>
     { sum [ [ (simd-sum) ] [ + ] float-8-v->n-op ] }
 } simd-vector-words
 
-\ double-4 \ double-4-with float H{
+\ double-4 \ double-4-with m:float H{
     { v+ [ [ (simd-v+) ] double-4-vv->v-op ] }
     { v- [ [ (simd-v-) ] double-4-vv->v-op ] }
     { v* [ [ (simd-v*) ] double-4-vv->v-op ] }
index 75f327664d0c3bef944944a10ea0e780616347c5..cdf68cebd35720a2223ec0e23039587dbb672f22 100755 (executable)
@@ -8,6 +8,7 @@ math.parser opengl.gl combinators combinators.smart arrays
 sequences splitting words byte-arrays assocs vocabs
 colors colors.constants accessors generalizations locals fry
 specialized-arrays ;
+FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-ARRAY: uint
 IN: opengl
index 26ffd0cf88e25617a01780a1d78febee69069c26..562cbc91cec9ef23230a55c15418f499923aebcc 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel opengl.gl alien.c-types continuations namespaces
-assocs alien alien.strings libc opengl math sequences combinators
+assocs alien alien.data alien.strings libc opengl math sequences combinators
 macros arrays io.encodings.ascii fry specialized-arrays
 destructors accessors ;
 SPECIALIZED-ARRAY: uint
index 0eba1d28542657342b1de8fdfa1dacb7959e0735..df9955a53cdf7af181d7cbe90c6485f90cb3fa57 100644 (file)
@@ -5,8 +5,8 @@
 !
 ! export LD_LIBRARY_PATH=/opt/local/lib
 
-USING: alien alien.syntax combinators kernel system
-alien.libraries ;
+USING: alien alien.c-types alien.syntax combinators kernel system
+alien.libraries classes.struct ;
 
 IN: openssl.libcrypto
 
@@ -20,35 +20,35 @@ IN: openssl.libcrypto
 } cond
 >>
 
-C-STRUCT: bio-method
-    { "int" "type" }
-    { "void*" "name" }
-    { "void*" "bwrite" }
-    { "void*" "bread" }
-    { "void*" "bputs" }
-    { "void*" "bgets" }
-    { "void*" "ctrl" }
-    { "void*" "create" }
-    { "void*" "destroy" }
-    { "void*" "callback-ctrl" } ;
-
-C-STRUCT: bio
-    { "void*" "method" }
-    { "void*" "callback" }
-    { "void*" "cb-arg" }
-    { "int" "init" }
-    { "int" "shutdown" }
-    { "int" "flags" }
-    { "int" "retry-reason" }
-    { "int" "num" }
-    { "void*" "ptr" }
-    { "void*" "next-bio" }
-    { "void*" "prev-bio" }
-    { "int" "references" } 
-    { "ulong" "num-read" }
-    { "ulong" "num-write" } 
-    { "void*" "crypto-ex-data-stack" }
-    { "int" "crypto-ex-data-dummy" } ;
+STRUCT: bio-method
+    { type int }
+    { name void* }
+    { bwrite void* }
+    { bread void* }
+    { bputs void* }
+    { bgets void* }
+    { ctrl void* }
+    { create void* }
+    { destroy void* }
+    { callback-ctrl void* } ;
+
+STRUCT: bio
+    { method void* }
+    { callback void* }
+    { cb-arg void* }
+    { init int }
+    { shutdown int }
+    { flags int }
+    { retry-reason int }
+    { num int }
+    { ptr void* }
+    { next-bio void* }
+    { prev-bio void* }
+    { references int } 
+    { num-read ulong }
+    { num-write ulong } 
+    { crypto-ex-data-stack void* }
+    { crypto-ex-data-dummy int } ;
 
 CONSTANT: BIO_NOCLOSE       HEX: 00
 CONSTANT: BIO_CLOSE         HEX: 01
@@ -103,11 +103,11 @@ FUNCTION: void* BIO_f_buffer (  ) ;
 
 CONSTANT: EVP_MAX_MD_SIZE 64
 
-C-STRUCT: EVP_MD_CTX
-    { "EVP_MD*" "digest" }
-    { "ENGINE*" "engine" }
-    { "ulong" "flags" }
-    { "void*" "md_data" } ;
+STRUCT: EVP_MD_CTX
+    { digest EVP_MD* }
+    { engine ENGINE* }
+    { flags ulong }
+    { md_data void* } ;
 
 TYPEDEF: void* EVP_MD*
 TYPEDEF: void* ENGINE*
index 1dcb1b5617f788d71addd5ea6749da9c3df2262b..ccc63c61cbaa3a35d71384de603c397b6f8ba2e6 100644 (file)
@@ -19,6 +19,9 @@ HELP: length-limit
 HELP: line-limit
 { $var-description "The maximum number of lines output by the prettyprinter before output is truncated with \"...\". The default is " { $link f } ", denoting unlimited line count." } ;
 
+HELP: number-base
+{ $var-description "The number base in which the prettyprinter will output numeric literals. A value of " { $snippet "2" } " will print integers and ratios in binary with " { $link POSTPONE: BIN: } ", and " { $snippet "8" } " will print them in octal with " { $link POSTPONE: OCT: } ". A value of " { $snippet "16" } " will print all integers, ratios, and floating-point values in hexadecimal with " { $link POSTPONE: HEX: } ". Other values of " { $snippet "number-base" } " will print numbers in decimal, which is the default." } ;
+
 HELP: string-limit?
 { $var-description "Toggles whether printed strings are truncated to the margin." } ;
 
index 7c114f2e228cc1630f388589d5ff6cd583fec14e..1560b208ab0a8e1980b9bb5b79a3030aa5093afd 100644 (file)
@@ -28,6 +28,7 @@ ARTICLE: "prettyprint-variables" "Prettyprint control variables"
 { $subsection nesting-limit }
 { $subsection length-limit }
 { $subsection line-limit }
+{ $subsection number-base }
 { $subsection string-limit? }
 { $subsection boa-tuples? }
 { $subsection c-object-pointers? }
@@ -202,8 +203,8 @@ HELP: .o
 { $description "Outputs an integer in octal." } ;
 
 HELP: .h
-{ $values { "n" "an integer" } }
-{ $description "Outputs an integer in hexadecimal." } ;
+{ $values { "n" "an integer or floating-point value" } }
+{ $description "Outputs an integer or floating-point value in hexadecimal." } ;
 
 HELP: stack.
 { $values { "seq" "a sequence" } }
index 83b1fab0d0be092b3f21f32cf97e2aaf34348be9..d959b191c9993170f017167e9f031332992b3c16 100644 (file)
@@ -1,4 +1,4 @@
-USING: accessors alien.c-types byte-arrays
+USING: accessors alien.c-types alien.data byte-arrays
 combinators.short-circuit continuations destructors init kernel
 locals namespaces random windows.advapi32 windows.errors
 windows.kernel32 math.bitwise ;
index 2698149bac4c594f261a246353cc56e27e241f69..5d88f42d5021fc68b858e5ba4125191da08b1772 100755 (executable)
@@ -4,7 +4,8 @@ specialized-arrays.private sequences alien.c-types accessors
 kernel arrays combinators compiler compiler.units classes.struct
 combinators.smart compiler.tree.debugger math libc destructors
 sequences.private multiline eval words vocabs namespaces
-assocs prettyprint ;
+assocs prettyprint alien.data ;
+FROM: alien.c-types => float ;
 
 SPECIALIZED-ARRAY: int
 SPECIALIZED-ARRAY: bool
index 15245cc71016c7fe1d38abd771bc18e869648117..6931c83677fc0dd90af63033c46b20c478d8e7e0 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types assocs byte-arrays classes
-compiler.units functors kernel lexer libc math
+USING: accessors alien alien.c-types alien.data alien.parser assocs
+byte-arrays classes compiler.units functors kernel lexer libc math
 math.vectors.specialization namespaces parser prettyprint.custom
 sequences sequences.private strings summary vocabs vocabs.loader
 vocabs.parser words fry combinators ;
@@ -103,13 +103,21 @@ A T c-type-boxed-class f specialize-vector-words
 
 ;FUNCTOR
 
+GENERIC: (underlying-type) ( c-type -- c-type' )
+
+M: string (underlying-type) c-types get at ;
+M: word (underlying-type) "c-type" word-prop ;
+
 : underlying-type ( c-type -- c-type' )
-    dup c-types get at {
+    dup (underlying-type) {
         { [ dup not ] [ drop no-c-type ] }
-        { [ dup string? ] [ nip underlying-type ] }
+        { [ dup c-type-name? ] [ nip underlying-type ] }
         [ drop ]
     } cond ;
 
+: underlying-type-name ( c-type -- name )
+    underlying-type dup word? [ name>> ] when ;
+
 : specialized-array-vocab ( c-type -- vocab )
     "specialized-arrays.instances." prepend ;
 
@@ -125,31 +133,31 @@ PRIVATE>
     ] ?if ; inline
 
 : define-array-vocab ( type -- vocab )
-    underlying-type
+    underlying-type-name
     [ specialized-array-vocab ] [ '[ _ define-array ] ] bi
     generate-vocab ;
 
-M: string require-c-array define-array-vocab drop ;
+M: c-type-name require-c-array define-array-vocab drop ;
 
 ERROR: specialized-array-vocab-not-loaded c-type ;
 
-M: string c-array-constructor
-    underlying-type
+M: c-type-name c-array-constructor
+    underlying-type-name
     dup [ "<" "-array>" surround ] [ specialized-array-vocab ] bi lookup
     [ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
 
-M: string c-(array)-constructor
-    underlying-type
+M: c-type-name c-(array)-constructor
+    underlying-type-name
     dup [ "(" "-array)" surround ] [ specialized-array-vocab ] bi lookup
     [ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
 
-M: string c-direct-array-constructor
-    underlying-type
+M: c-type-name c-direct-array-constructor
+    underlying-type-name
     dup [ "<direct-" "-array>" surround ] [ specialized-array-vocab ] bi lookup
     [ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
 
 SYNTAX: SPECIALIZED-ARRAY:
-    scan define-array-vocab use-vocab ;
+    scan-c-type define-array-vocab use-vocab ;
 
 "prettyprint" vocab [
     "specialized-arrays.prettyprint" require
index da559abd7808178af73967cb849ab6556287be1d..3d150adf9117774057ca51f84080c9a971de5dd0 100644 (file)
@@ -19,7 +19,7 @@ TUPLE: alien-callback-params < alien-node-params quot xt ;
 
 : alien-stack ( params extra -- )
     over parameters>> length + consume-d >>in-d
-    dup return>> "void" = 0 1 ? produce-d >>out-d
+    dup return>> void? 0 1 ? produce-d >>out-d
     drop ;
 
 : return-prep-quot ( node -- quot )
index 6a67b815cdeb1cdd37d59fc8fbdc98e23a0fb9a0..e451c53c71e6883fbef791b7276f14d048d670db 100755 (executable)
@@ -1,14 +1,43 @@
 USING: help.markup help.syntax kernel effects sequences
-sequences.private words ;
+sequences.private words combinators ;
 IN: stack-checker.errors
 
+HELP: do-not-compile
+{ $error-description "Thrown when inference encounters a macro being applied to a value which is not known to be a literal. Such code needs changes before it can compile and run. See " { $link "inference-combinators" } " and " { $link "inference-escape" } " for details." }
+{ $examples
+    "In this example, " { $link cleave } " is being applied to an array that is constructed on the fly. This is not allowed and fails to compile with a " { $link do-not-compile } " error:"
+    { $code
+        ": cannot-compile-call-example ( x -- y z )"
+        "    [ 1 + ] [ 1 - ] 2array cleave ;"
+    }
+} ;
+
 HELP: literal-expected
 { $error-description "Thrown when inference encounters a combinator or macro being applied to a value which is not known to be a literal, or constructed in a manner which can be analyzed statically. Such code needs changes before it can compile and run. See " { $link "inference-combinators" } " and " { $link "inference-escape" } " for details." }
 { $examples
-    "In this example, words calling " { $snippet "literal-expected-example" } " will have a static stac keffect, even if " { $snippet "literal-expected-example" } " does not:"
+    "In this example, the words being defined cannot be called, because they fail to compile with a " { $link literal-expected } " error:"
     { $code
-        ": literal-expected-example ( quot -- )"
+        ": bad-example ( quot -- )"
+        "    [ call ] [ call ] bi ;"
+        ""
+        ": usage ( -- )"
+        "    10 [ 2 * ] bad-example . ;"
+    }
+    "One fix is to declare the combinator as inline:"
+    { $code
+        ": good-example ( quot -- )"
         "    [ call ] [ call ] bi ; inline"
+        ""
+        ": usage ( -- )"
+        "    10 [ 2 * ] good-example . ;"
+    }
+    "Another fix is to use " { $link POSTPONE: call( } ":"
+    { $code
+        ": good-example ( quot -- )"
+        "    [ call( x -- y ) ] [ call( x -- y ) ] bi ;"
+        ""
+        ": usage ( -- )"
+        "    10 [ 2 * ] good-example . ;"
     }
 } ;
 
@@ -89,7 +118,8 @@ ARTICLE: "inference-errors" "Stack checker errors"
     { { $link "tools.inference" } " throws them as errors" }
     { "The " { $link "compiler" } " reports them via " { $link "tools.errors" } }
 }
-"Error thrown when insufficient information is available to calculate the stack effect of a combinator call (see " { $link "inference-combinators" } "):"
+"Errors thrown when insufficient information is available to calculate the stack effect of a call to a combinator or macro (see " { $link "inference-combinators" } "):"
+{ $subsection do-not-compile }
 { $subsection literal-expected }
 "Error thrown when a word's stack effect declaration does not match the composition of the stack effects of its factors:"
 { $subsection effect-error }
index bd612c644a9a59f3e46447fb18d20a76f7d782c5..12016168fb23200e7c365db455f179b1a9d26dbb 100644 (file)
@@ -1,4 +1,4 @@
-USING: help.markup help.syntax words alien.c-types assocs
+USING: help.markup help.syntax words alien.c-types alien.data assocs
 kernel math ;
 IN: tools.deploy.config
 
index 0a8ab0b1169b47e8c6f87988fb1b5962f1525c34..16408c0eb8b9f43e99dff60fccee5e1bf3049c9c 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types arrays byte-arrays combinators
 destructors generic io kernel libc math sequences system tr
-vocabs.loader words ;
+vocabs.loader words alien.data ;
 IN: tools.disassembler
 
 GENERIC: disassemble ( obj -- )
index 2f0456ab623d61e40e371d5b68227e09c57e00a0..89bd5f726c970484538e4beb1d0fb7d96cc59317 100755 (executable)
@@ -4,7 +4,8 @@ USING: tools.disassembler namespaces combinators
 alien alien.syntax alien.c-types lexer parser kernel
 sequences layouts math math.order alien.libraries
 math.parser system make fry arrays libc destructors
-tools.disassembler.utils splitting ;
+tools.disassembler.utils splitting alien.data
+classes.struct ;
 IN: tools.disassembler.udis
 
 <<
@@ -17,57 +18,57 @@ IN: tools.disassembler.udis
 
 LIBRARY: libudis86
 
-C-STRUCT: ud_operand
-    { "int" "type" }
-    { "uchar" "size" }
-    { "ulonglong" "lval" }
-    { "int" "base" }
-    { "int" "index" }
-    { "uchar" "offset" }
-    { "uchar" "scale" } ;
-
-C-STRUCT: ud
-    { "void*" "inp_hook" }
-    { "uchar" "inp_curr" }
-    { "uchar" "inp_fill" }
-    { "FILE*" "inp_file" }
-    { "uchar" "inp_ctr" }
-    { "uchar*" "inp_buff" }
-    { "uchar*" "inp_buff_end" }
-    { "uchar" "inp_end" }
-    { "void*" "translator" }
-    { "ulonglong" "insn_offset" }
-    { "char[32]" "insn_hexcode" }
-    { "char[64]" "insn_buffer" }
-    { "uint" "insn_fill" }
-    { "uchar" "dis_mode" }
-    { "ulonglong" "pc" }
-    { "uchar" "vendor" }
-    { "struct map_entry*" "mapen" }
-    { "int" "mnemonic" }
-    { "ud_operand[3]" "operand" }
-    { "uchar" "error" }
-    { "uchar" "pfx_rex" }
-    { "uchar" "pfx_seg" }
-    { "uchar" "pfx_opr" }
-    { "uchar" "pfx_adr" }
-    { "uchar" "pfx_lock" }
-    { "uchar" "pfx_rep" }
-    { "uchar" "pfx_repe" }
-    { "uchar" "pfx_repne" }
-    { "uchar" "pfx_insn" }
-    { "uchar" "default64" }
-    { "uchar" "opr_mode" }
-    { "uchar" "adr_mode" }
-    { "uchar" "br_far" }
-    { "uchar" "br_near" }
-    { "uchar" "implicit_addr" }
-    { "uchar" "c1" }
-    { "uchar" "c2" }
-    { "uchar" "c3" }
-    { "uchar[256]" "inp_cache" }
-    { "uchar[64]" "inp_sess" }
-    { "ud_itab_entry*" "itab_entry" } ;
+STRUCT: ud_operand
+    { type int }
+    { size uchar }
+    { lval ulonglong }
+    { base int }
+    { index int }
+    { offset uchar }
+    { scale uchar } ;
+
+STRUCT: ud
+    { inp_hook void* }
+    { inp_curr uchar }
+    { inp_fill uchar }
+    { inp_file FILE* }
+    { inp_ctr uchar }
+    { inp_buff uchar* }
+    { inp_buff_end uchar* }
+    { inp_end uchar }
+    { translator void* }
+    { insn_offset ulonglong }
+    { insn_hexcode char[32] }
+    { insn_buffer char[64] }
+    { insn_fill uint }
+    { dis_mode uchar }
+    { pc ulonglong }
+    { vendor uchar }
+    { mapen void* }
+    { mnemonic int }
+    { operand ud_operand[3] }
+    { error uchar }
+    { pfx_rex uchar }
+    { pfx_seg uchar }
+    { pfx_opr uchar }
+    { pfx_adr uchar }
+    { pfx_lock uchar }
+    { pfx_rep uchar }
+    { pfx_repe uchar }
+    { pfx_repne uchar }
+    { pfx_insn uchar }
+    { default64 uchar }
+    { opr_mode uchar }
+    { adr_mode uchar }
+    { br_far uchar }
+    { br_near uchar }
+    { implicit_addr uchar }
+    { c1 uchar }
+    { c2 uchar }
+    { c3 uchar }
+    { inp_cache uchar[256] }
+    { inp_sess uchar[64] }
+    { itab_entry ud_itab_entry* } ;
 
 FUNCTION: void ud_translate_intel ( ud* u ) ;
 FUNCTION: void ud_translate_att ( ud* u ) ;
@@ -98,7 +99,7 @@ FUNCTION: uint ud_insn_len ( ud* u ) ;
 FUNCTION: char* ud_lookup_mnemonic ( int c ) ;
 
 : <ud> ( -- ud )
-    "ud" malloc-object &free
+    ud malloc-struct &free
     dup ud_init
     dup cell-bits ud_set_mode
     dup UD_SYN_INTEL ud_set_syntax ;
index 6ae56af030c6014b469b9d0d63e765ffcfe7accf..a49d22735d08741d2ed45df95ee19160a43b5647 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2006, 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.strings arrays assocs
-cocoa kernel math cocoa.messages cocoa.subclassing cocoa.classes
-cocoa.views cocoa.application cocoa.pasteboard cocoa.types
-cocoa.windows sequences io.encodings.utf8 ui ui.private ui.gadgets
-ui.gadgets.private ui.gadgets.worlds ui.gestures
+USING: accessors alien alien.c-types alien.data alien.strings
+arrays assocs cocoa kernel math cocoa.messages cocoa.subclassing
+cocoa.classes cocoa.views cocoa.application cocoa.pasteboard
+cocoa.types cocoa.windows sequences io.encodings.utf8 ui ui.private
+ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures
 core-foundation.strings core-graphics core-graphics.types threads
 combinators math.rectangles ;
 IN: ui.backend.cocoa.views
index 2be6e70df8d4be613c020778f927a39c6696882c..1e01f889dc3cbc76fb0bc81a93e032dfdb3e97d5 100755 (executable)
@@ -13,7 +13,7 @@ opengl ui.render math.bitwise locals accessors math.rectangles
 math.order calendar ascii sets io.encodings.utf16n
 windows.errors literals ui.pixel-formats
 ui.pixel-formats.private memoize classes
-specialized-arrays classes.struct ;
+specialized-arrays classes.struct alien.data ;
 SPECIALIZED-ARRAY: POINT
 IN: ui.backend.windows
 
@@ -653,7 +653,7 @@ M: windows-ui-backend do-events
 
 : init-win32-ui ( -- )
     V{ } clone nc-buttons set-global
-    "MSG" malloc-object msg-obj set-global
+    MSG malloc-struct msg-obj set-global
     GetDoubleClickTime milliseconds double-click-timeout set-global ;
 
 : cleanup-win32-ui ( -- )
index 26cbafc0d54277dec2103699a5d780b14b6fcdfe..fb6f8153e962f6d6a8031986ee203e7ae350eba9 100644 (file)
@@ -119,7 +119,7 @@ PRIVATE>
         [ append theme-image ] tri-curry@ tri
     ] 2dip <tile-pen> ;
 
-CONSTANT: button-background COLOR: FactorLightTan
+CONSTANT: button-background COLOR: FactorTan
 CONSTANT: button-clicked-background COLOR: FactorDarkSlateBlue
 
 : <border-button-pen> ( -- pen )
index 5edd1a5093f6887604c9baa9298a15f32516059b..c263be7056f7bcbe649bbbca28df236f576652d4 100644 (file)
@@ -1,4 +1,5 @@
-USING: alien.syntax unix.time classes.struct ;
+USING: alien.c-types alien.syntax unix.time unix.types
+unix.types.macosx classes.struct ;
 IN: unix
 
 CONSTANT: FD_SETSIZE 1024
@@ -18,15 +19,15 @@ CONSTANT: _UTX_LINESIZE 32
 CONSTANT: _UTX_IDSIZE 4
 CONSTANT: _UTX_HOSTSIZE 256
     
-C-STRUCT: utmpx
-    { { "char" _UTX_USERSIZE } "ut_user" }
-    { { "char" _UTX_IDSIZE } "ut_id" }
-    { { "char" _UTX_LINESIZE } "ut_line" }
-    { "pid_t" "ut_pid" }
-    { "short" "ut_type" }
-    { "timeval" "ut_tv" }
-    { { "char" _UTX_HOSTSIZE } "ut_host" }
-    { { "uint" 16 } "ut_pad" } ;
+STRUCT: utmpx
+    { ut_user { char _UTX_USERSIZE } }
+    { ut_id   { char _UTX_IDSIZE   } }
+    { ut_line { char _UTX_LINESIZE } }
+    { ut_pid  pid_t }
+    { ut_type short }
+    { ut_tv   timeval }
+    { ut_host { char _UTX_HOSTSIZE } }
+    { ut_pad  { uint 16 } } ;
 
 CONSTANT: __DARWIN_MAXPATHLEN 1024
 CONSTANT: __DARWIN_MAXNAMELEN 255
@@ -37,7 +38,7 @@ STRUCT: dirent
     { d_reclen __uint16_t }
     { d_type __uint8_t }
     { d_namlen __uint8_t }
-    { d_name { "char" __DARWIN_MAXNAMELEN+1 } } ;
+    { d_name { char __DARWIN_MAXNAMELEN+1 } } ;
 
 CONSTANT: EPERM 1
 CONSTANT: ENOENT 2
index f8aee1635d3db8e1bc676bea7df58494f2a372b8..1882fa830b7c2f9bae6cd001158c56c0860ce2e0 100644 (file)
@@ -1,29 +1,30 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax unix.time classes.struct ;
+USING: alien.c-types alien.syntax unix.time unix.types
+unix.types.netbsd classes.struct ;
 IN: unix
 
 STRUCT: sockaddr_storage
     { ss_len __uint8_t }
     { ss_family sa_family_t }
-    { __ss_pad1 { "char" _SS_PAD1SIZE } }
+    { __ss_pad1 { char _SS_PAD1SIZE } }
     { __ss_align __int64_t }
-    { __ss_pad2 { "char" _SS_PAD2SIZE } } ;
+    { __ss_pad2 { char _SS_PAD2SIZE } } ;
 
 STRUCT: exit_struct
     { e_termination uint16_t }
     { e_exit uint16_t } ;
 
-C-STRUCT: utmpx
-    { { "char" _UTX_USERSIZE } "ut_user" }
-    { { "char" _UTX_IDSIZE } "ut_id" }
-    { { "char" _UTX_LINESIZE } "ut_line" }
-    { { "char" _UTX_HOSTSIZE } "ut_host" }
-    { "uint16_t" "ut_session" }
-    { "uint16_t" "ut_type" }
-    { "pid_t" "ut_pid" }
-    { "exit_struct" "ut_exit" }
-    { "sockaddr_storage" "ut_ss" }
-    { "timeval" "ut_tv" }
-    { { "uint32_t" 10 } "ut_pad" } ;
+STRUCT: utmpx
+    { ut_user { char _UTX_USERSIZE } }
+    { ut_id   { char _UTX_IDSIZE   } }
+    { ut_line { char _UTX_LINESIZE } }
+    { ut_host { char _UTX_HOSTSIZE } }
+    { ut_session uint16_t }
+    { ut_type uint16_t }
+    { ut_pid pid_t }
+    { ut_exit exit_struct }
+    { ut_ss sockaddr_storage }
+    { ut_tv timeval }
+    { ut_pad { uint32_t 10 } } ;
 
index 131d8dda5dc681488a36296ed79400f63dcd6009..2912f8b744326aeac16f909ecb738acd036b4bab 100644 (file)
@@ -1,6 +1,6 @@
-USING: kernel alien.c-types alien.strings sequences math alien.syntax
-unix namespaces continuations threads assocs io.backend.unix
-io.encodings.utf8 unix.utilities fry ;
+USING: kernel alien.c-types alien.data alien.strings sequences
+math alien.syntax unix namespaces continuations threads assocs
+io.backend.unix io.encodings.utf8 unix.utilities fry ;
 IN: unix.process
 
 ! Low-level Unix process launching utilities. These are used
index 8d141ccb247d61b0a736cb335bd736d707f7b949..919b2ae8a2eabafebba8722633dbb30dbc8d1b63 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings
+USING: alien alien.c-types alien.data alien.strings
 combinators.short-circuit fry kernel layouts sequences accessors
 specialized-arrays ;
 IN: unix.utilities
index 6e72f7d1147ef2a1dcb4cf22c6f04a167fb00bd8..6083776fc60059fc1b5ae93b1fc27c6f2b6094ac 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.syntax combinators continuations
-io.encodings.string io.encodings.utf8 kernel sequences strings
-unix calendar system accessors unix.time calendar.unix
-vocabs.loader ;
+USING: alien.c-types alien.data alien.syntax combinators
+continuations io.encodings.string io.encodings.utf8 kernel
+sequences strings unix calendar system accessors unix.time
+calendar.unix vocabs.loader classes.struct ;
 IN: unix.utmpx
 
 CONSTANT: EMPTY 0
@@ -39,15 +39,15 @@ M: unix new-utmpx-record
     utmpx-record new ;
     
 M: unix utmpx>utmpx-record ( utmpx -- utmpx-record )
-    [ new-utmpx-record ] dip
+    [ new-utmpx-record ] dip \ utmpx memory>struct
     {
-        [ utmpx-ut_user _UTX_USERSIZE memory>string >>user ]
-        [ utmpx-ut_id _UTX_IDSIZE memory>string >>id ]
-        [ utmpx-ut_line _UTX_LINESIZE memory>string >>line ]
-        [ utmpx-ut_pid >>pid ]
-        [ utmpx-ut_type >>type ]
-        [ utmpx-ut_tv timeval>unix-time >>timestamp ]
-        [ utmpx-ut_host _UTX_HOSTSIZE memory>string >>host ]
+        [ ut_user>> _UTX_USERSIZE memory>string >>user ]
+        [ ut_id>>   _UTX_IDSIZE memory>string >>id ]
+        [ ut_line>> _UTX_LINESIZE memory>string >>line ]
+        [ ut_pid>>  >>pid ]
+        [ ut_type>> >>type ]
+        [ ut_tv>>   timeval>unix-time >>timestamp ]
+        [ ut_host>> _UTX_HOSTSIZE memory>string >>host ]
     } cleave ;
 
 : with-utmpx ( quot -- )
index 6d80534e8ca7c085a9cf24fa4d0bf4417e2d611a..21f048a00f43bcba99f7dc66c5cdff6f204a3fe9 100755 (executable)
@@ -1,5 +1,5 @@
 USING: alien.syntax kernel math windows.types windows.kernel32
-math.bitwise ;
+math.bitwise classes.struct ;
 IN: windows.advapi32
 
 LIBRARY: advapi32
@@ -62,12 +62,12 @@ CONSTANT: CRYPT_DELETEKEYSET   HEX: 10
 CONSTANT: CRYPT_MACHINE_KEYSET HEX: 20
 CONSTANT: CRYPT_SILENT         HEX: 40
 
-C-STRUCT: ACL
-    { "BYTE" "AclRevision" }
-    { "BYTE" "Sbz1" }
-    { "WORD" "AclSize" }
-    { "WORD" "AceCount" }
-    { "WORD" "Sbz2" } ;
+STRUCT: ACL
+    { AclRevision BYTE }
+    { Sbz1 BYTE }
+    { AclSize WORD }
+    { AceCount WORD }
+    { Sbz2 WORD } ;
 
 TYPEDEF: ACL* PACL
 
@@ -82,56 +82,56 @@ CONSTANT: NO_PROPAGATE_INHERIT_ACE HEX: 4
 CONSTANT: INHERIT_ONLY_ACE HEX: 8
 CONSTANT: VALID_INHERIT_FLAGS HEX: f
 
-C-STRUCT: ACE_HEADER
-    { "BYTE" "AceType" }
-    { "BYTE" "AceFlags" }
-    { "WORD" "AceSize" } ;
+STRUCT: ACE_HEADER
+    { AceType BYTE }
+    { AceFlags BYTE }
+    { AceSize WORD } ;
 
 TYPEDEF: ACE_HEADER* PACE_HEADER
 
-C-STRUCT: ACCESS_ALLOWED_ACE
-    { "ACE_HEADER" "Header" }
-    { "DWORD" "Mask" }
-    { "DWORD" "SidStart" } ;
+STRUCT: ACCESS_ALLOWED_ACE
+    { Header ACE_HEADER }
+    { Mask DWORD }
+    { SidStart DWORD } ;
 
 TYPEDEF: ACCESS_ALLOWED_ACE* PACCESS_ALLOWED_ACE
 
-C-STRUCT: ACCESS_DENIED_ACE
-    { "ACE_HEADER" "Header" }
-    { "DWORD" "Mask" }
-    { "DWORD" "SidStart" } ;
+STRUCT: ACCESS_DENIED_ACE
+    { Header ACE_HEADER }
+    { Mask DWORD }
+    { SidStart DWORD } ;
 TYPEDEF: ACCESS_DENIED_ACE* PACCESS_DENIED_ACE
 
 
-C-STRUCT: SYSTEM_AUDIT_ACE
-    { "ACE_HEADER" "Header" }
-    { "DWORD" "Mask" }
-    { "DWORD" "SidStart" } ;
+STRUCT: SYSTEM_AUDIT_ACE
+    { Header ACE_HEADER }
+    { Mask DWORD }
+    { SidStart DWORD } ;
 
 TYPEDEF: SYSTEM_AUDIT_ACE* PSYSTEM_AUDIT_ACE
 
-C-STRUCT: SYSTEM_ALARM_ACE
-    { "ACE_HEADER" "Header" }
-    { "DWORD" "Mask" }
-    { "DWORD" "SidStart" } ;
+STRUCT: SYSTEM_ALARM_ACE
+    { Header ACE_HEADER }
+    { Mask DWORD }
+    { SidStart DWORD } ;
 
 TYPEDEF: SYSTEM_ALARM_ACE* PSYSTEM_ALARM_ACE
 
-C-STRUCT: ACCESS_ALLOWED_CALLBACK_ACE
-    { "ACE_HEADER" "Header" }
-    { "DWORD" "Mask" }
-    { "DWORD" "SidStart" } ;
+STRUCT: ACCESS_ALLOWED_CALLBACK_ACE
+    { Header ACE_HEADER }
+    { Mask DWORD }
+    { SidStart DWORD } ;
 
 TYPEDEF: ACCESS_ALLOWED_CALLBACK_ACE* PACCESS_ALLOWED_CALLBACK_ACE
 
-C-STRUCT: SECURITY_DESCRIPTOR
-    { "UCHAR" "Revision" }
-    { "UCHAR" "Sbz1" }
-    { "WORD" "Control" }
-    { "PVOID" "Owner" }
-    { "PVOID" "Group" }
-    { "PACL" "Sacl" }
-    { "PACL" "Dacl" } ;
+STRUCT: SECURITY_DESCRIPTOR
+    { Revision UCHAR }
+    { Sbz1 UCHAR }
+    { Control WORD }
+    { Owner PVOID }
+    { Group PVOID }
+    { Sacl PACL }
+    { Dacl PACL } ;
 
 TYPEDEF: SECURITY_DESCRIPTOR* PSECURITY_DESCRIPTOR
 
@@ -224,21 +224,21 @@ C-ENUM:
 
 TYPEDEF: TRUSTEE* PTRUSTEE
 
-C-STRUCT: TRUSTEE
-    { "PTRUSTEE" "pMultipleTrustee" }
-    { "MULTIPLE_TRUSTEE_OPERATION" "MultipleTrusteeOperation" }
-    { "TRUSTEE_FORM" "TrusteeForm" }
-    { "TRUSTEE_TYPE" "TrusteeType" }
-    { "LPTSTR" "ptstrName" } ;
-
-C-STRUCT: EXPLICIT_ACCESS
-    { "DWORD" "grfAccessPermissions" }
-    { "ACCESS_MODE" "grfAccessMode" }
-    { "DWORD" "grfInheritance" }
-    { "TRUSTEE" "Trustee" } ;
-
-C-STRUCT: SID_IDENTIFIER_AUTHORITY
-    { { "BYTE" 6 } "Value" } ;
+STRUCT: TRUSTEE
+    { pMultipleTrustee PTRUSTEE }
+    { MultipleTrusteeOperation MULTIPLE_TRUSTEE_OPERATION }
+    { TrusteeForm TRUSTEE_FORM }
+    { TrusteeType TRUSTEE_TYPE }
+    { ptstrName LPTSTR } ;
+
+STRUCT: EXPLICIT_ACCESS
+    { grfAccessPermissions DWORD }
+    { grfAccessMode ACCESS_MODE }
+    { grfInheritance DWORD }
+    { Trustee TRUSTEE } ;
+
+STRUCT: SID_IDENTIFIER_AUTHORITY
+    { Value { BYTE 6 } } ;
 
 TYPEDEF: SID_IDENTIFIER_AUTHORITY* PSID_IDENTIFIER_AUTHORITY
 
index d485692a910fbef397b53e4c872661973280066c..e06f5b60719e390ed93beea1fc844a524b8f6bc4 100644 (file)
@@ -1,6 +1,6 @@
 USING: alien alien.c-types alien.destructors windows.com.syntax\r
 windows.ole32 windows.types continuations kernel alien.syntax\r
-libc destructors accessors ;\r
+libc destructors accessors alien.data ;\r
 IN: windows.com\r
 \r
 LIBRARY: ole32\r
index 2100d6a2156f420d6abe3f044c8abc2b48401775..3cf8b55e39e270e0825b3ecd49ea1014a4d2a639 100755 (executable)
@@ -67,7 +67,7 @@ unless
 : (stack-effect-from-return-and-parameters) ( return parameters -- stack-effect )
     swap
     [ [ second ] map ]
-    [ dup "void" = [ drop { } ] [ 1array ] if ] bi*
+    [ dup void? [ drop { } ] [ 1array ] if ] bi*
     <effect> ;
 
 : (define-word-for-function) ( function interface n -- )
index e69fc5b820e0d391d21764b14c8a1387ce1125b4..e4f0ef0654b0730f5574c2086e0613ec477da231 100755 (executable)
@@ -1,9 +1,9 @@
-USING: alien alien.c-types alien.accessors windows.com.syntax
-init windows.com.syntax.private windows.com continuations kernel
-namespaces windows.ole32 libc vocabs assocs accessors arrays
-sequences quotations combinators math words compiler.units
-destructors fry math.parser generalizations sets
-specialized-arrays windows.kernel32 classes.struct ;
+USING: alien alien.c-types alien.data alien.accessors
+windows.com.syntax init windows.com.syntax.private windows.com
+continuations kernel namespaces windows.ole32 libc vocabs
+assocs accessors arrays sequences quotations combinators math
+words compiler.units destructors fry math.parser generalizations
+sets specialized-arrays windows.kernel32 classes.struct ;
 SPECIALIZED-ARRAY: void*
 IN: windows.com.wrapper
 
index b67b5fa08f18096c6c34837cba37afc36b9abea9..3c0509c49d1a8c4a606fbdea48dd9720ff75bfa7 100755 (executable)
@@ -1,8 +1,9 @@
 USING: windows.dinput windows.kernel32 windows.ole32 windows.com
-windows.com.syntax alien alien.c-types alien.syntax kernel system namespaces
-combinators sequences fry math accessors macros words quotations
-libc continuations generalizations splitting locals assocs init
-specialized-arrays memoize classes.struct ;
+windows.com.syntax alien alien.c-types alien.data alien.syntax
+kernel system namespaces combinators sequences fry math accessors
+macros words quotations libc continuations generalizations
+splitting locals assocs init specialized-arrays memoize
+classes.struct strings arrays ;
 SPECIALIZED-ARRAY: DIOBJECTDATAFORMAT
 IN: windows.dinput.constants
 
@@ -22,12 +23,17 @@ SYMBOLS:
 MEMO: c-type* ( name -- c-type ) c-type ;
 MEMO: heap-size* ( c-type -- n ) heap-size ;
 
+GENERIC: array-base-type ( c-type -- c-type' )
+M: object array-base-type ;
+M: string array-base-type "[" split1 drop ;
+M: array array-base-type first ;
+
 : (field-spec-of) ( field struct -- field-spec )
     c-type* fields>> [ name>> = ] with find nip ;
 : (offsetof) ( field struct -- offset )
     [ (field-spec-of) offset>> ] [ drop 0 ] if* ;
 : (sizeof) ( field struct -- size )
-    [ (field-spec-of) type>> "[" split1 drop heap-size* ] [ drop 1 ] if* ;
+    [ (field-spec-of) type>> array-base-type heap-size* ] [ drop 1 ] if* ;
 
 : (flag) ( thing -- integer )
     {
index bd6512341f5bf839322479024baa909d8c71c061..3ed2256c7d911a2fe1664fb1717f726017b8f880 100755 (executable)
@@ -1,31 +1,30 @@
 USING: alien.strings io.encodings.utf16n windows.com\r
 windows.com.wrapper combinators windows.kernel32 windows.ole32\r
-windows.shell32 kernel accessors\r
+windows.shell32 kernel accessors windows.types\r
 prettyprint namespaces ui.tools.listener ui.tools.workspace\r
-alien.c-types alien sequences math ;\r
+alien.data alien sequences math classes.struct ;\r
+SPECIALIZED-ARRAY: WCHAR\r
 IN: windows.dragdrop-listener\r
 \r
-<< "WCHAR" require-c-array >>\r
-\r
 : filenames-from-hdrop ( hdrop -- filenames )\r
     dup HEX: FFFFFFFF f 0 DragQueryFile ! get count of files\r
     [\r
         2dup f 0 DragQueryFile 1 + ! get size of filename buffer\r
-        dup "WCHAR" <c-array>\r
+        dup WCHAR <c-array>\r
         [ swap DragQueryFile drop ] keep\r
         utf16n alien>string\r
     ] with map ;\r
 \r
 : filenames-from-data-object ( data-object -- filenames )\r
-    "FORMATETC" <c-object>\r
-        CF_HDROP         over set-FORMATETC-cfFormat\r
-        f                over set-FORMATETC-ptd\r
-        DVASPECT_CONTENT over set-FORMATETC-dwAspect\r
-        -1               over set-FORMATETC-lindex\r
-        TYMED_HGLOBAL    over set-FORMATETC-tymed\r
-    "STGMEDIUM" <c-object>\r
+    FORMATETC <struct>\r
+        CF_HDROP         >>cfFormat\r
+        f                >>ptd\r
+        DVASPECT_CONTENT >>dwAspect\r
+        -1               >>lindex\r
+        TYMED_HGLOBAL    >>tymed\r
+    STGMEDIUM <struct>\r
     [ IDataObject::GetData ] keep swap succeeded? [\r
-        dup STGMEDIUM-data\r
+        dup data>>\r
         [ filenames-from-hdrop ] with-global-lock\r
         swap ReleaseStgMedium\r
     ] [ drop f ] if ;\r
index d2ee337726a5abb330b46721ec4b149fecfc7172..a7a41433f7dcb15aa90f8b8515e5b7c0e05dd0dc 100755 (executable)
@@ -1,11 +1,10 @@
-USING: alien.c-types kernel locals math math.bitwise
+USING: alien.data kernel locals math math.bitwise
 windows.kernel32 sequences byte-arrays unicode.categories
 io.encodings.string io.encodings.utf16n alien.strings
-arrays literals ;
+arrays literals windows.types specialized-arrays ;
+SPECIALIZED-ARRAY: TCHAR
 IN: windows.errors
 
-<< "TCHAR" require-c-array >>
-
 CONSTANT: ERROR_SUCCESS                               0
 CONSTANT: ERROR_INVALID_FUNCTION                      1
 CONSTANT: ERROR_FILE_NOT_FOUND                        2
@@ -698,8 +697,6 @@ CONSTANT: FORMAT_MESSAGE_MAX_WIDTH_MASK   HEX: 000000FF
 : make-lang-id ( lang1 lang2 -- n )
     10 shift bitor ; inline
 
-<< "TCHAR" require-c-array >>
-
 ERROR: error-message-failed id ;
 :: n>win32-error-string ( id -- string )
     {
@@ -709,7 +706,7 @@ ERROR: error-message-failed id ;
     f
     id
     LANG_NEUTRAL SUBLANG_DEFAULT make-lang-id
-    32768 [ "TCHAR" <c-array> ] [ ] bi
+    32768 [ TCHAR <c-array> ] [ ] bi
     f pick [ FormatMessage 0 = [ id error-message-failed ] when ] dip
     utf16n alien>string [ blank? ] trim ;
 
index 2cba1173d585f07085c3d75233b1856ee954d23e..075b0218b3e4cde1c2bf2762edff8a1c193316d0 100755 (executable)
@@ -317,14 +317,14 @@ STRUCT: OSVERSIONINFO
 
 TYPEDEF: void* LPOSVERSIONINFO
 
-C-STRUCT: MEMORY_BASIC_INFORMATION
-  { "void*" "BaseAddress" }
-  { "void*" "AllocationBase" }
-  { "DWORD" "AllocationProtect" }
-  { "SIZE_T" "RegionSize" }
-  { "DWORD" "state" }
-  { "DWORD" "protect" }
-  { "DWORD" "type" } ;
+STRUCT: MEMORY_BASIC_INFORMATION
+  { BaseAddress void* }
+  { AllocationBase void* }
+  { AllocationProtect DWORD }
+  { RegionSize SIZE_T }
+  { state DWORD }
+  { protect DWORD }
+  { type DWORD } ;
 
 STRUCT: GUID
     { Data1 ULONG }
@@ -524,55 +524,55 @@ CONSTANT: EV_RX80FULL     HEX: 400
 CONSTANT: EV_EVENT1       HEX: 800
 CONSTANT: EV_EVENT2       HEX: 1000
 
-C-STRUCT: DCB
-    { "DWORD" "DCBlength" }
-    { "DWORD" "BaudRate" }
-    { "DWORD" "flags" }
-    { "WORD"  "wReserved" }
-    { "WORD"  "XonLim" }
-    { "WORD"  "XoffLim" }
-    { "BYTE"  "ByteSize" }
-    { "BYTE"  "Parity" }
-    { "BYTE"  "StopBits" }
-    { "char"  "XonChar" }
-    { "char"  "XoffChar" }
-    { "char"  "ErrorChar" }
-    { "char"  "EofChar" }
-    { "char"  "EvtChar" }
-    { "WORD"  "wReserved1" } ;
+STRUCT: DCB
+    { DCBlength DWORD }
+    { BaudRate DWORD }
+    { flags DWORD }
+    { wReserved WORD  }
+    { XonLim WORD  }
+    { XoffLim WORD  }
+    { ByteSize BYTE  }
+    { Parity BYTE  }
+    { StopBits BYTE  }
+    { XonChar char  }
+    { XoffChar char  }
+    { ErrorChar char  }
+    { EofChar char  }
+    { EvtChar char  }
+    { wReserved1 WORD  } ;
 TYPEDEF: DCB* PDCB
 TYPEDEF: DCB* LPDCB
 
-C-STRUCT: COMM_CONFIG
-    { "DWORD" "dwSize" }
-    { "WORD" "wVersion" }
-    { "WORD" "wReserved" }
-    { "DCB" "dcb" }
-    { "DWORD" "dwProviderSubType" }
-    { "DWORD" "dwProviderOffset" }
-    { "DWORD" "dwProviderSize" }
-    { { "WCHAR" 1 } "wcProviderData" } ;
+STRUCT: COMM_CONFIG
+    { dwSize DWORD }
+    { wVersion WORD }
+    { wReserved WORD }
+    { dcb DCB }
+    { dwProviderSubType DWORD }
+    { dwProviderOffset DWORD }
+    { dwProviderSize DWORD }
+    { wcProviderData { WCHAR 1 } } ;
 TYPEDEF: COMMCONFIG* LPCOMMCONFIG
 
-C-STRUCT: COMMPROP
-    { "WORD" "wPacketLength" }
-    { "WORD" "wPacketVersion" }
-    { "DWORD" "dwServiceMask" }
-    { "DWORD" "dwReserved1" }
-    { "DWORD" "dwMaxTxQueue" }
-    { "DWORD" "dwMaxRxQueue" }
-    { "DWORD" "dwMaxBaud" }
-    { "DWORD" "dwProvSubType" }
-    { "DWORD" "dwProvCapabilities" }
-    { "DWORD" "dwSettableParams" }
-    { "DWORD" "dwSettableBaud" }
-    { "WORD"  "wSettableData" }
-    { "WORD"  "wSettableStopParity" }
-    { "DWORD" "dwCurrentTxQueue" }
-    { "DWORD" "dwCurrentRxQueue" }
-    { "DWORD" "dwProvSpec1" }
-    { "DWORD" "dwProvSpec2" }
-    { { "WCHAR" 1 } "wcProvChar" } ;
+STRUCT: COMMPROP
+    { wPacketLength WORD }
+    { wPacketVersion WORD }
+    { dwServiceMask DWORD }
+    { dwReserved1 DWORD }
+    { dwMaxTxQueue DWORD }
+    { dwMaxRxQueue DWORD }
+    { dwMaxBaud DWORD }
+    { dwProvSubType DWORD }
+    { dwProvCapabilities DWORD }
+    { dwSettableParams DWORD }
+    { dwSettableBaud DWORD }
+    { wSettableData WORD  }
+    { wSettableStopParity WORD  }
+    { dwCurrentTxQueue DWORD }
+    { dwCurrentRxQueue DWORD }
+    { dwProvSpec1 DWORD }
+    { dwProvSpec2 DWORD }
+    { wcProvChar { WCHAR 1 } } ;
 TYPEDEF: COMMPROP* LPCOMMPROP
 
 
@@ -645,19 +645,19 @@ CONSTANT: WAIT_TIMEOUT 258
 CONSTANT: WAIT_IO_COMPLETION HEX: c0
 CONSTANT: WAIT_FAILED HEX: ffffffff
 
-C-STRUCT: LUID
-    { "DWORD" "LowPart" }
-    { "LONG" "HighPart" } ;
+STRUCT: LUID
+    { LowPart DWORD }
+    { HighPart LONG } ;
 TYPEDEF: LUID* PLUID
 
-C-STRUCT: LUID_AND_ATTRIBUTES
-    { "LUID" "Luid" }
-    { "DWORD" "Attributes" } ;
+STRUCT: LUID_AND_ATTRIBUTES
+    { Luid LUID }
+    { Attributes DWORD } ;
 TYPEDEF: LUID_AND_ATTRIBUTES* PLUID_AND_ATTRIBUTES
 
-C-STRUCT: TOKEN_PRIVILEGES
-    { "DWORD" "PrivilegeCount" }
-    { "LUID_AND_ATTRIBUTES*" "Privileges" } ;
+STRUCT: TOKEN_PRIVILEGES
+    { PrivilegeCount DWORD }
+    { Privileges LUID_AND_ATTRIBUTES* } ;
 TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES
 
 STRUCT: WIN32_FILE_ATTRIBUTE_DATA
@@ -669,29 +669,29 @@ STRUCT: WIN32_FILE_ATTRIBUTE_DATA
     { nFileSizeLow DWORD } ;
 TYPEDEF: WIN32_FILE_ATTRIBUTE_DATA* LPWIN32_FILE_ATTRIBUTE_DATA
 
-C-STRUCT: BY_HANDLE_FILE_INFORMATION
-  { "DWORD" "dwFileAttributes" }
-  { "FILETIME" "ftCreationTime" }
-  { "FILETIME" "ftLastAccessTime" }
-  { "FILETIME" "ftLastWriteTime" }
-  { "DWORD" "dwVolumeSerialNumber" }
-  { "DWORD" "nFileSizeHigh" }
-  { "DWORD" "nFileSizeLow" }
-  { "DWORD" "nNumberOfLinks" }
-  { "DWORD" "nFileIndexHigh" }
-  { "DWORD" "nFileIndexLow" } ;
+STRUCT: BY_HANDLE_FILE_INFORMATION
+  { dwFileAttributes DWORD }
+  { ftCreationTime FILETIME }
+  { ftLastAccessTime FILETIME }
+  { ftLastWriteTime FILETIME }
+  { dwVolumeSerialNumber DWORD }
+  { nFileSizeHigh DWORD }
+  { nFileSizeLow DWORD }
+  { nNumberOfLinks DWORD }
+  { nFileIndexHigh DWORD }
+  { nFileIndexLow DWORD } ;
 TYPEDEF: BY_HANDLE_FILE_INFORMATION* LPBY_HANDLE_FILE_INFORMATION
 
 CONSTANT: OFS_MAXPATHNAME 128
 
-C-STRUCT: OFSTRUCT
-    { "BYTE" "cBytes" }
-    { "BYTE" "fFixedDisk" }
-    { "WORD" "nErrCode" }
-    { "WORD" "Reserved1" }
-    { "WORD" "Reserved2" }
-    ! { { "CHAR" OFS_MAXPATHNAME } "szPathName" } ;
-    { { "CHAR" 128 } "szPathName" } ;
+STRUCT: OFSTRUCT
+    { cBytes BYTE }
+    { fFixedDisk BYTE }
+    { nErrCode WORD }
+    { Reserved1 WORD }
+    { Reserved2 WORD }
+    { szPathName { CHAR 128 } } ;
+    ! { szPathName { CHAR OFS_MAXPATHNAME } } ;
 
 TYPEDEF: OFSTRUCT* LPOFSTRUCT
 
@@ -707,18 +707,6 @@ STRUCT: WIN32_FIND_DATA
     { cFileName { "TCHAR" MAX_PATH } }
     { cAlternateFileName TCHAR[14] } ;
 
-STRUCT: BY_HANDLE_FILE_INFORMATION
-    { dwFileAttributes DWORD }
-    { ftCreationTime FILETIME }
-    { ftLastAccessTime FILETIME }
-    { ftLastWriteTime FILETIME }
-    { dwVolumeSerialNumber DWORD }
-    { nFileSizeHigh DWORD }
-    { nFileSizeLow DWORD }
-    { nNumberOfLinks DWORD }
-    { nFileIndexHigh DWORD }
-    { nFileIndexLow DWORD } ;
-
 TYPEDEF: WIN32_FIND_DATA* PWIN32_FIND_DATA
 TYPEDEF: WIN32_FIND_DATA* LPWIN32_FIND_DATA
 TYPEDEF: void* POVERLAPPED
index 63cfd92ba12a64a8f287ef59e43111b116628b41..e38477c98c7bdf60ca018da592ba93b1da9dec53 100755 (executable)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2009 Joe Groff, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel combinators sequences
-math windows.gdi32 windows.types images destructors
-accessors fry locals classes.struct ;
+USING: alien.c-types alien.data kernel combinators
+sequences math windows.gdi32 windows.types images
+destructors accessors fry locals classes.struct ;
 IN: windows.offscreen
 
 : (bitmap-info) ( dim -- BITMAPINFO )
index 9e117c85225df02f23c73cecfdecdae3f343ce8b..3bc7f459600425c849cd028018690c1f1ec3952f 100755 (executable)
@@ -1,5 +1,5 @@
-USING: alien alien.syntax alien.c-types alien.strings math
-kernel sequences windows.errors windows.types io accessors
+USING: alien alien.syntax alien.c-types alien.data alien.strings
+math kernel sequences windows.errors windows.types io accessors
 math.order namespaces make math.parser windows.kernel32
 combinators locals specialized-arrays literals splitting
 grouping classes.struct combinators.smart ;
@@ -78,29 +78,29 @@ CONSTANT: TYMED_MFPICT   32
 CONSTANT: TYMED_ENHMF    64
 CONSTANT: TYMED_NULL     0
 
-C-STRUCT: DVTARGETDEVICE
-    { "DWORD" "tdSize" }
-    { "WORD" "tdDriverNameOffset" }
-    { "WORD" "tdDeviceNameOffset" }
-    { "WORD" "tdPortNameOffset" }
-    { "WORD" "tdExtDevmodeOffset" }
-    { "BYTE[1]" "tdData" } ;
+STRUCT: DVTARGETDEVICE
+    { tdSize DWORD }
+    { tdDriverNameOffset WORD }
+    { tdDeviceNameOffset WORD }
+    { tdPortNameOffset WORD }
+    { tdExtDevmodeOffset WORD }
+    { tdData BYTE[1] } ;
 
 TYPEDEF: WORD CLIPFORMAT
 TYPEDEF: POINT POINTL
 
-C-STRUCT: FORMATETC
-    { "CLIPFORMAT" "cfFormat" }
-    { "DVTARGETDEVICE*" "ptd" }
-    { "DWORD" "dwAspect" }
-    { "LONG" "lindex" }
-    { "DWORD" "tymed" } ;
+STRUCT: FORMATETC
+    { cfFormat CLIPFORMAT }
+    { ptd DVTARGETDEVICE* }
+    { dwAspect DWORD }
+    { lindex LONG }
+    { tymed DWORD } ;
 TYPEDEF: FORMATETC* LPFORMATETC
 
-C-STRUCT: STGMEDIUM
-    { "DWORD" "tymed" }
-    { "void*" "data" }
-    { "LPUNKNOWN" "punkForRelease" } ;
+STRUCT: STGMEDIUM
+    { tymed DWORD }
+    { data void* }
+    { punkForRelease LPUNKNOWN } ;
 TYPEDEF: STGMEDIUM* LPSTGMEDIUM
 
 CONSTANT: COINIT_MULTITHREADED     0
index c882ba2e7f3a16c2ab2fee56a2da30bc708a6803..6275f2d3c95a9007e43b1b358e099a25b71a0a15 100755 (executable)
@@ -3,6 +3,7 @@
 USING: alien alien.c-types alien.syntax namespaces kernel words
 sequences math math.bitwise math.vectors colors
 io.encodings.utf16n classes.struct accessors ;
+FROM: alien.c-types => float short ;
 IN: windows.types
 
 TYPEDEF: char                CHAR
@@ -10,6 +11,12 @@ TYPEDEF: uchar               UCHAR
 TYPEDEF: uchar               BYTE
 
 TYPEDEF: ushort              wchar_t
+SYMBOL: wchar_t*
+<<
+{ char* utf16n } \ wchar_t* typedef
+\ wchar_t \ wchar_t* "pointer-c-type" set-word-prop
+>>
+
 TYPEDEF: wchar_t             WCHAR
 
 TYPEDEF: short               SHORT
@@ -69,8 +76,6 @@ TYPEDEF: ulonglong   ULARGE_INTEGER
 TYPEDEF: LARGE_INTEGER* PLARGE_INTEGER
 TYPEDEF: ULARGE_INTEGER* PULARGE_INTEGER
 
-<< { "char*" utf16n } "wchar_t*" typedef >>
-
 TYPEDEF: wchar_t*  LPCSTR
 TYPEDEF: wchar_t*  LPWSTR
 TYPEDEF: WCHAR       TCHAR
@@ -248,14 +253,13 @@ STRUCT: RECT
     { right LONG }
     { bottom LONG } ;
 
-C-STRUCT: PAINTSTRUCT
-    { "HDC" " hdc" }
-    { "BOOL" "fErase" }
-    { "RECT" "rcPaint" }
-    { "BOOL" "fRestore" }
-    { "BOOL" "fIncUpdate" }
-    { "BYTE[32]" "rgbReserved" }
-;
+STRUCT: PAINTSTRUCT
+    { hdc HDC }
+    { fErase BOOL }
+    { rcPaint RECT }
+    { fRestore BOOL }
+    { fIncUpdate BOOL }
+    { rgbReserved BYTE[32] } ;
 
 STRUCT: BITMAPINFOHEADER
     { biSize DWORD }
@@ -283,21 +287,21 @@ STRUCT: BITMAPINFO
 TYPEDEF: void* LPPAINTSTRUCT
 TYPEDEF: void* PAINTSTRUCT
 
-C-STRUCT: POINT
-    { "LONG" "x" }
-    { "LONG" "y" } ; 
+STRUCT: POINT
+    { x LONG }
+    { y LONG } ; 
 
 STRUCT: SIZE
     { cx LONG }
     { cy LONG } ;
 
-C-STRUCT: MSG
-    { "HWND" "hWnd" }
-    { "UINT" "message" }
-    { "WPARAM" "wParam" }
-    { "LPARAM" "lParam" }
-    { "DWORD" "time" }
-    { "POINT" "pt" } ;
+STRUCT: MSG
+    { hWnd HWND }
+    { message UINT }
+    { wParam WPARAM }
+    { lParam LPARAM }
+    { time DWORD }
+    { pt POINT } ;
 
 TYPEDEF: MSG*                LPMSG
 
@@ -339,34 +343,34 @@ TYPEDEF: PFD* LPPFD
 TYPEDEF: HANDLE HGLRC
 TYPEDEF: HANDLE HRGN
 
-C-STRUCT: LVITEM
-    { "uint" "mask" }
-    { "int" "iItem" }
-    { "int" "iSubItem" }
-    { "uint" "state" }
-    { "uint" "stateMask" }
-    { "void*" "pszText" }
-    { "int" "cchTextMax" }
-    { "int" "iImage" }
-    { "long" "lParam" }
-    { "int" "iIndent" }
-    { "int" "iGroupId" }
-    { "uint" "cColumns" }
-    { "uint*" "puColumns" }
-    { "int*" "piColFmt" }
-    { "int" "iGroup" } ;
-
-C-STRUCT: LVFINDINFO
-    { "uint" "flags" }
-    { "char*" "psz" }
-    { "long" "lParam" }
-    { "POINT" "pt" }
-    { "uint" "vkDirection" } ;
-
-C-STRUCT: ACCEL
-    { "BYTE" "fVirt" }
-    { "WORD" "key" }
-    { "WORD" "cmd" } ;
+STRUCT: LVITEM
+    { mask uint }
+    { iItem int }
+    { iSubItem int }
+    { state uint }
+    { stateMask uint }
+    { pszText void* }
+    { cchTextMax int }
+    { iImage int }
+    { lParam long }
+    { iIndent int }
+    { iGroupId int }
+    { cColumns uint }
+    { puColumns uint* }
+    { piColFmt int* }
+    { iGroup int } ;
+
+STRUCT: LVFINDINFO
+    { flags uint }
+    { psz char* }
+    { lParam long }
+    { pt POINT }
+    { vkDirection uint } ;
+
+STRUCT: ACCEL
+    { fVirt BYTE }
+    { key WORD }
+    { cmd WORD } ;
 TYPEDEF: ACCEL* LPACCEL
 
 TYPEDEF: DWORD COLORREF
index 50fa98996c7fe3fee90c7ba8f858002a87379a0d..eb57a469258ff10558ad03f7b28c9c7c34f96a5b 100755 (executable)
@@ -1,23 +1,23 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax alien.destructors ;
+USING: alien.syntax alien.destructors classes.struct ;
 IN: windows.usp10
 
 LIBRARY: usp10
 
-C-STRUCT: SCRIPT_CONTROL
-    { "DWORD" "flags" } ;
+STRUCT: SCRIPT_CONTROL
+    { flags DWORD } ;
 
-C-STRUCT: SCRIPT_STATE
-    { "WORD" "flags" } ;
+STRUCT: SCRIPT_STATE
+    { flags WORD } ;
 
-C-STRUCT: SCRIPT_ANALYSIS
-    { "WORD" "flags" }
-    { "SCRIPT_STATE" "s" } ;
+STRUCT: SCRIPT_ANALYSIS
+    { flags WORD }
+    { s SCRIPT_STATE } ;
 
-C-STRUCT: SCRIPT_ITEM
-    { "int" "iCharPos" }
-    { "SCRIPT_ANALYSIS" "a" } ;
+STRUCT: SCRIPT_ITEM
+    { iCharPos int }
+    { a SCRIPT_ANALYSIS } ;
 
 FUNCTION: HRESULT ScriptItemize (
     WCHAR* pwcInChars,
@@ -53,8 +53,8 @@ SCRIPT_JUSTIFY_BARA
 SCRIPT_JUSTIFY_SEEN
 SCRIPT_JUSTIFFY_RESERVED4 ;
 
-C-STRUCT: SCRIPT_VISATTR
-    { "WORD" "flags" } ;
+STRUCT: SCRIPT_VISATTR
+    { flags WORD } ;
 
 FUNCTION: HRESULT ScriptShape (
     HDC hdc,
@@ -69,9 +69,9 @@ FUNCTION: HRESULT ScriptShape (
     int* pcGlyphs
 ) ;
 
-C-STRUCT: GOFFSET
-    { "LONG" "du" }
-    { "LONG" "dv" } ;
+STRUCT: GOFFSET
+    { du LONG }
+    { dv LONG } ;
 
 FUNCTION: HRESULT ScriptPlace (
     HDC hdc,
@@ -111,8 +111,8 @@ FUNCTION: HRESULT ScriptJustify (
     int* piJustify
 ) ;
 
-C-STRUCT: SCRIPT_LOGATTR
-    { "BYTE" "flags" } ;
+STRUCT: SCRIPT_LOGATTR
+    { flags BYTE } ;
 
 FUNCTION: HRESULT ScriptBreak (
     WCHAR* pwcChars,
@@ -184,21 +184,21 @@ FUNCTION: HRESULT ScriptGetGlyphABCWidth (
     ABC* pABC
 ) ;
 
-C-STRUCT: SCRIPT_PROPERTIES
-    { "DWORD" "flags" } ;
+STRUCT: SCRIPT_PROPERTIES
+    { flags DWORD } ;
 
 FUNCTION: HRESULT ScriptGetProperties (
     SCRIPT_PROPERTIES*** ppSp,
     int* piNumScripts
 ) ;
 
-C-STRUCT: SCRIPT_FONTPROPERTIES
-    { "int" "cBytes" }
-    { "WORD" "wgBlank" }
-    { "WORD" "wgDefault" }
-    { "WORD" "wgInvalid" }
-    { "WORD" "wgKashida" }
-    { "int" "iKashidaWidth" } ;
+STRUCT: SCRIPT_FONTPROPERTIES
+    { cBytes int }
+    { wgBlank WORD }
+    { wgDefault WORD }
+    { wgInvalid WORD }
+    { wgKashida WORD }
+    { iKashidaWidth int } ;
 
 FUNCTION: HRESULT ScriptGetFontProperties (
     HDC hdc,
@@ -234,11 +234,11 @@ CONSTANT: SSA_LAYOUTRTL HEX: 20000000
 CONSTANT: SSA_DONTGLYPH HEX: 40000000
 CONSTANT: SSA_NOKASHIDA HEX: 80000000
 
-C-STRUCT: SCRIPT_TABDEF
-    { "int" "cTabStops" }
-    { "int" "iScale" }
-    { "int*" "pTabStops" }
-    { "int" "iTabOrigin" } ;
+STRUCT: SCRIPT_TABDEF
+    { cTabStops int }
+    { iScale int }
+    { pTabStops int* }
+    { iTabOrigin int } ;
 
 TYPEDEF: void* SCRIPT_STRING_ANALYSIS
 
@@ -319,8 +319,8 @@ FUNCTION: HRESULT ScriptIsComplex (
     DWORD dwFlags
 ) ;
 
-C-STRUCT: SCRIPT_DIGITSUBSTITUTE
-    { "DWORD" "flags" } ;
+STRUCT: SCRIPT_DIGITSUBSTITUTE
+    { flags DWORD } ;
 
 FUNCTION: HRESULT ScriptRecordDigitSubstitution (
     LCID Locale,
@@ -336,4 +336,4 @@ FUNCTION: HRESULT ScriptApplyDigitSubstitution (
     SCRIPT_DIGITSUBSTITUTE* psds,
     SCRIPT_CONTROL* psc,
     SCRIPT_STATE* pss
-) ;
\ No newline at end of file
+) ;
index 87b8970b02d1f40bfcd03c85d5024c8fa3116cb4..dc751e64a6e40c6b4216744fc3d5fc7fe009d336 100755 (executable)
@@ -4,6 +4,7 @@ USING: alien alien.c-types alien.strings alien.syntax arrays
 byte-arrays kernel literals math sequences windows.types
 windows.kernel32 windows.errors math.bitwise io.encodings.utf16n
 classes.struct windows.com.syntax init ;
+FROM: alien.c-types => short ;
 IN: windows.winsock
 
 TYPEDEF: void* SOCKET
@@ -134,9 +135,9 @@ STRUCT: addrinfo
     { addr sockaddr* }
     { next addrinfo* } ;
 
-C-STRUCT: timeval
-    { "long" "sec" }
-    { "long" "usec" } ;
+STRUCT: timeval
+    { sec long }
+    { usec long } ;
 
 LIBRARY: winsock
 
@@ -176,15 +177,15 @@ TYPEDEF: HANDLE WSAEVENT
 TYPEDEF: LPHANDLE LPWSAEVENT
 TYPEDEF: sockaddr* LPSOCKADDR
 
-C-STRUCT: FLOWSPEC
-    { "uint"        "TokenRate" }
-    { "uint"        "TokenBucketSize" }
-    { "uint"        "PeakBandwidth" }
-    { "uint"        "Latency" }
-    { "uint"        "DelayVariation" }
-    { "SERVICETYPE" "ServiceType" }
-    { "uint"        "MaxSduSize" }
-    { "uint"        "MinimumPolicedSize" } ;
+STRUCT: FLOWSPEC
+    { TokenRate          uint        }
+    { TokenBucketSize    uint        }
+    { PeakBandwidth      uint        }
+    { Latency            uint        }
+    { DelayVariation     uint        }
+    { ServiceType        SERVICETYPE }
+    { MaxSduSize         uint        }
+    { MinimumPolicedSize uint        } ;
 TYPEDEF: FLOWSPEC* PFLOWSPEC
 TYPEDEF: FLOWSPEC* LPFLOWSPEC
 
@@ -193,44 +194,44 @@ STRUCT: WSABUF
     { buf void* } ;
 TYPEDEF: WSABUF* LPWSABUF
 
-C-STRUCT: QOS
-    { "FLOWSPEC" "SendingFlowspec" }
-    { "FLOWSPEC" "ReceivingFlowspec" }
-    { "WSABUF" "ProviderSpecific" } ;
+STRUCT: QOS
+    { SendingFlowspec FLOWSPEC }
+    { ReceivingFlowspec FLOWSPEC }
+    { ProviderSpecific WSABUF } ;
 TYPEDEF: QOS* LPQOS
 
 CONSTANT: MAX_PROTOCOL_CHAIN 7
 
-C-STRUCT: WSAPROTOCOLCHAIN
-    { "int" "ChainLen" }
-    ! { { "DWORD" MAX_PROTOCOL_CHAIN } "ChainEntries" } ;
-    { { "DWORD" 7 } "ChainEntries" } ;
+STRUCT: WSAPROTOCOLCHAIN
+    { ChainLen int }
+    { ChainEntries { DWORD 7 } } ;
+    ! { ChainEntries { DWORD MAX_PROTOCOL_CHAIN } } ;
 TYPEDEF: WSAPROTOCOLCHAIN* LPWSAPROTOCOLCHAIN
 
 CONSTANT: WSAPROTOCOL_LEN 255
 
-C-STRUCT: WSAPROTOCOL_INFOW
-    { "DWORD" "dwServiceFlags1" }
-    { "DWORD" "dwServiceFlags2" }
-    { "DWORD" "dwServiceFlags3" }
-    { "DWORD" "dwServiceFlags4" }
-    { "DWORD" "dwProviderFlags" }
-    { "GUID" "ProviderId" }
-    { "DWORD" "dwCatalogEntryId" }
-    { "WSAPROTOCOLCHAIN" "ProtocolChain" }
-    { "int" "iVersion" }
-    { "int" "iAddressFamily" }
-    { "int" "iMaxSockAddr" }
-    { "int" "iMinSockAddr" }
-    { "int" "iSocketType" }
-    { "int" "iProtocol" }
-    { "int" "iProtocolMaxOffset" }
-    { "int" "iNetworkByteOrder" }
-    { "int" "iSecurityScheme" }
-    { "DWORD" "dwMessageSize" }
-    { "DWORD" "dwProviderReserved" }
-    { { "WCHAR" 256 } "szProtocol" } ;
-    ! { { "WCHAR" 256 } "szProtocol"[WSAPROTOCOL_LEN+1] } ;
+STRUCT: WSAPROTOCOL_INFOW
+    { dwServiceFlags1 DWORD }
+    { dwServiceFlags2 DWORD }
+    { dwServiceFlags3 DWORD }
+    { dwServiceFlags4 DWORD }
+    { dwProviderFlags DWORD }
+    { ProviderId GUID }
+    { dwCatalogEntryId DWORD }
+    { ProtocolChain WSAPROTOCOLCHAIN }
+    { iVersion int }
+    { iAddressFamily int }
+    { iMaxSockAddr int }
+    { iMinSockAddr int }
+    { iSocketType int }
+    { iProtocol int }
+    { iProtocolMaxOffset int }
+    { iNetworkByteOrder int }
+    { iSecurityScheme int }
+    { dwMessageSize DWORD }
+    { dwProviderReserved DWORD }
+    { szProtocol { WCHAR 256 } } ;
+    ! { szProtocol[WSAPROTOCOL_LEN+1] { WCHAR 256 } } ;
 TYPEDEF: WSAPROTOCOL_INFOW* PWSAPROTOCOL_INFOW
 TYPEDEF: WSAPROTOCOL_INFOW* LPWSAPROTOCOL_INFOW
 TYPEDEF: WSAPROTOCOL_INFOW WSAPROTOCOL_INFO
@@ -238,12 +239,12 @@ TYPEDEF: WSAPROTOCOL_INFOW* PWSAPROTOCOL_INFO
 TYPEDEF: WSAPROTOCOL_INFOW* LPWSAPROTOCOL_INFO
 
 
-C-STRUCT: WSANAMESPACE_INFOW
-    { "GUID"    "NSProviderId" }
-    { "DWORD"   "dwNameSpace" }
-    { "BOOL"    "fActive" }
-    { "DWORD"   "dwVersion" }
-    { "LPWSTR"  "lpszIdentifier" } ;
+STRUCT: WSANAMESPACE_INFOW
+    { NSProviderId   GUID    }
+    { dwNameSpace    DWORD   }
+    { fActive        BOOL    }
+    { dwVersion      DWORD   }
+    { lpszIdentifier LPWSTR  } ;
 TYPEDEF: WSANAMESPACE_INFOW* PWSANAMESPACE_INFOW
 TYPEDEF: WSANAMESPACE_INFOW* LPWSANAMESPACE_INFOW
 TYPEDEF: WSANAMESPACE_INFOW WSANAMESPACE_INFO
@@ -252,19 +253,19 @@ TYPEDEF: WSANAMESPACE_INFO* LPWSANAMESPACE_INFO
 
 CONSTANT: FD_MAX_EVENTS 10
 
-C-STRUCT: WSANETWORKEVENTS
-    { "long" "lNetworkEvents" }
-    { { "int" FD_MAX_EVENTS } "iErrorCode" } ;
+STRUCT: WSANETWORKEVENTS
+    { lNetworkEvents long }
+    { iErrorCode { int FD_MAX_EVENTS } } ;
 TYPEDEF: WSANETWORKEVENTS* PWSANETWORKEVENTS
 TYPEDEF: WSANETWORKEVENTS* LPWSANETWORKEVENTS
 
-! C-STRUCT: WSAOVERLAPPED
-    ! { "DWORD" "Internal" }
-    ! { "DWORD" "InternalHigh" }
-    ! { "DWORD" "Offset" }
-    ! { "DWORD" "OffsetHigh" }
-    ! { "WSAEVENT" "hEvent" }
-    ! { "DWORD" "bytesTransferred" } ;
+! STRUCT: WSAOVERLAPPED
+    ! { Internal DWORD }
+    ! { InternalHigh DWORD }
+    ! { Offset DWORD }
+    ! { OffsetHigh DWORD }
+    ! { hEvent WSAEVENT }
+    ! { bytesTransferred DWORD } ;
 ! TYPEDEF: WSAOVERLAPPED* LPWSAOVERLAPPED
 
 FUNCTION: SOCKET WSAAccept ( SOCKET s,
index 48d556de1ddb28b6a4374b77c26cca506154f56b..0cd7704cf88781f3c2fcd1bb9cd64ffa6be8ffa9 100644 (file)
 ! add to this library and are wondering what part of the file to
 ! modify, just find the function or data structure in the manual
 ! and note the section.
-USING: accessors kernel arrays alien alien.c-types alien.strings
-alien.syntax classes.struct math math.bitwise words sequences
-namespaces continuations io io.encodings.ascii x11.syntax ;
+USING: accessors kernel arrays alien alien.c-types alien.data
+alien.strings alien.syntax classes.struct math math.bitwise words
+sequences namespaces continuations io io.encodings.ascii x11.syntax ;
+FROM: alien.c-types => short ;
 IN: x11.xlib
 
 LIBRARY: xlib
index 6a0a42253b797a3042e0536bd04c7e27406a73b1..c1b5a9e159f25c67ab3536cce186d6345e69a24e 100644 (file)
@@ -1,4 +1,4 @@
-USING: alien.strings alien.c-types tools.test kernel libc
+USING: alien.strings alien.c-types alien.data tools.test kernel libc
 io.encodings.8-bit io.encodings.utf8 io.encodings.utf16
 io.encodings.utf16n io.encodings.ascii alien io.encodings.string ;
 IN: alien.strings.tests
index c7be17e38d90555f1eb97b83dc32fe22747e6249..9c84904ff736db68c7da487bd773d1e0aa5b1a26 100644 (file)
@@ -40,7 +40,7 @@ load-help? off
     "bootstrap.layouts" require
 
     [
-        "vocab:bootstrap/stage2.factor"
+        "resource:basis/bootstrap/stage2.factor"
         dup exists? [
             run-file
         ] [
index 0a57ad34f35a2e5b83f2325c937814c98eb1beaf..626cbd63dfbd2bd05f24e5ca3788942ed999ff9e 100644 (file)
@@ -99,9 +99,17 @@ GENERIC# boa>object 1 ( class slots -- tuple )
 M: tuple-class boa>object
     swap prefix >tuple ;
 
+ERROR: bad-slot-name class slot ;
+
+: check-slot-exists ( class initials slot-spec/f index/f name -- class initials slot-spec index )
+    over [ drop ] [ nip nip nip bad-slot-name ] if ;
+
+: slot-named-checked ( class initials name slots -- class initials slot-spec )
+    over [ slot-named* ] dip check-slot-exists drop ;
+
 : assoc>object ( class slots values -- tuple )
     [ [ [ initial>> ] map ] keep ] dip
-    swap [ [ slot-named* drop ] curry dip ] curry assoc-map
+    swap [ [ slot-named-checked ] curry dip ] curry assoc-map
     [ dup <enum> ] dip update boa>object ;
 
 : parse-tuple-literal-slots ( class slots -- tuple )
index 4a7fcea0e6250a1984246072a36bd7ff1e3d63b1..5d778ba1e41ec165d9647bd8ae59d5506b8e56d6 100755 (executable)
@@ -85,7 +85,7 @@ $nl
 } ;
 
 ARTICLE: "spread-combinators" "Spread combinators"
-"The spread combinators apply multiple quotations to multiple values. The " { $snippet "*" } " suffix signifies spreading."
+"The spread combinators apply multiple quotations to multiple values. In this case, " { $snippet "*" } " suffix signify spreading."
 $nl
 "Two quotations:"
 { $subsection bi* }
index ebb9c8aa5e351a8a7ead699ddcde777dc066a627..c3ee350099b43315a1259d02e96a0236a03de5ce 100644 (file)
@@ -61,7 +61,7 @@ HELP: bin>
 $nl
 "Outputs " { $link f } " if the string does not represent a number." } ;
 
-{ bin> POSTPONE: BIN: bin> .b } related-words
+{ >bin POSTPONE: BIN: bin> .b } related-words
 
 HELP: oct>
 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
@@ -69,7 +69,7 @@ HELP: oct>
 $nl
 "Outputs " { $link f } " if the string does not represent a number." } ;
 
-{ oct> POSTPONE: OCT: oct> .o } related-words
+{ >oct POSTPONE: OCT: oct> .o } related-words
 
 HELP: hex>
 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
@@ -77,7 +77,7 @@ HELP: hex>
 $nl
 "Outputs " { $link f } " if the string does not represent a number." } ;
 
-{ hex> POSTPONE: HEX: hex> .h } related-words
+{ >hex POSTPONE: HEX: hex> .h } related-words
 
 HELP: >base
 { $values { "n" real } { "radix" "an integer between 2 and 36" } { "str" string } }
index e34fb0957f123b9e71f9266400987fde4fdd8ec6..394ae3f67c58c203f005dbb41150c0548dd683eb 100644 (file)
@@ -593,10 +593,13 @@ HELP: #!
 { $description "Discards all input until the end of the line." } ;
 
 HELP: HEX:
-{ $syntax "HEX: integer" }
-{ $values { "integer" "hexadecimal digits (0-9, a-f, A-F)" } }
-{ $description "Adds an integer read from a hexadecimal literal to the parse tree." }
-{ $examples { $example "USE: prettyprint" "HEX: ff ." "255" } } ;
+{ $syntax "HEX: NNN" "HEX: NNN.NNNpEEE" }
+{ $values { "N" "hexadecimal digit (0-9, a-f, A-F)" } { "pEEE" "decimal exponent value" } }
+{ $description "Adds an integer or floating-point value read from a hexadecimal literal to the parse tree." }
+{ $examples
+    { $example "USE: prettyprint" "HEX: ff ." "255" }
+    { $example "USE: prettyprint" "HEX: 1.8p5 ." "48.0" }
+} ;
 
 HELP: OCT:
 { $syntax "OCT: integer" }
index 84c3450102953e0444fd19e463d514135bbd39b7..ee69d954eafe13c785eb949914ce1887440cf762 100644 (file)
@@ -41,6 +41,11 @@ SYMBOL: c-strings
     [ current-vocab name>> % "_" % % ] "" make ;
 PRIVATE>
 
+: parse-arglist ( parameters return -- types effect )
+    [ 2 group unzip [ "," ?tail drop ] map ]
+    [ [ { } ] [ 1array ] if-void ]
+    bi* <effect> ;
+
 : append-function-body ( prototype-str body -- str )
     [ swap % " {\n" % % "\n}\n" % ] "" make ;
 
index e6a0b8b7d8f3bba17eec890010136975725dbd91..c49b2b5aaeea61d18d9a8c100d111c418522560b 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Jeremy Hughes.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.inline alien.inline.syntax io.directories io.files
-kernel namespaces tools.test alien.c-types alien.structs ;
+kernel namespaces tools.test alien.c-types alien.data alien.structs ;
 IN: alien.inline.syntax.tests
 
 DELETE-C-LIBRARY: test
index 070febc3245cab6849ea2c2d93e8f528ba988376..ac7f6ae17f4252d94281f44d5b1d497b6b09bbd7 100644 (file)
@@ -2,10 +2,11 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types assocs combinators.short-circuit
 continuations effects fry kernel math memoize sequences
-splitting strings peg.ebnf make ;
+splitting strings peg.ebnf make words ;
 IN: alien.inline.types
 
 : cify-type ( str -- str' )
+    dup word? [ name>> ] when
     { { CHAR: - CHAR: space } } substitute ;
 
 : factorize-type ( str -- str' )
index 361753a0d33fa7a936627c19d4ee9d8e2c59629c..5d6ec29912d09b1893b11cb33dce88e25c3d8c95 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Jeremy Hughes.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: help.markup help.syntax kernel quotations sequences
-strings alien alien.c-types math byte-arrays ;
+strings alien alien.c-types alien.data math byte-arrays ;
 IN: alien.marshall
 
 <PRIVATE
index 2cae12264168235a1d90c7c3af77d0f5c3fe8c86..059ee72de1c481fd2d986dd7e0f3bc1411020e54 100644 (file)
@@ -3,9 +3,10 @@
 USING: accessors alien alien.c-types alien.inline.types
 alien.marshall.private alien.strings byte-arrays classes
 combinators combinators.short-circuit destructors fry
-io.encodings.utf8 kernel libc sequences
+io.encodings.utf8 kernel libc sequences alien.data
 specialized-arrays strings unix.utilities vocabs.parser
 words libc.private locals generalizations math ;
+FROM: alien.c-types => float short ;
 SPECIALIZED-ARRAY: bool
 SPECIALIZED-ARRAY: char
 SPECIALIZED-ARRAY: double
@@ -22,7 +23,7 @@ SPECIALIZED-ARRAY: ushort
 SPECIALIZED-ARRAY: void*
 IN: alien.marshall
 
-<< primitive-types [ [ "void*" = ] [ "bool" = ] bi or not ]
+<< primitive-types [ [ void* = ] [ bool = ] bi or not ]
 filter [ define-primitive-marshallers ] each >>
 
 TUPLE: alien-wrapper { underlying alien } ;
index c85b722d11d3d4ddef3d9711c9e5279b0f041646..d138282ff372bad4550f77b4bce277d7b8878bc7 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors alien alien.c-types alien.inline arrays
 combinators fry functors kernel lexer libc macros math
 sequences specialized-arrays libc.private
-combinators.short-circuit ;
+combinators.short-circuit alien.data ;
 SPECIALIZED-ARRAY: void*
 IN: alien.marshall.private
 
index 54bcab45f23f20b5e7b4df131311597f0291f9fe..3f9c8e3a7ef09206565b249e249436b95d653733 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors alien.c-types alien.marshall arrays assocs
 classes.tuple combinators destructors generalizations generic
 kernel libc locals parser quotations sequences slots words
-alien.structs lexer vocabs.parser fry effects ;
+alien.structs lexer vocabs.parser fry effects alien.data ;
 IN: alien.marshall.structs
 
 <PRIVATE
index 6b76e98f3adcbe58715008e509091f118b28591e..89cd04ad60edff3ca6b916d3c5d79d73b2f17ac1 100644 (file)
@@ -1,7 +1,7 @@
 USING: alien.c-types alien.syntax audio combinators
 combinators.short-circuit io io.binary io.encodings.binary
 io.files io.streams.byte-array kernel locals math
-sequences ;
+sequences alien alien.data classes.struct accessors ;
 IN: audio.wav
 
 CONSTANT: RIFF-MAGIC "RIFF"
@@ -9,30 +9,26 @@ CONSTANT: WAVE-MAGIC "WAVE"
 CONSTANT: FMT-MAGIC  "fmt "
 CONSTANT: DATA-MAGIC "data"
 
-C-STRUCT: riff-chunk-header
-    { "char[4]" "id" }
-    { "uchar[4]" "size" }
-    ;
+STRUCT: riff-chunk-header
+    { id char[4] }
+    { size char[4] } ;
 
-C-STRUCT: riff-chunk
-    { "riff-chunk-header" "header" }
-    { "char[4]" "format" }
-    ;
+STRUCT: riff-chunk
+    { header riff-chunk-header }
+    { format char[4] } ;
 
-C-STRUCT: wav-fmt-chunk
-    { "riff-chunk-header" "header" }
-    { "uchar[2]" "audio-format" }
-    { "uchar[2]" "num-channels" }
-    { "uchar[4]" "sample-rate" }
-    { "uchar[4]" "byte-rate" }
-    { "uchar[2]" "block-align" }
-    { "uchar[2]" "bits-per-sample" }
-    ;
+STRUCT: wav-fmt-chunk
+    { header riff-chunk-header }
+    { audio-format uchar[2] }
+    { num-channels uchar[2] }
+    { sample-rate uchar[4] }
+    { byte-rate uchar[4] }
+    { block-align uchar[2] }
+    { bits-per-sample uchar[2] } ;
 
-C-STRUCT: wav-data-chunk
-    { "riff-chunk-header" "header" }
-    { "uchar[0]" "body" }
-    ;
+STRUCT: wav-data-chunk
+    { header riff-chunk-header }
+    { body uchar[0] } ;
 
 ERROR: invalid-wav-file ;
 
@@ -44,39 +40,39 @@ ERROR: invalid-wav-file ;
 : read-chunk ( -- byte-array/f )
     4 ensured-read [ 4 ensured-read* dup le> ensured-read* 3append ] [ f ] if* ;
 : read-riff-chunk ( -- byte-array/f )
-    "riff-chunk" heap-size ensured-read* ;
+    riff-chunk heap-size ensured-read* ;
 
 : id= ( chunk id -- ? )
-    [ 4 head ] dip sequence= ;
+    [ 4 head ] dip sequence= ; inline
 
-: check-chunk ( chunk id min-size -- ? )
-    [ id= ] [ [ length ] dip >= ] bi-curry* bi and ;
+: check-chunk ( chunk id class -- ? )
+    heap-size [ id= ] [ [ length ] dip >= ] bi-curry* bi and ;
 
 :: read-wav-chunks ( -- fmt data )
     f :> fmt! f :> data!
     [ { [ fmt data and not ] [ read-chunk ] } 0&& dup ]
     [ {
-        { [ dup FMT-MAGIC  "wav-fmt-chunk"  heap-size check-chunk ] [ fmt!  ] }
-        { [ dup DATA-MAGIC "wav-data-chunk" heap-size check-chunk ] [ data! ] }
+        { [ dup FMT-MAGIC  wav-fmt-chunk  check-chunk ] [ wav-fmt-chunk  memory>struct fmt!  ] }
+        { [ dup DATA-MAGIC wav-data-chunk check-chunk ] [ wav-data-chunk memory>struct data! ] }
     } cond ] while drop
     fmt data 2dup and [ invalid-wav-file ] unless ;
 
 : verify-wav ( chunk -- )
     {
         [ RIFF-MAGIC id= ]
-        [ riff-chunk-format 4 memory>byte-array WAVE-MAGIC id= ]
+        [ riff-chunk memory>struct format>> 4 memory>byte-array WAVE-MAGIC id= ]
     } 1&&
     [ invalid-wav-file ] unless ;
 
 : (read-wav) ( -- audio )
     read-wav-chunks
     [
-        [ wav-fmt-chunk-num-channels    2 memory>byte-array le> ]
-        [ wav-fmt-chunk-bits-per-sample 2 memory>byte-array le> ]
-        [ wav-fmt-chunk-sample-rate     4 memory>byte-array le> ] tri
+        [ num-channels>>    2 memory>byte-array le> ]
+        [ bits-per-sample>> 2 memory>byte-array le> ]
+        [ sample-rate>>     4 memory>byte-array le> ] tri
     ] [
-        [ riff-chunk-header-size 4 memory>byte-array le> dup ]
-        [ wav-data-chunk-body ] bi swap memory>byte-array
+        [ header>> size>> 4 memory>byte-array le> dup ]
+        [ body>> >c-ptr ] bi swap memory>byte-array
     ] bi* <audio> ;
 
 : read-wav ( filename -- audio )
index 4f93367b8a48e687e01c69b19bbd901c9f6370ae..41ae5b35781b3d6ced2fb634f49de8657deb4182 100644 (file)
@@ -1,8 +1,7 @@
 ! Factor port of
 ! http://shootout.alioth.debian.org/gp4/benchmark.php?test=spectralnorm&lang=all
 USING: specialized-arrays kernel math math.functions
-math.vectors sequences sequences.private prettyprint words hints
-locals ;
+math.vectors sequences prettyprint words hints locals ;
 SPECIALIZED-ARRAY: double
 IN: benchmark.spectral-norm
 
@@ -19,13 +18,13 @@ IN: benchmark.spectral-norm
     + 1 + recip ; inline
 
 : (eval-A-times-u) ( u i j -- x )
-    tuck [ swap nth-unsafe ] [ eval-A ] 2bi* * ; inline
+    [ swap nth ] [ eval-A ] bi-curry bi* * ; inline
 
 : eval-A-times-u ( n u -- seq )
     [ (eval-A-times-u) ] inner-loop ; inline
 
 : (eval-At-times-u) ( u i j -- x )
-    tuck [ swap nth-unsafe ] [ swap eval-A ] 2bi* * ; inline
+    [ swap nth ] [ swap eval-A ] bi-curry bi* * ; inline
 
 : eval-At-times-u ( u n -- seq )
     [ (eval-At-times-u) ] inner-loop ; inline
index 8041bef07f2c740f063f0062231abc61a0035990..bd13de32c744f8a6aeba3bc9cb6339d923ed4c48 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.accessors alien.c-types alien.syntax byte-arrays
 destructors generalizations hints kernel libc locals math math.order
-sequences sequences.private classes.struct accessors ;
+sequences sequences.private classes.struct accessors alien.data ;
 IN: benchmark.yuv-to-rgb
 
 STRUCT: yuv_buffer
index dd6730b57f1382d41f9592fb8460eeda57946589..d80f3aa98aa6f00f2d5461c7b86a72d7a0f2a337 100755 (executable)
@@ -3,8 +3,9 @@ http.client io io.encodings.ascii io.files io.files.temp kernel
 math math.matrices math.parser math.vectors opengl
 opengl.capabilities opengl.gl opengl.demo-support sequences
 splitting vectors words specialized-arrays ;
-SPECIALIZED-ARRAY: float
-SPECIALIZED-ARRAY: uint
+QUALIFIED-WITH: alien.c-types c
+SPECIALIZED-ARRAY: c:float
+SPECIALIZED-ARRAY: c:uint
 IN: bunny.model
 
 : numbers ( str -- seq )
index 3e466b4781aa6ef1ad798c7192e9f44284391736..4d6c77fd23c03388961911fd8ed27ecd5c0af8d0 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors alien.c-types alien.strings assocs byte-arrays
 combinators continuations destructors fry io.encodings.8-bit
 io io.encodings.string io.encodings.utf8 kernel math
-namespaces prettyprint sequences
+namespaces prettyprint sequences classes.struct
 strings threads curses.ffi ;
 IN: curses
 
@@ -133,12 +133,12 @@ PRIVATE>
 
 : move-cursor ( window-name y x -- )
     [
-        window-ptr
+        window-ptr c-window memory>struct
         {
             [ ]
             [ (curses-window-refresh) ]
-            [ c-window-_curx ]
-            [ c-window-_cury ]
+            [ _curx>> ]
+            [ _cury>> ]
         } cleave
     ] 2dip mvcur curses-error (curses-window-refresh) ;
 
index 3ff9404bff39955c3017619380e7cc565f531b66..4eb01e913c7bd787beab0510368b9d2529794423 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.syntax combinators kernel system
-alien.libraries ;
+alien.libraries classes.struct ;
 IN: curses.ffi
 
 << "curses" {
@@ -21,56 +21,56 @@ TYPEDEF: ushort wchar_t
 
 CONSTANT: CCHARW_MAX  5
 
-C-STRUCT: cchar_t
-    { "attr_t" "attr" }
-    { { "wchar_t" CCHARW_MAX } "chars" } ;
+STRUCT: cchar_t
+    { attr attr_t }
+    { chars { wchar_t CCHARW_MAX } } ;
 
-C-STRUCT: pdat
-    { "NCURSES_SIZE_T" "_pad_y" }
-    { "NCURSES_SIZE_T" "_pad_x" }
-    { "NCURSES_SIZE_T" "_pad_top" }
-    { "NCURSES_SIZE_T" "_pad_left" }
-    { "NCURSES_SIZE_T" "_pad_bottom" }
-    { "NCURSES_SIZE_T" "_pad_right" } ;
+STRUCT: pdat
+    { _pad_y NCURSES_SIZE_T }
+    { _pad_x NCURSES_SIZE_T }
+    { _pad_top NCURSES_SIZE_T }
+    { _pad_left NCURSES_SIZE_T }
+    { _pad_bottom NCURSES_SIZE_T }
+    { _pad_right NCURSES_SIZE_T } ;
 
-C-STRUCT: c-window
-    { "NCURSES_SIZE_T" "_cury" }
-    { "NCURSES_SIZE_T" "_curx" }
+STRUCT: c-window
+    { _cury NCURSES_SIZE_T }
+    { _curx NCURSES_SIZE_T }
 
-    { "NCURSES_SIZE_T" "_maxy" }
-    { "NCURSES_SIZE_T" "_maxx" }
-    { "NCURSES_SIZE_T" "_begy" }
-    { "NCURSES_SIZE_T" "_begx" }
+    { _maxy NCURSES_SIZE_T }
+    { _maxx NCURSES_SIZE_T }
+    { _begy NCURSES_SIZE_T }
+    { _begx NCURSES_SIZE_T }
 
-    { "short"  " _flags" }
+    { _flags short  }
 
-    { "attr_t"  "_attrs" }
-    { "chtype"  "_bkgd" }
+    { _attrs attr_t  }
+    { _bkgd chtype  }
 
-    { "bool"    "_notimeout" }
-    { "bool"    "_clear" }
-    { "bool"    "_leaveok" }
-    { "bool"    "_scroll" }
-    { "bool"    "_idlok" }
-    { "bool"    "_idcok" }
-    { "bool"    "_immed" }
-    { "bool"    "_sync" }
-    { "bool"    "_use_keypad" }
-    { "int"     "_delay" }
+    { _notimeout bool    }
+    { _clear bool    }
+    { _leaveok bool    }
+    { _scroll bool    }
+    { _idlok bool    }
+    { _idcok bool    }
+    { _immed bool    }
+    { _sync bool    }
+    { _use_keypad bool    }
+    { _delay int     }
 
-    { "char*" "_line" }
-    { "NCURSES_SIZE_T" "_regtop" }
-    { "NCURSES_SIZE_T" "_regbottom" }
+    { _line char* }
+    { _regtop NCURSES_SIZE_T }
+    { _regbottom NCURSES_SIZE_T }
 
-    { "int" "_parx" }
-    { "int" "_pary" }
-    { "WINDOW*" "_parent" }
+    { _parx int }
+    { _pary int }
+    { _parent WINDOW* }
 
-    { "pdat" "_pad" }
+    { _pad pdat }
 
-    { "NCURSES_SIZE_T" "_yoffset" }
+    { _yoffset NCURSES_SIZE_T }
 
-    { "cchar_t"  "_bkgrnd" } ;
+    { _bkgrnd cchar_t  } ;
 
 LIBRARY: curses
 
index 1000bb9d71c9bcaac5401d1fbc6354e09ca032a0..c4d889991edf25be4e0b5184ee42dd9f9412a4d0 100644 (file)
@@ -3,7 +3,7 @@
 
 USING: kernel accessors sequences sequences.private destructors math namespaces
        locals openssl openssl.libcrypto byte-arrays bit-arrays.private
-       alien.c-types alien.destructors ;
+       alien.c-types alien.destructors alien.data ;
 
 IN: ecdsa
 
index c45475cefa30a9b81567e7232959c84e3f9e4f0b..6644596828bd3bb4da78523226b763af8aafcb39 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax kernel system combinators
-alien.libraries ;
+alien.libraries classes.struct ;
 IN: freetype
 
 << "freetype" {
@@ -23,7 +23,7 @@ TYPEDEF: ushort FT_UShort
 TYPEDEF: long FT_Long
 TYPEDEF: ulong FT_ULong
 TYPEDEF: uchar FT_Bool
-TYPEDEF: cell FT_Offset
+TYPEDEF: ulong FT_Offset
 TYPEDEF: int FT_PtrDist
 TYPEDEF: char FT_String
 TYPEDEF: int FT_Tag
@@ -41,130 +41,130 @@ FUNCTION: FT_Error FT_Init_FreeType ( void* library ) ;
 TYPEDEF: void face
 TYPEDEF: void glyph
 
-C-STRUCT: glyph
-    { "void*" "library" }
-    { "face*" "face" }
-    { "glyph*" "next" }
-    { "FT_UInt" "reserved" }
-    { "void*" "generic" }
-    { "void*" "generic" }
+STRUCT: glyph
+    { library void* }
+    { face face* }
+    { next glyph* }
+    { reserved FT_UInt }
+    { generic void* }
+    { generic2 void* }
 
-    { "FT_Pos" "width" }
-    { "FT_Pos" "height" }
+    { width FT_Pos }
+    { height FT_Pos }
 
-    { "FT_Pos" "hori-bearing-x" }
-    { "FT_Pos" "hori-bearing-y" }
-    { "FT_Pos" "hori-advance" }
+    { hori-bearing-x FT_Pos }
+    { hori-bearing-y FT_Pos }
+    { hori-advance FT_Pos }
 
-    { "FT_Pos" "vert-bearing-x" }
-    { "FT_Pos" "vert-bearing-y" }
-    { "FT_Pos" "vert-advance" }
+    { vert-bearing-x FT_Pos }
+    { vert-bearing-y FT_Pos }
+    { vert-advance FT_Pos }
 
-    { "FT_Fixed" "linear-hori-advance" }
-    { "FT_Fixed" "linear-vert-advance" }
-    { "FT_Pos" "advance-x" }
-    { "FT_Pos" "advance-y" }
+    { linear-hori-advance FT_Fixed }
+    { linear-vert-advance FT_Fixed }
+    { advance-x FT_Pos }
+    { advance-y FT_Pos }
 
-    { "intptr_t" "format" }
+    { format intptr_t }
 
-    { "int" "bitmap-rows" }
-    { "int" "bitmap-width" }
-    { "int" "bitmap-pitch" }
-    { "void*" "bitmap-buffer" }
-    { "short" "bitmap-num-grays" }
-    { "char" "bitmap-pixel-mode" }
-    { "char" "bitmap-palette-mode" }
-    { "void*" "bitmap-palette" }
+    { bitmap-rows int }
+    { bitmap-width int }
+    { bitmap-pitch int }
+    { bitmap-buffer void* }
+    { bitmap-num-grays short }
+    { bitmap-pixel-mode char }
+    { bitmap-palette-mode char }
+    { bitmap-palette void* }
 
-    { "FT_Int" "bitmap-left" }
-    { "FT_Int" "bitmap-top" }
+    { bitmap-left FT_Int }
+    { bitmap-top FT_Int }
 
-    { "short" "n-contours" }
-    { "short" "n-points" }
+    { n-contours short }
+    { n-points short }
 
-    { "void*" "points" }
-    { "char*" "tags" }
-    { "short*" "contours" }
+    { points void* }
+    { tags char* }
+    { contours short* }
 
-    { "int" "outline-flags" }
+    { outline-flags int }
 
-    { "FT_UInt" "num_subglyphs" }
-    { "void*" "subglyphs" }
+    { num_subglyphs FT_UInt }
+    { subglyphs void* }
 
-    { "void*" "control-data" }
-    { "long" "control-len" }
+    { control-data void* }
+    { control-len long }
 
-    { "FT_Pos" "lsb-delta" }
-    { "FT_Pos" "rsb-delta" }
+    { lsb-delta FT_Pos }
+    { rsb-delta FT_Pos }
 
-    { "void*" "other" } ;
+    { other void* } ;
 
-C-STRUCT: face-size
-    { "face*" "face" }
-    { "void*" "generic" }
-    { "void*" "generic" }
+STRUCT: face-size
+    { face face* }
+    { generic void* }
+    { generic2 void* }
 
-    { "FT_UShort" "x-ppem" }
-    { "FT_UShort" "y-ppem" }
+    { x-ppem FT_UShort }
+    { y-ppem FT_UShort }
 
-    { "FT_Fixed" "x-scale" }
-    { "FT_Fixed" "y-scale" }
+    { x-scale FT_Fixed }
+    { y-scale FT_Fixed }
 
-    { "FT_Pos" "ascender" }
-    { "FT_Pos" "descender" }
-    { "FT_Pos" "height" }
-    { "FT_Pos" "max-advance" } ;
+    { ascender FT_Pos }
+    { descender FT_Pos }
+    { height FT_Pos }
+    { max-advance FT_Pos } ;
 
-C-STRUCT: face
-    { "FT_Long" "num-faces" }
-    { "FT_Long" "index" }
+STRUCT: face
+    { num-faces FT_Long }
+    { index FT_Long }
 
-    { "FT_Long" "flags" }
-    { "FT_Long" "style-flags" }
+    { flags FT_Long }
+    { style-flags FT_Long }
 
-    { "FT_Long" "num-glyphs" }
+    { num-glyphs FT_Long }
 
-    { "FT_Char*" "family-name" }
-    { "FT_Char*" "style-name" }
+    { family-name FT_Char* }
+    { style-name FT_Char* }
 
-    { "FT_Int" "num-fixed-sizes" }
-    { "void*" "available-sizes" }
+    { num-fixed-sizes FT_Int }
+    { available-sizes void* }
 
-    { "FT_Int" "num-charmaps" }
-    { "void*" "charmaps" }
+    { num-charmaps FT_Int }
+    { charmaps void* }
 
-    { "void*" "generic" }
-    { "void*" "generic" }
+    { generic void* }
+    { generic2 void* }
 
-    { "FT_Pos" "x-min" }
-    { "FT_Pos" "y-min" }
-    { "FT_Pos" "x-max" }
-    { "FT_Pos" "y-max" }
+    { x-min FT_Pos }
+    { y-min FT_Pos }
+    { x-max FT_Pos }
+    { y-max FT_Pos }
 
-    { "FT_UShort" "units-per-em" }
-    { "FT_Short" "ascender" }
-    { "FT_Short" "descender" }
-    { "FT_Short" "height" }
+    { units-per-em FT_UShort }
+    { ascender FT_Short }
+    { descender FT_Short }
+    { height FT_Short }
 
-    { "FT_Short" "max-advance-width" }
-    { "FT_Short" "max-advance-height" }
+    { max-advance-width FT_Short }
+    { max-advance-height FT_Short }
 
-    { "FT_Short" "underline-position" }
-    { "FT_Short" "underline-thickness" }
+    { underline-position FT_Short }
+    { underline-thickness FT_Short }
 
-    { "glyph*" "glyph" }
-    { "face-size*" "size" }
-    { "void*" "charmap" } ;
+    { glyph glyph* }
+    { size face-size* }
+    { charmap void* } ;
 
-C-STRUCT: FT_Bitmap
-    { "int" "rows" }
-    { "int" "width" }
-    { "int" "pitch" }
-    { "void*" "buffer" }
-    { "short" "num_grays" }
-    { "char" "pixel_mode" }
-    { "char" "palette_mode" }
-    { "void*" "palette" } ;
+STRUCT: FT_Bitmap
+    { rows int }
+    { width int }
+    { pitch int }
+    { buffer void* }
+    { num_grays short }
+    { pixel_mode char }
+    { palette_mode char }
+    { palette void* } ;
 
 FUNCTION: FT_Error FT_New_Face ( void* library, FT_Char* font, FT_Long index, face* face ) ;
 
index 10e49984a1c63d5cb052493af8ca67799f1fc1de..d6c7456d63a9cf009201a7e0425f6d8750c71dde 100755 (executable)
@@ -7,6 +7,7 @@ io io.encodings.ascii io.files io.files.temp kernel math
 math.matrices math.parser math.vectors method-chains sequences
 splitting threads ui ui.gadgets ui.gadgets.worlds
 ui.pixel-formats specialized-arrays specialized-vectors ;
+FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-VECTOR: uint
 IN: gpu.demos.bunny
index 0ee9ab78c56c1a3f1d26fa9bbde031623fba0ca0..4f2437c0c1318f31e6e2740ae5b3577fa98565e2 100644 (file)
@@ -1,5 +1,5 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien alien.c-types arrays
+USING: accessors alien alien.c-types alien.data arrays
 assocs classes classes.mixin classes.parser classes.singleton
 classes.tuple classes.tuple.private combinators combinators.tuple destructors fry
 generic generic.parser gpu gpu.buffers gpu.framebuffers
@@ -9,7 +9,9 @@ lexer locals math math.order math.parser namespaces opengl
 opengl.gl parser quotations sequences slots sorting
 specialized-arrays strings ui.gadgets.worlds variants
 vocabs.parser words ;
-SPECIALIZED-ARRAY: float
+FROM: math => float ;
+QUALIFIED-WITH: alien.c-types c
+SPECIALIZED-ARRAY: c:float
 SPECIALIZED-ARRAY: int
 SPECIALIZED-ARRAY: uint
 SPECIALIZED-ARRAY: void*
index 91bc760673cec2d37fe4ba7eb60fe6825705c5f1..39c1792a1652aa1fdaf85c7b8abbeffb4881234a 100755 (executable)
@@ -1,11 +1,11 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien alien.c-types alien.strings arrays assocs
-byte-arrays classes.mixin classes.parser classes.singleton
-classes.struct combinators combinators.short-circuit definitions
-destructors generic.parser gpu gpu.buffers hashtables images
-io.encodings.ascii io.files io.pathnames kernel lexer literals
-locals math math.parser memoize multiline namespaces opengl
-opengl.gl opengl.shaders parser quotations sequences
+USING: accessors alien alien.c-types alien.data alien.strings
+arrays assocs byte-arrays classes.mixin classes.parser
+classes.singleton classes.struct combinators combinators.short-circuit
+definitions destructors generic.parser gpu gpu.buffers hashtables
+images io.encodings.ascii io.files io.pathnames kernel lexer
+literals locals math math.parser memoize multiline namespaces
+opengl opengl.gl opengl.shaders parser quotations sequences
 specialized-arrays splitting strings tr ui.gadgets.worlds
 variants vectors vocabs vocabs.loader vocabs.parser words
 words.constant ;
index 02d60467221bdd8de3a8fe0a0c85cfd785ebc759..1a840ea0b4305e5c22196cb15a668ef4676c3d66 100755 (executable)
@@ -1,9 +1,11 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien.c-types arrays byte-arrays combinators gpu
-kernel literals math math.rectangles opengl opengl.gl sequences
-variants specialized-arrays ;
+USING: accessors alien.c-types alien.data arrays byte-arrays
+combinators gpu kernel literals math math.rectangles opengl
+opengl.gl sequences variants specialized-arrays ;
+QUALIFIED-WITH: alien.c-types c
+FROM: math => float ;
 SPECIALIZED-ARRAY: int
-SPECIALIZED-ARRAY: float
+SPECIALIZED-ARRAY: c:float
 IN: gpu.state
 
 UNION: ?rect rect POSTPONE: f ;
index 8015ff9a9b7517e90e1b786b9cf8dd15807ecddd..2649f7c586607987e20e1543ca211790bcc3608f 100644 (file)
@@ -3,6 +3,7 @@ USING: accessors alien.c-types arrays byte-arrays combinators
 destructors fry gpu gpu.buffers images kernel locals math
 opengl opengl.gl opengl.textures sequences
 specialized-arrays ui.gadgets.worlds variants ;
+FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 IN: gpu.textures
 
index cf3d7d3690198c85cbdaf442bf463d82cb3d731a..d6b26cb129cfd2f39cdadc52aad03f4b3e027902 100644 (file)
@@ -1,5 +1,5 @@
-USING: alien.c-types alien.syntax half-floats kernel math tools.test
-specialized-arrays ;
+USING: accessors alien.c-types alien.syntax half-floats kernel
+math tools.test specialized-arrays alien.data classes.struct ;
 SPECIALIZED-ARRAY: half
 IN: half-floats.tests
 
@@ -9,7 +9,7 @@ IN: half-floats.tests
 [ HEX: be00 ] [ -1.5  half>bits ] unit-test
 [ HEX: 7c00 ] [  1/0. half>bits ] unit-test
 [ HEX: fc00 ] [ -1/0. half>bits ] unit-test
-[ HEX: 7eaa ] [ HEX: aaaaaaaaaaaaa <fp-nan> half>bits ] unit-test
+[ HEX: 7eaa ] [ NAN: aaaaaaaaaaaaa half>bits ] unit-test
 
 ! too-big floats overflow to infinity
 [ HEX: 7c00 ] [   65536.0 half>bits ] unit-test
@@ -30,18 +30,18 @@ IN: half-floats.tests
 [  3.0  ] [ HEX: 4200 bits>half ] unit-test
 [    t  ] [ HEX: 7e00 bits>half fp-nan? ] unit-test
 
-C-STRUCT: halves
-    { "half" "tom" }
-    { "half" "dick" }
-    { "half" "harry" }
-    { "half" "harry-jr" } ;
+STRUCT: halves
+    { tom half }
+    { dick half }
+    { harry half }
+    { harry-jr half } ;
 
-[ 8 ] [ "halves" heap-size ] unit-test
+[ 8 ] [ halves heap-size ] unit-test
 
 [ 3.0 ] [
-    "halves" <c-object>
-    3.0 over set-halves-dick
-    halves-dick
+    halves <struct>
+        3.0 >>dick
+    dick>>
 ] unit-test
 
 [ half-array{ 1.0 2.0 3.0 1/0. -1/0. } ]
index 2c089e4330308d3496ede384de6bef67b6131660..d0f6a090677dfc173c2f9cdcbd7fd2af29d1880d 100755 (executable)
@@ -1,5 +1,7 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien.c-types alien.syntax kernel math math.order ;
+USING: accessors alien.accessors alien.c-types alien.data
+alien.syntax kernel math math.order ;
+FROM: math => float ;
 IN: half-floats
 
 : half>bits ( float -- bits )
@@ -26,13 +28,18 @@ IN: half-floats
         ] unless
     ] bi bitor bits>float ;
 
-C-STRUCT: half { "ushort" "(bits)" } ;
+SYMBOL: half
 
 <<
 
-"half" c-type
-    [ half>bits <ushort> ] >>unboxer-quot
-    [ *ushort bits>half ] >>boxer-quot
-    drop
+<c-type>
+    float >>class
+    float >>boxed-class
+    [ alien-unsigned-2 bits>half ] >>getter
+    [ [ >float half>bits ] 2dip set-alien-unsigned-2 ] >>setter
+    2 >>size
+    2 >>align
+    [ >float ] >>unboxer-quot
+\ half define-primitive-type
 
 >>
index 63d0157780e3e1b9e7812b41df895fa1e98dde0a..1d1e217ba0ce9ee9102749da0c1366fcd8e6b49d 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax kernel sequences system ;
+USING: alien.syntax classes.struct kernel sequences system ;
 IN: io.serial.unix.termios
 
 CONSTANT: NCCS 20
@@ -9,11 +9,11 @@ TYPEDEF: uint tcflag_t
 TYPEDEF: uchar cc_t
 TYPEDEF: uint speed_t
 
-C-STRUCT: termios
-    { "tcflag_t" "iflag" }           !  input mode flags
-    { "tcflag_t" "oflag" }           !  output mode flags
-    { "tcflag_t" "cflag" }           !  control mode flags
-    { "tcflag_t" "lflag" }           !  local mode flags
-    { { "cc_t" NCCS } "cc" }         !  control characters
-    { "speed_t" "ispeed" }           !  input speed
-    { "speed_t" "ospeed" } ;         !  output speed
+STRUCT: termios
+    { iflag tcflag_t }
+    { oflag tcflag_t }
+    { cflag tcflag_t }
+    { lflag tcflag_t }
+    { cc { cc_t NCCS } }
+    { ispeed speed_t }
+    { ospeed speed_t } ;
index 4b8c52c7fb8d06f98e9163bcfa76b570881d49cc..0982339cf8994913072a4105f018ad86f858c191 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax kernel system unix ;
+USING: alien.syntax classes.struct kernel system unix ;
 IN: io.serial.unix.termios
 
 CONSTANT: NCCS 32
@@ -9,12 +9,12 @@ TYPEDEF: uchar cc_t
 TYPEDEF: uint speed_t
 TYPEDEF: uint tcflag_t
 
-C-STRUCT: termios
-    { "tcflag_t" "iflag" }           !  input mode flags
-    { "tcflag_t" "oflag" }           !  output mode flags
-    { "tcflag_t" "cflag" }           !  control mode flags
-    { "tcflag_t" "lflag" }           !  local mode flags
-    { "cc_t" "line" }                !  line discipline
-    { { "cc_t" NCCS } "cc" }         !  control characters
-    { "speed_t" "ispeed" }           !  input speed
-    { "speed_t" "ospeed" } ;         !  output speed
+STRUCT: termios
+    { iflag tcflag_t }
+    { oflag tcflag_t }
+    { cflag tcflag_t }
+    { lflag tcflag_t }
+    { line cc_t }
+    { cc { cc_t NCCS } }
+    { ispeed speed_t }
+    { ospeed speed_t } ;
index 1ba8031dfc25ec5e70693f701cc0a770008563ea..8ee115ca45f80df712b700fa06db2ddf4dbd01b0 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.syntax combinators io.ports
-io.streams.duplex system kernel math math.bitwise
-vocabs.loader unix io.serial io.serial.unix.termios io.backend.unix ;
+USING: accessors alien.c-types alien.syntax alien.data 
+classes.struct combinators io.ports io.streams.duplex
+system kernel math math.bitwise vocabs.loader unix io.serial
+io.serial.unix.termios io.backend.unix ;
 IN: io.serial.unix
 
 << {
@@ -40,19 +41,19 @@ M: unix open-serial ( serial -- serial' )
 
 : get-termios ( serial -- termios )
     serial-fd
-    "termios" <c-object> [ tcgetattr io-error ] keep ;
+    termios <struct> [ tcgetattr io-error ] keep ;
 
 : configure-termios ( serial -- )
     dup termios>>
     {
-        [ [ iflag>> ] dip over [ set-termios-iflag ] [ 2drop ] if ]
-        [ [ oflag>> ] dip over [ set-termios-oflag ] [ 2drop ] if ]
+        [ [ iflag>> ] dip over [ (>>iflag) ] [ 2drop ] if ]
+        [ [ oflag>> ] dip over [ (>>oflag) ] [ 2drop ] if ]
         [
             [
                 [ cflag>> 0 or ] [ baud>> lookup-baud ] bi bitor
-            ] dip set-termios-cflag
+            ] dip (>>cflag)
         ]
-        [ [ lflag>> ] dip over [ set-termios-lflag ] [ 2drop ] if ]
+        [ [ lflag>> ] dip over [ (>>lflag) ] [ 2drop ] if ]
     } 2cleave ;
 
 : tciflush ( serial -- )
index a591fe9ce0fcd8aab5fb8aaadcd7b44646d67d98..84510fb67e350d674ae0a5c8668c984ac3504368 100644 (file)
@@ -99,7 +99,13 @@ M: mb-writer dispose drop ;
 
 ! Test join
 [ { "JOIN #factortest" } [
-      "#factortest" %join %pop-output-line
+    "#factortest" %join %pop-output-line
+  ] unit-test
+] spawning-irc
+
+[ { "PART #factortest" } [
+    "#factortest" %join %pop-output-line drop
+    "#factortest" chat> remove-chat %pop-output-line
   ] unit-test
 ] spawning-irc
 
index 6ce851e7dd0137a758e981bb637189db1d8b0e73..ef1695f5634ed6a588a645f4c59dd8a2aa53a8c9 100644 (file)
@@ -172,7 +172,7 @@ M: irc-nick-chat remove-chat name>> unregister-chat ;
 M: irc-server-chat remove-chat drop +server-chat+ unregister-chat ;
 
 M: irc-channel-chat remove-chat
-    [ part new annotate-message irc-send ]
+    [ name>> "PART " prepend string>irc-message irc-send ]
     [ name>> unregister-chat ] bi ;
 
 : (speak) ( message irc-chat -- ) swap annotate-message irc-send ;
index 1a03a2c9413fecfb786690d93bf79a04400e7882..60e9e39d9f5abf8d3611841355eedb5e683b3a24 100644 (file)
@@ -4,6 +4,7 @@ USING: accessors alien.c-types jamshred.game jamshred.oint
 jamshred.player jamshred.tunnel kernel math math.constants
 math.functions math.vectors opengl opengl.gl opengl.glu
 opengl.demo-support sequences specialized-arrays ;
+FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 IN: jamshred.gl
 
index 46729c42be6c392751d2e5c30a62bebe993e92e4..a5602273d2b0017ab378537258215a503bfed548 100644 (file)
@@ -1,5 +1,5 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien alien.c-types destructors kernel libc math ;
+USING: accessors alien alien.c-types alien.data destructors kernel libc math ;
 IN: memory.piles
 
 TUPLE: pile
index 81a6621eff5180d9c4fff499887b407df83ef5e8..bccdec14200a1da41e422bb7b90595380660fdd3 100644 (file)
@@ -4,6 +4,7 @@ USING: kernel accessors arrays alien system combinators
 alien.syntax namespaces alien.c-types sequences vocabs.loader
 shuffle openal.backend alien.libraries generalizations
 specialized-arrays ;
+FROM: alien.c-types => float short ;
 SPECIALIZED-ARRAY: uint
 IN: openal
 
index d0567bdd48bbb1e19cabc01eeefd773f492205a1..b573cd51aba2d09c04b67a71073c63ac409427c5 100644 (file)
@@ -1,4 +1,5 @@
-USING: classes.struct cocoa core-foundation.strings ;
+USING: classes.struct cocoa cocoa.application cocoa.classes
+cocoa.enumeration cocoa.plists core-foundation.strings kernel ;
 IN: qtkit
 
 STRUCT: QTTime
@@ -74,3 +75,19 @@ IMPORT: QTMovieView
 IMPORT: QTSampleBuffer
 IMPORT: QTTrack
 
+: <movie> ( filename -- movie )
+    QTMovie swap <NSString> f -> movieWithFile:error: -> retain ;
+
+: movie-attributes ( movie -- attributes )
+    -> movieAttributes plist> ;
+
+: play ( movie -- )
+    -> play ;
+: stop ( movie -- )
+    -> stop ;
+
+: movie-tracks ( movie -- tracks )
+    -> tracks NSFastEnumeration>vector ;
+
+: track-attributes ( track -- attributes )
+    -> trackAttributes plist> ;
index 32ceb3b677cce28f676438adbd24756bc00630c3..af37580ff268863b815b3beac23141b3751c9b9b 100755 (executable)
@@ -19,10 +19,14 @@ CONSTANT: stylesheet
                 { wrap-margin 1100 }
             }
         }
-        { code-style
+        { code-char-style
             H{
                 { font-name "monospace" }
                 { font-size 36 }
+            }
+        }
+        { code-style
+            H{
                 { page-color T{ rgba f 0.4 0.4 0.4 0.3 } }
             }
         }
@@ -101,6 +105,7 @@ SYNTAX: STRIP-TEASE:
     { T{ button-down } [ request-focus ] }
     { T{ key-down f f "DOWN" } [ next-page ] }
     { T{ key-down f f "UP" } [ prev-page ] }
+    { T{ key-down f f "f" } [ dup fullscreen? not set-fullscreen ] }
 } set-gestures
 
 : slides-window ( slides -- )
index 71b05ac6421f2813af784a4a7012fffae3ea22ab..978fb32d423492a5c7afd22192f3b616648415ad 100644 (file)
@@ -2,6 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types combinators kernel locals math
 math.ranges openal sequences sequences.merged specialized-arrays ;
+FROM: alien.c-types => short ;
 SPECIALIZED-ARRAY: uchar
 SPECIALIZED-ARRAY: short
 IN: synth.buffers
index 13c7cb9433b19f4c81e1aa3efc6d7ef08e8dfc8c..8c4f81a11701369a9aa7f8b1b63e7d4a7e7a1b5e 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types system-info kernel math namespaces
+USING: alien.c-types alien.data system-info kernel math namespaces
 windows windows.kernel32 system-info.backend system ;
 IN: system-info.windows.ce
 
index 3ff3bc642851c8b257d23f4903991deffc062385..0450e6522c5e963bb5b45ac48ed3a0e6f6d2e6f0 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.libraries alien.syntax
 combinators kernel system tokyo.alien.tchdb tokyo.alien.tcutil
-tokyo.alien.tctdb ;
+tokyo.alien.tctdb classes.struct ;
 IN: tokyo.alien.tcrdb
 
 << "tokyotyrant" {
@@ -14,16 +14,16 @@ IN: tokyo.alien.tcrdb
 LIBRARY: tokyotyrant
 
 TYPEDEF: void* TCRDB*
-! C-STRUCT: TCRDB
-!     { "pthread_mutex_t" mmtx }
-!     { "pthread_key_t" eckey }
-!     { "char*" host }
-!     { "int" port }
-!     { "char*" expr }
-!     { "int" fd }
-!     { "TTSOCK*" sock }
-!     { "double" timeout }
-!     { "int" opts } ;
+! STRUCT: TCRDB
+!     { mmtx pthread_mutex_t }
+!     { eckey pthread_key_t }
+!     { host char* }
+!     { port int }
+!     { expr char* }
+!     { fd int }
+!     { sock TTSOCK* }
+!     { timeout double }
+!     { opts int } ;
 
 C-ENUM:
     TTESUCCESS
@@ -96,9 +96,9 @@ CONSTANT: RDBITVOID    TDBITVOID
 CONSTANT: RDBITKEEP    TDBITKEEP
 
 TYPEDEF: void* RDBQRY*
-! C-STRUCT: RDBQRY
-!     { "TCRDB*" rdb }
-!     { "TCLIST*" args } ;
+! STRUCT: RDBQRY
+!     { rdb TCRDB* }
+!     { args TCLIST* } ;
 
 CONSTANT: RDBQCSTREQ   TDBQCSTREQ
 CONSTANT: RDBQCSTRINC  TDBQCSTRINC
index 207ae9ab345a3fac1d1bbb477e259b5f876f57ba..b5a29073cdb25126ef936bd6fc610011d8c54244 100644 (file)
@@ -91,7 +91,10 @@ SYMBOL: dh-file
 : init-production ( -- )
     common-configuration
     <vhost-dispatcher>
-        <factor-website> <wiki> <login-config> <factor-boilerplate> "wiki" add-responder test-db <alloy> "concatenative.org" add-responder
+        <factor-website>
+            <wiki> "wiki" add-responder
+            <user-admin> "user-admin" add-responder
+        <login-config> <factor-boilerplate> test-db <alloy> "concatenative.org" add-responder
         <pastebin> <login-config> <factor-boilerplate> test-db <alloy> "paste.factorcode.org" add-responder
         <planet> <login-config> <factor-boilerplate> test-db <alloy> "planet.factorcode.org" add-responder
         home "docs" append-path <help-webapp> test-db <alloy> "docs.factorcode.org" add-responder