Is there any way to return an Int64 from the Neko/C FFI?

28 views
Skip to first unread message

TopHattedCoder

unread,
Sep 4, 2013, 3:31:33 PM9/4/13
to haxe...@googlegroups.com
 Here's the example I'm trying run:
var c = new Context();
c
.lock();
var func = c.build(function(n:UInt64):UInt64 {
   
var current:UInt64 = 0, next:UInt64 = 1, temp:UInt64;
   
for(i in 1...n) {
       temp
= current + next;
       current
= next;
       
next = temp;
   
}
   
return current;
});
func
.compile();
Sys.println('Computing fibonacci numbers for ${Sys.args().join(", ")}');
for(n in Sys.args()) {
   
var r:{high:Int, low:Int} = func.apply([Std.parseInt(n)]);
   
Sys.println('$n: $r');
}
c
.unlock();
c
.destroy();
This currently prints:
Computing fibonacci numbers for 20, 40, 60, 80, 100, 120
20: { high => 0, low => 6765 }
40: { high => 0, low => 1670859 }
60: { high => 360, low => 8590032 }
80: { high => 5452131, low => 205285 }
100: { high => 870020775, low => 9748419 }
120: { high => 1019028024, low => 9177504 }
The bit of the external interface that handles with returning longs is here:
case JIT_TYPE_ULONG: {
   
const value v = alloc_empty_object();
   
const jit_ulong l = *((jit_ulong*) ptr);
    alloc_field
(v, low, alloc_int(l & 0xFFFFFF));
    alloc_field
(v, high, alloc_int(l >> 32));
   
return v;
}
case JIT_TYPE_LONG: {
   
const value v = alloc_empty_object();
   
const jit_long l = *((jit_long*) ptr);
    alloc_field
(v, low, alloc_int(l & 0xFFFFFF));
    alloc_field
(v, high, alloc_int(l >> 32));
   
return v;
}
  1. Is there any built-in way for returning Int64s?
  2. If not, does anyone know why using Int64.make gives the wrong values?
Thanks.

TopHattedCoder

unread,
Sep 4, 2013, 3:42:28 PM9/4/13
to haxe...@googlegroups.com
Never mind that last bit, I only set 24 bits in the mask. I'll just add a map filter in the apply function for when int 64s are returned.
Reply all
Reply to author
Forward
0 new messages