File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -104,11 +104,14 @@ return 0;
104104 (= (:type of- type ) :function) (callback- type of- type in - struct ?)
105105 :else ' pixie.stdlib/CVoidP))
106106
107+ (def float - types {32 ' pixie.stdlib/CFloat
108+ 64 ' pixie.stdlib/CDouble})
109+
107110(defmethod edn- to- ctype :float
108- [{:keys [size]} _]
109- (cond
110- ( = size 8 ) ' pixie.stdlib/CDouble
111- : else ( assert false " unknown type " ) ))
111+ [{:keys [size] : as tp } _]
112+ (let [tp - found (get float - types ( * 8 size))]
113+ ( assert tp - found ( str " No type found for " tp))
114+ tp - found ))
112115
113116(defmethod edn- to- ctype :void
114117 [_ _]
Original file line number Diff line number Diff line change @@ -350,6 +350,26 @@ def ffi_type(self):
350350 return clibffi .cast_type_to_ffitype (rffi .INT )
351351CInt ()
352352
353+ class CFloat (CType ):
354+ def __init__ (self ):
355+ CType .__init__ (self , u"pixie.stdlib.CFloat" )
356+
357+ def ffi_get_value (self , ptr ):
358+ casted = rffi .cast (rffi .FLOATP , ptr )
359+ return Float (rffi .cast (rffi .DOUBLE , casted [0 ]))
360+
361+ def ffi_set_value (self , ptr , val ):
362+ val = to_float (val )
363+ casted = rffi .cast (rffi .FLOATP , ptr )
364+ casted [0 ] = rffi .cast (rffi .FLOAT , val .float_val ())
365+
366+ def ffi_size (self ):
367+ return rffi .sizeof (rffi .FLOAT )
368+
369+ def ffi_type (self ):
370+ return clibffi .cast_type_to_ffitype (rffi .FLOAT )
371+ CFloat ()
372+
353373class CDouble (CType ):
354374 def __init__ (self ):
355375 CType .__init__ (self , u"pixie.stdlib.CDouble" )
You can’t perform that action at this time.
0 commit comments