]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/data/data.factor
Move <ref>, deref and little-endian? from alien.c-types to alien.data, remove <c...
[factor.git] / basis / alien / data / data.factor
index ab34bf5a4e7f645775db13874210032b6176e957..e17ed9dc3c511eda2e3fdbfc98b3ef47fbe7eef7 100644 (file)
@@ -7,6 +7,15 @@ stack-checker.dependencies combinators.short-circuit ;
 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 ;
@@ -44,15 +53,6 @@ M: pointer <c-direct-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 ;