"If this condition is not satisfied, " { $link "malloc" } " must be used instead."
{ $warning "Failure to comply with these requirements can lead to crashes, data corruption, and security exploits." } ;
-ARTICLE: "c-out-params" "Output parameters in C"
-"A frequently-occurring idiom in C code is the \"out parameter\". If a C function returns more than one value, the caller passes pointers of the correct type, and the C function writes its return values to those locations."
-$nl
-"To wrap Factor data for consumption by the FFI, we use a utility word that constructs a byte array of the correct size and converts the Factor object to a C value stored into that byte array:"
-{ $subsections <ref> }
-"You call the out parameter constructor with the required initial value, then pass the byte array to the C function, which receives a pointer to the start of the byte array's data area. The C function then returns, leaving the result in the byte array; you read it back using this word:"
-{ $subsections deref } ;
-
ARTICLE: "c-types.primitives" "Primitive C types"
"The following numerical types are defined in the " { $vocab-link "alien.c-types" } " vocabulary; a " { $snippet "u" } " prefix denotes an unsigned type:"
{ $table
[ 492 ] [ { int xyz } heap-size ] unit-test
-[ -1 ] [ -1 char <ref> char deref ] unit-test
-[ -1 ] [ -1 short <ref> short deref ] unit-test
-[ -1 ] [ -1 int <ref> int deref ] unit-test
-
-! I don't care if this throws an error or works, but at least
-! it should be consistent between platforms
-[ -1 ] [ -1.0 int <ref> int deref ] unit-test
-[ -1 ] [ -1.0 long <ref> long deref ] unit-test
-[ -1 ] [ -1.0 longlong <ref> longlong deref ] unit-test
-[ 1 ] [ 1.0 uint <ref> uint deref ] unit-test
-[ 1 ] [ 1.0 ulong <ref> ulong deref ] unit-test
-[ 1 ] [ 1.0 ulonglong <ref> ulonglong deref ] unit-test
-
UNION-STRUCT: foo
{ a int }
{ b int } ;
[ t ] [ void* c-type MyIntArray c-type = ] unit-test
-[
- 0 B{ 1 2 3 4 } <displaced-alien> void* <ref>
-] must-fail
-
-os windows? cpu x86.64? and [
- [ -2147467259 ] [ 2147500037 long <ref> long deref ] unit-test
-] when
-
[ 0 ] [ -10 uchar c-type-clamp ] unit-test
[ 12 ] [ 12 uchar c-type-clamp ] unit-test
[ -10 ] [ -10 char c-type-clamp ] unit-test
: c-type-clamp ( value c-type -- value' )
dup { float double } member-eq?
[ drop ] [ c-type-interval clamp ] if ; inline
-
-: <ref> ( value c-type -- c-ptr )
- [ heap-size <byte-array> ] keep
- '[ 0 _ set-alien-value ] keep ; inline
-
-: deref ( c-ptr c-type -- value )
- [ 0 ] dip alien-value ; inline
-
-: little-endian? ( -- ? ) 1 int <ref> char deref 1 = ; foldable
{ $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." } ;
-
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." } ;
{ $warning
"The Factor garbage collector can move byte arrays around, and code passing byte arrays, or objects backed by byte arrays, must obey important guidelines. See " { $link "byte-arrays-gc" } "." } ;
+ARTICLE: "c-boxes" "C value boxes"
+"Sometimes it is useful to create a byte array storing a single C value, like a struct with a single field. A pair of utility macros exist to make this more convenient:"
+{ $subsections <ref> deref } ;
+
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
"malloc"
"c-strings"
"c-out-params"
+ "c-boxes"
}
"Important guidelines for passing data in byte arrays:"
{ $subsections "byte-arrays-gc" }
"C-style enumerated types are supported:"
-{ $subsections "alien.enums" POSTPONE: ENUM: }
-"C types can be aliased for convenience and consistency with native library documentation:"
-{ $subsections POSTPONE: TYPEDEF: }
+{ $subsections "alien.enums" }
"A utility for defining " { $link "destructors" } " for deallocating memory:"
{ $subsections "alien.destructors" }
"C struct and union types can be defined with " { $link POSTPONE: STRUCT: } " and " { $link POSTPONE: UNION: } ". See " { $link "classes.struct" } " for details. For passing arrays to and from C, use the " { $link "specialized-arrays" } " vocabulary." ;
{ $subsections alien>string }
"For example, if a C function returns a " { $link c-string } " but stipulates that the caller must deallocate the memory afterward, you must define the function as returning " { $snippet "char*" } " and call " { $link (free) } " yourself." ;
+HELP: <ref>
+{ $values { "c-type" "a C type" } }
+{ $description "Creates a new byte array to store a Factor object as a C value." }
+{ $examples
+ { $example "USING: alien.c-types alien.data prettyprint sequences ;" "123 int <ref> length ." "4" }
+} ;
+
+HELP: deref
+{ $values { "c-type" "a C type" } }
+{ $description "Loads a C value from a byte array." }
+{ $examples
+ { $example "USING: alien.c-types alien.data prettyprint sequences ;" "321 int <ref> int deref ." "321" }
+} ;
+
+ARTICLE: "c-out-params" "Output parameters in C"
+"A frequently-occurring idiom in C code is the \"out parameter\". If a C function returns more than one value, the caller passes pointers of the correct type, and the C function writes its return values to those locations."
+{ $subsection with-out-parameters } ;
specialized-arrays.private tools.test compiler.units vocabs ;
IN: alien.data.tests
+
+[ -1 ] [ -1 char <ref> char deref ] unit-test
+[ -1 ] [ -1 short <ref> short deref ] unit-test
+[ -1 ] [ -1 int <ref> int deref ] unit-test
+
+! I don't care if this throws an error or works, but at least
+! it should be consistent between platforms
+[ -1 ] [ -1.0 int <ref> int deref ] unit-test
+[ -1 ] [ -1.0 long <ref> long deref ] unit-test
+[ -1 ] [ -1.0 longlong <ref> longlong deref ] unit-test
+[ 1 ] [ 1.0 uint <ref> uint deref ] unit-test
+[ 1 ] [ 1.0 ulong <ref> ulong deref ] unit-test
+[ 1 ] [ 1.0 ulonglong <ref> ulonglong deref ] unit-test
+
+[
+ 0 B{ 1 2 3 4 } <displaced-alien> void* <ref>
+] must-fail
+
+os windows? cpu x86.64? and [
+ [ -2147467259 ] [ 2147500037 long <ref> long deref ] unit-test
+] when
+
STRUCT: foo { a int } { b void* } { c bool } ;
SPECIALIZED-ARRAY: foo
QUALIFIED: math
IN: alien.data
+: <ref> ( value c-type -- c-ptr )
+ [ heap-size <byte-array> ] keep
+ '[ 0 _ set-alien-value ] keep ; inline
+
+: deref ( c-ptr c-type -- value )
+ [ 0 ] dip alien-value ; inline
+
+: little-endian? ( -- ? ) 1 int <ref> char deref 1 = ; foldable
+
GENERIC: require-c-array ( c-type -- )
M: array require-c-array first require-c-array ;
: malloc-array ( n type -- array )
[ 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-byte-array ( byte-array -- alien )
binary-object [ nip malloc dup ] 2keep memcpy ;
}
{ $description "Convert a number to an enum." } ;
-ARTICLE: "alien.enums" "Enumeration types"
-"The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link POSTPONE: ENUM: } " C types, and provides words for converting between enum singletons and integers. It is possible to dispatch off of members of an enum."
-$nl
-"Defining enums at run-time:"
-{ $subsection define-enum }
-"Conversions between enums and integers:"
-{ $subsections enum>number number>enum } ;
-
{ POSTPONE: ENUM: define-enum enum>number number>enum } related-words
ABOUT: "alien.enums"
GENERIC: (<fortran-result>) ( type -- quot )
M: fortran-type (<fortran-result>)
- (fortran-type>c-type) \ <c-object> [ ] 2sequence ;
+ (fortran-type>c-type) \ heap-size \ <byte-array> [ ] 3sequence ;
M: character-type (<fortran-result>)
fix-character-type dims>> product dup
{ $syntax "C-GLOBAL: type name" }
{ $values { "type" "a C type" } { "name" "a C global variable name" } }
{ $description "Defines a new word named " { $snippet "name" } " which accesses a global variable in the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
+
+ARTICLE: "alien.enums" "Enumeration types"
+"The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link POSTPONE: ENUM: } " C types, and provides words for converting between enum singletons and integers. It is possible to dispatch off of members of an enum."
+$nl
+"Defining enums:"
+{ $subsection POSTPONE: ENUM: }
+"Defining enums at run-time:"
+{ $subsection define-enum }
+"Conversions between enums and integers:"
+{ $subsections enum>number number>enum } ;
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.syntax arrays calendar
-kernel math unix unix.time unix.types namespaces system
+USING: alien alien.c-types alien.data alien.syntax arrays
+calendar kernel math unix unix.time unix.types namespaces system
accessors classes.struct ;
IN: calendar.unix
! Copyright (C) 2006, 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel io io.binary io.files io.streams.byte-array math
-math.functions math.parser namespaces splitting grouping strings
-sequences byte-arrays locals sequences.private macros fry
-io.encodings.binary math.bitwise checksums accessors
-checksums.common checksums.stream combinators combinators.smart
-specialized-arrays literals hints ;
+USING: alien.c-types alien.data kernel io io.binary io.files
+io.streams.byte-array math math.functions math.parser namespaces
+splitting grouping strings sequences byte-arrays locals
+sequences.private macros fry io.encodings.binary math.bitwise
+checksums accessors checksums.common checksums.stream
+combinators combinators.smart specialized-arrays literals hints ;
SPECIALIZED-ARRAY: uint
IN: checksums.md5
sequences tools.test 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
+make alien.c-types alien.data combinators.short-circuit math.order
math.libm math.parser math.functions alien.syntax memory
stack-checker ;
FROM: math => float ;
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.syntax byte-arrays combinators
-kernel math math.functions sequences system accessors
-libc ;
+USING: alien alien.c-types alien.data alien.syntax byte-arrays
+combinators kernel math math.functions sequences system
+accessors libc ;
QUALIFIED: compression.zlib.ffi
IN: compression.zlib
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.syntax kernel math core-foundation ;
+USING: alien.c-types alien.data alien.syntax kernel math
+core-foundation ;
FROM: math => float ;
IN: core-foundation.numbers
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.destructors alien.syntax accessors
-destructors fry kernel math math.bitwise sequences libc colors
-images images.memory core-graphics.types core-foundation.utilities
-opengl.gl literals ;
+USING: alien alien.c-types alien.data alien.destructors
+alien.syntax accessors destructors fry kernel math math.bitwise
+sequences libc colors images images.memory core-graphics.types
+core-foundation.utilities opengl.gl literals ;
IN: core-graphics
TYPEDEF: int CGImageAlphaInfo
! Copyright (C) 2009, 2010 Joe Groff, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types arrays assocs combinators fry kernel locals
+USING: alien.data arrays assocs combinators fry kernel locals
macros math math.vectors namespaces quotations sequences system
compiler.cfg.comparisons compiler.cfg.intrinsics
compiler.codegen.fixup cpu.architecture cpu.x86
! Copyright (C) 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types combinators kernel locals system namespaces
-compiler.codegen.fixup compiler.constants
+USING: alien.c-types alien.data combinators kernel locals system
+namespaces compiler.codegen.fixup compiler.constants
compiler.cfg.comparisons compiler.cfg.intrinsics
cpu.architecture cpu.x86 cpu.x86.assembler
cpu.x86.assembler.operands ;
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types namespaces io.binary fry
+USING: alien.c-types alien.data namespaces io.binary fry
kernel math grouping sequences math.bitwise ;
IN: endian
-USING: accessors alien alien.c-types alien.strings arrays assocs
-byte-arrays combinators combinators.short-circuit continuations
-game.input game.input.dinput.keys-array io.encodings.utf16
-io.encodings.utf16n kernel locals math math.bitwise
-math.rectangles namespaces parser sequences shuffle
+USING: accessors alien alien.c-types alien.data alien.strings
+arrays assocs byte-arrays combinators combinators.short-circuit
+continuations game.input game.input.dinput.keys-array
+io.encodings.utf16 io.encodings.utf16n kernel locals math
+math.bitwise math.rectangles namespaces parser sequences shuffle
specialized-arrays ui.backend.windows vectors windows.com
windows.directx.dinput windows.directx.dinput.constants
windows.kernel32 windows.messages windows.ole32 windows.errors
-windows.user32 classes.struct alien.data ;
+windows.user32 classes.struct ;
SPECIALIZED-ARRAY: DIDEVICEOBJECTDATA
IN: game.input.dinput
! Copyright (C) 2004, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel bit-arrays sequences assocs math
+USING: alien.data kernel bit-arrays sequences assocs math
namespaces accessors math.order locals fry io.ports
io.backend.unix io.backend.unix.multiplexers unix unix.ffi
unix.time ;
! Copyright (C) 2004, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.syntax generic assocs kernel
-kernel.private math io.ports sequences strings sbufs threads
-unix unix.ffi vectors io.buffers io.backend io.encodings math.parser
-continuations system libc namespaces make io.timeouts
-io.encodings.utf8 destructors destructors.private accessors
-summary combinators locals unix.time unix.types fry
-io.backend.unix.multiplexers ;
+USING: alien alien.c-types alien.data alien.syntax generic
+assocs kernel kernel.private math io.ports sequences strings
+sbufs threads unix unix.ffi vectors io.buffers io.backend
+io.encodings math.parser continuations system libc namespaces
+make io.timeouts io.encodings.utf8 destructors
+destructors.private accessors summary combinators locals
+unix.time unix.types fry io.backend.unix.multiplexers ;
QUALIFIED: io
IN: io.backend.unix
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types io.directories.unix kernel system unix
-classes.struct unix.ffi ;
+USING: alien.c-types alien.data io.directories.unix kernel
+system unix classes.struct unix.ffi ;
IN: io.directories.unix.linux
M: linux find-next-file ( DIR* -- dirent )
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings combinators
-continuations destructors fry io io.backend io.backend.unix
-io.directories io.encodings.binary io.encodings.utf8 io.files
-io.pathnames io.files.types kernel math.bitwise sequences system
-unix unix.stat vocabs.loader classes.struct unix.ffi literals ;
+USING: accessors alien.c-types alien.data alien.strings
+combinators continuations destructors fry io io.backend
+io.backend.unix io.directories io.encodings.binary
+io.encodings.utf8 io.files io.pathnames io.files.types kernel
+math.bitwise sequences system unix unix.stat vocabs.loader
+classes.struct unix.ffi literals ;
IN: io.directories.unix
CONSTANT: touch-mode flags{ O_WRONLY O_APPEND O_CREAT O_EXCL }
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings combinators
-grouping io.encodings.utf8 io.files kernel math sequences system
-unix io.files.unix arrays unix.statfs.macosx unix.statvfs.macosx
-unix.getfsstat.macosx io.files.info.unix io.files.info
-classes.struct specialized-arrays ;
+USING: accessors alien.c-types alien.data alien.strings
+combinators grouping io.encodings.utf8 io.files kernel math
+sequences system unix io.files.unix arrays unix.statfs.macosx
+unix.statvfs.macosx unix.getfsstat.macosx io.files.info.unix
+io.files.info classes.struct specialized-arrays ;
SPECIALIZED-ARRAY: uint
SPECIALIZED-ARRAY: statfs64
IN: io.files.info.unix.macosx
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.data alien.strings
-alien.syntax arrays assocs classes.struct combinators
-combinators.short-circuit continuations destructors environment
-io io.backend io.binary io.buffers
+USING: accessors alien alien.data alien.c-types alien.data
+alien.strings alien.syntax arrays assocs classes.struct
+combinators combinators.short-circuit continuations destructors
+environment io io.backend io.binary io.buffers
io.encodings.utf16n io.files io.files.private io.files.types
io.pathnames io.ports io.streams.c io.streams.null io.timeouts
kernel libc literals locals make math math.bitwise namespaces
-sequences specialized-arrays system
-threads tr windows windows.errors windows.handles
-windows.kernel32 windows.shell32 windows.time windows.types ;
+sequences specialized-arrays system threads tr windows
+windows.errors windows.handles windows.kernel32 windows.shell32
+windows.time windows.types ;
SPECIALIZED-ARRAY: ushort
IN: io.files.windows
[ handle>> handle>> ]
[ buffer>> ]
[ buffer>> buffer-length ]
- [ drop DWORD <c-object> ]
+ [ drop 0 DWORD <ref> ]
[ FileArgs-overlapped ]
} cleave <FileArgs> ;
{ void* }\r
[\r
void* heap-size\r
- DWORD <c-object>\r
+ 0 DWORD <ref>\r
f\r
f\r
WSAIoctl SOCKET_ERROR = [\r
! 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.data alien.strings libc opengl math sequences combinators
-macros arrays io.encodings.ascii fry specialized-arrays
-destructors accessors ;
+assocs alien alien.data alien.strings libc opengl math sequences
+combinators macros arrays io.encodings.ascii fry
+specialized-arrays destructors accessors ;
SPECIALIZED-ARRAY: uint
IN: opengl.shaders
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs byte-arrays
-byte-vectors combinators fry io.backend io.binary kernel locals
-math math.bitwise math.constants math.functions math.order
-math.ranges namespaces sequences sets summary system
+USING: accessors alien.c-types alien.data arrays assocs
+byte-arrays byte-vectors combinators fry io.backend io.binary
+kernel locals math math.bitwise math.constants math.functions
+math.order math.ranges namespaces sequences sets summary system
vocabs.loader ;
IN: random
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types kernel locals math math.ranges
-math.bitwise math.vectors math.vectors.simd random
+USING: accessors alien.c-types alien.data kernel locals math
+math.ranges math.bitwise math.vectors math.vectors.simd random
sequences specialized-arrays sequences.private classes.struct
combinators.short-circuit fry ;
SPECIALIZED-ARRAY: uint
}
"Finally, sometimes a C library returns a pointer to an array in unmanaged memory, together with a length. In this case, a specialized array can be constructed to view this memory using " { $snippet "<direct-T-array>" } ":"
{ $code
- "USING: alien.c-types classes.struct ;"
+ "USING: alien.c-types alien.data classes.struct ;"
""
"STRUCT: device_info"
" { id int }"
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings alien.syntax
+USING: alien alien.c-types alien.data alien.strings alien.syntax
byte-arrays kernel namespaces sequences unix
system-info.backend system io.encodings.utf8 ;
IN: system-info.macosx
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.strings byte-arrays
-classes.struct combinators kernel math namespaces
-specialized-arrays system
-system-info.backend vocabs.loader windows windows.advapi32
-windows.errors windows.kernel32 words ;
+USING: accessors alien alien.c-types alien.data alien.strings
+byte-arrays classes.struct combinators kernel math namespaces
+specialized-arrays system system-info.backend vocabs.loader
+windows windows.advapi32 windows.errors windows.kernel32 words ;
SPECIALIZED-ARRAY: ushort
IN: system-info.windows
$nl
"Off by default."
$nl
-"The optimizing compiler is able to fold away calls to various words which take a C type as an input if the C type is a literal string:"
+"The optimizing compiler is able to fold away calls to various words which take a C type as an input if the C type is a literal string, for example,"
{ $list
{ $link c-type }
{ $link heap-size }
- { $link <c-object> }
{ $link <c-array> }
+ { $link <c-direct-array> }
{ $link malloc-array }
+ { $link <ref> }
+ { $link deref }
}
"If your program looks up C types dynamically or from words which do not have a stack effect, you must enable this flag, because in these situations the C type lookup code is not folded away and the word properties must be consulted at runtime." } ;
! Copyright (C) 2005, 2006 Doug Coleman.
! Portions copyright (C) 2007, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings arrays assocs ui
+USING: alien alien.data alien.strings arrays assocs ui
ui.private ui.gadgets ui.gadgets.private ui.backend
ui.clipboards ui.gadgets.worlds ui.gestures ui.event-loop io
kernel math math.vectors namespaces make sequences strings
-vectors words windows.dwmapi system-info.windows windows.kernel32
-windows.gdi32 windows.user32 windows.opengl32 windows.messages
-windows.types windows.offscreen windows threads libc combinators
-fry combinators.short-circuit continuations command-line shuffle
-opengl ui.render math.bitwise locals accessors math.rectangles
-math.order calendar ascii sets io.encodings.utf16n
-windows.errors literals ui.pixel-formats
+vectors words windows.dwmapi system-info.windows
+windows.kernel32 windows.gdi32 windows.user32 windows.opengl32
+windows.messages windows.types windows.offscreen windows threads
+libc combinators fry combinators.short-circuit continuations
+command-line shuffle 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 colors
-specialized-arrays classes.struct alien.data ;
+specialized-arrays classes.struct ;
FROM: namespaces => set ;
SPECIALIZED-ARRAY: POINT
QUALIFIED-WITH: alien.c-types c
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.strings assocs
-byte-arrays classes.struct combinators
+USING: accessors alien alien.c-types alien.data alien.strings
+assocs byte-arrays classes.struct combinators
combinators.short-circuit continuations fry io.backend.unix
io.encodings.utf8 kernel math math.parser namespaces sequences
splitting strings unix unix.ffi unix.users unix.utilities ;
TYPEDEF: ulonglong __fsfilcnt64_t
TYPEDEF: ulonglong ino64_t
TYPEDEF: ulonglong off64_t
-
-: <time_t> ( n -- long ) long <ref> ;
USING: kernel windows.com windows.com.syntax windows.ole32
-windows.types alien alien.syntax tools.test libc alien.c-types
-namespaces arrays continuations accessors math windows.com.wrapper
-windows.com.wrapper.private destructors effects compiler.units ;
+windows.types alien alien.data alien.syntax tools.test libc
+alien.c-types namespaces arrays continuations accessors math
+windows.com.wrapper windows.com.wrapper.private destructors
+effects compiler.units ;
IN: windows.com.tests
COM-INTERFACE: ISimple IUnknown {216fb341-0eb2-44b1-8edb-60b76e353abc}
! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.syntax
+USING: accessors alien alien.c-types alien.data alien.syntax
classes.struct io.encodings.string io.encodings.utf8 kernel
make sequences windows.errors windows.types ;
IN: windows.iphlpapi
CONSTANT: registry-value-max-length 16384
:: open-key ( key subkey mode -- hkey )
- key subkey 0 mode HKEY <c-object>
+ key subkey 0 mode 0 HKEY <ref>
[
RegOpenKeyEx dup ERROR_SUCCESS = [
drop
[ key subkey mode ] dip n>win32-error-string
open-key-failed
] if
- ] keep uint deref ;
+ ] keep HKEY deref ;
:: create-key* ( hKey lpSubKey lpClass dwOptions samDesired lpSecurityAttributes -- hkey new? )
- hKey lpSubKey 0 lpClass dwOptions samDesired lpSecurityAttributes
- HKEY <c-object>
- DWORD <c-object>
f :> ret!
+ hKey lpSubKey 0 lpClass dwOptions samDesired lpSecurityAttributes
+ 0 HKEY <ref>
+ 0 DWORD <ref>
[ RegCreateKeyEx ret! ] 2keep
- [ uint deref ]
- [ uint deref REG_CREATED_NEW_KEY = ] bi*
+ [ HKEY deref ]
+ [ DWORD deref REG_CREATED_NEW_KEY = ] bi*
ret ERROR_SUCCESS = [
[
hKey lpSubKey 0 lpClass dwOptions samDesired
registry-value-max-length TCHAR <c-array> dup :> registry-value
registry-value length dup :> registry-value-length
f
- DWORD <c-object> dup :> type
- f ! BYTE <c-object> dup :> data
- f ! BYTE <c-object> dup :> buffer
+ 0 DWORD <ref> dup :> type
+ f ! 0 BYTE <ref> dup :> data
+ f ! 0 BYTE <ref> dup :> buffer
RegEnumKeyEx dup ERROR_SUCCESS = [
] [
dup TCHAR <c-array> dup :> class-buffer
swap int <ref> dup :> class-buffer-length
f
- DWORD <c-object> dup :> sub-keys
- DWORD <c-object> dup :> longest-subkey
- DWORD <c-object> dup :> longest-class-string
- DWORD <c-object> dup :> #values
- DWORD <c-object> dup :> max-value
- DWORD <c-object> dup :> max-value-data
- DWORD <c-object> dup :> security-descriptor
+ 0 DWORD <ref> dup :> sub-keys
+ 0 DWORD <ref> dup :> longest-subkey
+ 0 DWORD <ref> dup :> longest-class-string
+ 0 DWORD <ref> dup :> #values
+ 0 DWORD <ref> dup :> max-value
+ 0 DWORD <ref> dup :> max-value-data
+ 0 DWORD <ref> dup :> security-descriptor
FILETIME <struct> dup :> last-write-time
RegQueryInfoKey :> ret
ret ERROR_SUCCESS = [
! Copyright (C) 2006, 2010 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings classes.struct
-io.encodings.utf8 kernel namespaces sequences
+USING: accessors alien.c-types alien.data alien.strings
+classes.struct io.encodings.utf8 kernel namespaces sequences
specialized-arrays x11 x11.constants x11.xlib ;
SPECIALIZED-ARRAY: int
IN: x11.clipboard
! Copyright (C) 2005, 2010 Eduardo Cavazos, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types kernel math math.bitwise
-math.vectors namespaces sequences arrays fry classes.struct
-literals x11 x11.xlib x11.constants x11.events x11.glx ;
+USING: accessors alien.c-types alien.data kernel math
+math.bitwise math.vectors namespaces sequences arrays fry
+classes.struct literals x11 x11.xlib x11.constants x11.events
+x11.glx ;
IN: x11.windows
CONSTANT: create-window-mask
! Copyright (C) 2007, 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings arrays byte-arrays
-hashtables io io.encodings.string kernel math namespaces
-sequences strings continuations x11 x11.xlib
+USING: alien alien.c-types alien.data alien.strings arrays
+byte-arrays hashtables io io.encodings.string kernel math
+namespaces sequences strings continuations x11 x11.xlib
specialized-arrays accessors io.encodings.utf16n ;
SPECIALIZED-ARRAY: uint
IN: x11.xim
! Copyright (C) 2010 Niklas Waern.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types combinators kernel namespaces x11
-x11.constants x11.xinput2.ffi ;
+USING: alien.c-types alien.data combinators kernel namespaces
+x11 x11.constants x11.xinput2.ffi ;
IN: x11.xinput2
: (xi2-available?) ( display -- ? )
! (c)2010 Joe Groff bsd license
-USING: alien alien.c-types alien.libraries alien.strings
-alien.syntax combinators destructors io.encodings.ascii kernel
-libc locals sequences system ;
+USING: alien alien.c-types alien.data alien.libraries
+alien.strings alien.syntax combinators destructors
+io.encodings.ascii kernel libc locals sequences system ;
IN: alien.cxx.demangle.libstdcxx
FUNCTION: char* __cxa_demangle ( char* mangled_name, char* output_buffer, size_t* length, int* status ) ;
! (c)2009 Joe Groff bsd license
-USING: accessors alien audio classes.struct fry calendar timers
-combinators combinators.short-circuit destructors generalizations
-kernel literals locals math openal sequences
-sequences.generalizations specialized-arrays strings ;
+USING: accessors alien alien.data audio classes.struct fry
+calendar timers combinators combinators.short-circuit
+destructors generalizations kernel literals locals math openal
+sequences sequences.generalizations specialized-arrays strings ;
QUALIFIED-WITH: alien.c-types c
SPECIALIZED-ARRAYS: c:float c:uchar c:uint ;
IN: audio.engine
:: flush-source ( al-source -- )
al-source alSourceStop
- 0 c:uint c:<ref> :> dummy-buffer
+ 0 c:uint <ref> :> dummy-buffer
al-source AL_BUFFERS_PROCESSED get-source-param [
al-source 1 dummy-buffer alSourceUnqueueBuffers
] times
audio-clip t >>done? drop
] [
al-buffer audio-clip openal-format data size audio-clip sample-rate>> alBufferData
- al-source 1 al-buffer c:uint c:<ref> alSourceQueueBuffers
+ al-source 1 al-buffer c:uint <ref> alSourceQueueBuffers
] if
] unless ;
M:: streaming-audio-clip (update-audio-clip) ( audio-clip -- )
audio-clip al-source>> :> al-source
- 0 c:uint c:<ref> :> buffer
+ 0 c:uint <ref> :> buffer
al-source AL_BUFFERS_PROCESSED get-source-param [
al-source 1 buffer alSourceUnqueueBuffers
- audio-clip buffer c:uint c:deref queue-clip-buffer
+ audio-clip buffer c:uint deref queue-clip-buffer
] times ;
: update-audio-clip ( audio-clip -- )
audio-engine get-available-source :> al-source
al-source [
- 1 0 c:uint c:<ref> [ alGenBuffers ] keep c:uint c:deref :> al-buffer
+ 1 0 c:uint <ref> [ alGenBuffers ] keep c:uint deref :> al-buffer
al-buffer audio { [ openal-format ] [ data>> ] [ size>> ] [ sample-rate>> ] } cleave
alBufferData
M: static-audio-clip dispose*
[ call-next-method ]
- [ [ 1 ] dip al-buffer>> c:uint c:<ref> alDeleteBuffers ] bi ;
+ [ [ 1 ] dip al-buffer>> c:uint <ref> alDeleteBuffers ] bi ;
M: streaming-audio-clip dispose*
[ call-next-method ]
! (c)2007, 2010 Chris Double, Joe Groff bsd license
-USING: accessors alien alien.c-types audio.engine byte-arrays
-classes.struct combinators destructors fry io io.files
-io.encodings.binary kernel libc locals make math math.order
-math.parser ogg ogg.vorbis sequences specialized-arrays
-specialized-vectors ;
+USING: accessors alien alien.c-types alien.data audio.engine
+byte-arrays classes.struct combinators destructors fry io
+io.files io.encodings.binary kernel libc locals make math
+math.order math.parser ogg ogg.vorbis sequences
+specialized-arrays specialized-vectors ;
FROM: alien.c-types => float short void* ;
SPECIALIZED-ARRAYS: float void* ;
SPECIALIZED-VECTOR: short
: create-context ( device flags -- context )
swap
- [ CUcontext <c-object> ] 2dip
- [ cuCtxCreate cuda-error ] 3keep 2drop void* deref ; inline
+ [ { CUcontext } ] 2dip
+ '[ _ _ cuCtxCreate cuda-error ] with-out-parameters ; inline
: sync-context ( -- )
cuCtxSynchronize cuda-error ; inline
: context-device ( -- n )
- CUdevice <c-object> [ cuCtxGetDevice cuda-error ] keep int deref ; inline
+ { CUdevice } [ cuCtxGetDevice cuda-error ] with-out-parameters ; inline
: destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
dup CUDA_SUCCESS = [ drop ] [ \ cuda-error boa throw ] if ;
: cuda-version ( -- n )
- c:int <c-object> [ cuDriverGetVersion cuda-error ] keep c:int c:deref ;
+ { c:int } [ cuDriverGetVersion cuda-error ] with-out-parameters ;
: init-cuda ( -- )
0 cuInit cuda-error ; inline
IN: cuda.devices
: #cuda-devices ( -- n )
- int <c-object> [ cuDeviceGetCount cuda-error ] keep int deref ;
+ { int } [ cuDeviceGetCount cuda-error ] with-out-parameters ;
: n>cuda-device ( n -- device )
- [ CUdevice <c-object> ] dip [ cuDeviceGet cuda-error ] 2keep
- drop int deref ;
+ [ { CUdevice } ] dip '[ _ cuDeviceGet cuda-error ] with-out-parameters ;
: enumerate-cuda-devices ( -- devices )
#cuda-devices iota [ n>cuda-device ] map ;
[ 2drop utf8 alien>string ] 3bi ;
: cuda-device-capability ( n -- pair )
- [ int <c-object> int <c-object> ] dip
- [ cuDeviceComputeCapability cuda-error ]
- [ drop [ int deref ] bi@ ] 3bi 2array ;
+ [ { int int } ] dip
+ '[ _ cuDeviceComputeCapability cuda-error ] with-out-parameters
+ 2array ;
: cuda-device-memory ( n -- bytes )
- [ uint <c-object> ] dip
- [ cuDeviceTotalMem cuda-error ]
- [ drop uint deref ] 2bi ;
+ [ { uint } ] dip
+ '[ _ cuDeviceTotalMem cuda-error ] with-out-parameters ;
: cuda-device-attribute ( attribute n -- n )
- [ int <c-object> ] 2dip
- [ cuDeviceGetAttribute cuda-error ]
- [ 2drop int deref ] 3bi ;
+ [ { int } ] 2dip
+ '[ _ _ cuDeviceGetAttribute cuda-error ] with-out-parameters ;
: cuda-device. ( n -- )
{
: create-gl-cuda-context ( device flags -- context )
swap
- [ CUcontext <c-object> ] 2dip
- [ cuGLCtxCreate cuda-error ] 3keep 2drop void* deref ; inline
+ [ { CUcontext } ] 2dip
+ '[ _ _ cuGLCtxCreate cuda-error ] with-out-parameters ; inline
: with-gl-cuda-context ( device flags quot -- )
[ set-up-cuda-context create-gl-cuda-context ] dip (with-cuda-context) ; inline
: gl-buffer>resource ( gl-buffer flags -- resource )
enum>number
- [ CUgraphicsResource <c-object> ] 2dip
- [ cuGraphicsGLRegisterBuffer cuda-error ] 3keep 2drop void* deref ; inline
+ [ { CUgraphicsResource } ] 2dip
+ '[ _ _ cuGraphicsGLRegisterBuffer cuda-error ] with-out-parameters ; inline
: buffer>resource ( buffer flags -- resource )
[ handle>> ] dip gl-buffer>resource ; inline
: map-resource ( resource -- device-ptr size )
[ 1 swap void* <ref> f cuGraphicsMapResources cuda-error ] [
- [ CUdeviceptr <c-object> uint <c-object> ] dip
- [ cuGraphicsResourceGetMappedPointer cuda-error ] 3keep drop
- [ uint deref ] [ uint deref ] bi*
+ [ { CUdeviceptr uint } ] dip
+ '[ _ cuGraphicsResourceGetMappedPointer cuda-error ]
+ with-out-parameters
] bi ; inline
: unmap-resource ( resource -- )
PRIVATE>
: load-module ( path -- module )
- [ CUmodule <c-object> ] dip
- [ cuModuleLoad cuda-error ] 2keep drop c:void* c:deref ;
+ [ { CUmodule } ] dip
+ '[ _ cuModuleLoad cuda-error ] with-out-parameters ;
: unload-module ( module -- )
cuModuleUnload cuda-error ;
[ [ 0 cuda-param-size ] ] swap '[ _ [cuda-arguments] ] if-empty ;
: get-function-ptr ( module string -- function )
- [ CUfunction <c-object> ] 2dip
- [ cuModuleGetFunction cuda-error ] 3keep 2drop c:void* c:deref ;
+ [ { CUfunction } ] 2dip
+ '[ _ _ cuModuleGetFunction cuda-error ] with-out-parameters ;
: cached-module ( module-name -- alien )
lookup-cuda-library
] ;
: cuda-global* ( module-name symbol-name -- device-ptr size )
- [ CUdeviceptr <c-object> c:uint <c-object> ] 2dip
+ [ { CUdeviceptr { c:uint initial: 0 } } ] 2dip
[ cached-module ] dip
- '[ _ _ cuModuleGetGlobal cuda-error ] 2keep [ c:uint c:deref ] bi@ ; inline
+ '[ _ _ cuModuleGetGlobal cuda-error ] with-out-parameters ; inline
: cuda-global ( module-name symbol-name -- device-ptr )
cuda-global* drop ; inline
IN: cuda.memory
: cuda-malloc ( n -- ptr )
- [ CUdeviceptr <c-object> ] dip
- '[ _ cuMemAlloc cuda-error ] keep
- c:int c:deref ; inline
+ [ { CUdeviceptr } ] dip
+ '[ _ cuMemAlloc cuda-error ] with-out-parameters ; inline
: cuda-malloc-type ( n type -- ptr )
c:heap-size * cuda-malloc ; inline
! (c)2009 Joe Groff bsd license
-USING: accessors alien.c-types arrays byte-arrays combinators
-destructors gpu gpu.buffers gpu.private gpu.textures
-gpu.textures.private images kernel locals math math.rectangles opengl
-opengl.framebuffers opengl.gl opengl.textures sequences
+USING: accessors alien.c-types alien.data arrays byte-arrays
+combinators destructors gpu gpu.buffers gpu.private gpu.textures
+gpu.textures.private images kernel locals math math.rectangles
+opengl opengl.framebuffers opengl.gl opengl.textures sequences
specialized-arrays typed ui.gadgets.worlds variants ;
SPECIALIZED-ARRAY: int
SPECIALIZED-ARRAY: uint
: eval-js ( string -- result-string )
[ js-context get dup ] dip
- JSStringCreateWithUTF8CString f f 0 JSValueRef <c-object>
- [ JSEvaluateScript ] keep void* deref
+ JSStringCreateWithUTF8CString f f 0
+ { { void* initial: f } } [ JSEvaluateScript ] with-out-parameters
dup [ nip JSValueRef>string javascriptcore-error ] [ drop JSValueRef>string ] if ;
: eval-js-standalone ( string -- result-string )
! Copyright (C) 2009 Matthew Willis.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.syntax assocs destructors
-kernel llvm.core llvm.engine llvm.wrappers namespaces ;
+USING: accessors alien.c-types alien.data alien.syntax assocs
+destructors kernel llvm.core llvm.engine llvm.wrappers
+namespaces ;
IN: llvm.jit
! Copyright (C) 2009 Matthew Willis.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.syntax destructors kernel
-llvm.core llvm.engine llvm.jit llvm.wrappers ;
+USING: accessors alien.c-types alien.data alien.syntax
+destructors kernel llvm.core llvm.engine llvm.jit llvm.wrappers
+;
IN: llvm.reader
! Copyright (C) 2009 Matthew Willis.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.strings
+USING: accessors alien.c-types alien.data alien.strings
io.encodings.utf8 destructors kernel
llvm.core llvm.engine ;
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types kernel alien alien.syntax shuffle
+USING: alien.c-types alien.data kernel alien alien.syntax shuffle
openal openal.alut.backend namespaces system generalizations ;
IN: openal.alut.macosx
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.syntax combinators generalizations
-kernel openal openal.alut.backend ;
+USING: alien.c-types alien.data alien.syntax combinators
+generalizations kernel openal openal.alut.backend ;
IN: openal.alut.other
LIBRARY: alut
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors arrays alien system combinators
-alien.syntax namespaces alien.c-types sequences vocabs.loader
+alien.syntax namespaces sequences vocabs.loader
shuffle alien.libraries generalizations
-specialized-arrays alien.destructors ;
-FROM: alien.c-types => float short ;
+specialized-arrays alien.destructors alien.data ;
+FROM: alien.c-types => char double float int short uchar uint
+ushort void ;
SPECIALIZED-ARRAY: uint
IN: openal
! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types arrays byte-arrays combinators
-combinators.smart destructors io.encodings.ascii io.encodings.string
-kernel libc locals math namespaces opencl.ffi sequences shuffle
-specialized-arrays variants ;
+USING: accessors alien alien.c-types alien.data arrays
+byte-arrays combinators combinators.smart destructors
+io.encodings.ascii io.encodings.string kernel libc locals math
+namespaces opencl.ffi sequences shuffle specialized-arrays
+variants ;
IN: opencl
SPECIALIZED-ARRAYS: void* char size_t ;
! Copyright (C) 2009 Bruno Deferrari
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs destructors fry functors
-kernel locals sequences serialize tokyo.alien.tcutil tokyo.utils vectors ;
+USING: accessors alien.c-types alien.data arrays assocs
+destructors fry functors kernel locals sequences serialize
+tokyo.alien.tcutil tokyo.utils vectors ;
IN: tokyo.assoc-functor
FUNCTOR: define-tokyo-assoc-api ( T N -- )