Move byte-length generic and methods into alien.c-types
parent
8b0e61b18b
commit
6f2b91d4a4
|
@ -34,10 +34,6 @@ HELP: <alien>
|
||||||
{ $description "Creates an alien object, wrapping a raw memory address." }
|
{ $description "Creates an alien object, wrapping a raw memory address." }
|
||||||
{ $notes "Alien objects are invalidated between image saves and loads." } ;
|
{ $notes "Alien objects are invalidated between image saves and loads." } ;
|
||||||
|
|
||||||
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-ptr
|
HELP: c-ptr
|
||||||
{ $class-description "Class of objects consisting of aliens, byte arrays and " { $link f } ". These objects can convert to pointer C types, which are all aliases of " { $snippet "void*" } "." } ;
|
{ $class-description "Class of objects consisting of aliens, byte arrays and " { $link f } ". These objects can convert to pointer C types, which are all aliases of " { $snippet "void*" } "." } ;
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ PREDICATE: alien pinned-alien
|
||||||
UNION: pinned-c-ptr
|
UNION: pinned-c-ptr
|
||||||
pinned-alien POSTPONE: f ;
|
pinned-alien POSTPONE: f ;
|
||||||
|
|
||||||
GENERIC: byte-length ( seq -- n ) flushable
|
|
||||||
|
|
||||||
M: f expired? drop t ;
|
M: f expired? drop t ;
|
||||||
|
|
||||||
: <alien> ( address -- alien )
|
: <alien> ( address -- alien )
|
||||||
|
|
|
@ -34,6 +34,10 @@ HELP: stack-size
|
||||||
{ $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." }
|
{ $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." } ;
|
{ $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
|
HELP: c-getter
|
||||||
{ $values { "name" string } { "quot" "a quotation with stack effect " { $snippet "( c-ptr n -- obj )" } } }
|
{ $values { "name" string } { "quot" "a quotation with stack effect " { $snippet "( c-ptr n -- obj )" } } }
|
||||||
{ $description "Outputs a quotation which reads values of this C type from a C structure." }
|
{ $description "Outputs a quotation which reads values of this C type from a C structure." }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2004, 2007 Slava Pestov.
|
! Copyright (C) 2004, 2007 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: byte-arrays arrays generator.registers assocs
|
USING: byte-arrays float-arrays arrays generator.registers assocs
|
||||||
kernel kernel.private libc math namespaces parser sequences
|
kernel kernel.private libc math namespaces parser sequences
|
||||||
strings words assocs splitting math.parser cpu.architecture
|
strings words assocs splitting math.parser cpu.architecture
|
||||||
alien quotations system compiler.units ;
|
alien quotations system compiler.units ;
|
||||||
|
@ -107,6 +107,12 @@ M: string stack-size c-type stack-size ;
|
||||||
|
|
||||||
M: c-type stack-size c-type-size ;
|
M: c-type stack-size c-type-size ;
|
||||||
|
|
||||||
|
GENERIC: byte-length ( seq -- n ) flushable
|
||||||
|
|
||||||
|
M: float-array byte-length length "float" heap-size * ;
|
||||||
|
|
||||||
|
M: byte-array byte-length length ;
|
||||||
|
|
||||||
: c-getter ( name -- quot )
|
: c-getter ( name -- quot )
|
||||||
c-type c-type-getter [
|
c-type c-type-getter [
|
||||||
[ "Cannot read struct fields with type" throw ]
|
[ "Cannot read struct fields with type" throw ]
|
||||||
|
|
|
@ -15,8 +15,6 @@ M: byte-array new drop <byte-array> ;
|
||||||
M: byte-array equal?
|
M: byte-array equal?
|
||||||
over byte-array? [ sequence= ] [ 2drop f ] if ;
|
over byte-array? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
M: byte-array byte-length
|
|
||||||
length ;
|
|
||||||
M: byte-array resize
|
M: byte-array resize
|
||||||
resize-byte-array ;
|
resize-byte-array ;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2007, 2008 Slava Pestov.
|
! Copyright (C) 2007, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel kernel.private alien alien.c-types sequences
|
USING: kernel kernel.private alien sequences
|
||||||
sequences.private math math.private ;
|
sequences.private math math.private ;
|
||||||
IN: float-arrays
|
IN: float-arrays
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ PRIVATE>
|
||||||
|
|
||||||
M: float-array clone (clone) ;
|
M: float-array clone (clone) ;
|
||||||
M: float-array length array-capacity ;
|
M: float-array length array-capacity ;
|
||||||
M: float-array byte-length array-capacity "float" heap-size * ;
|
|
||||||
|
|
||||||
M: float-array nth-unsafe
|
M: float-array nth-unsafe
|
||||||
float-array@ alien-double ;
|
float-array@ alien-double ;
|
||||||
|
|
Loading…
Reference in New Issue