[pure-lang-svn] SF.net SVN: pure-lang:[503] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-14 23:31:50
|
Revision: 503 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=503&view=rev Author: agraef Date: 2008-08-14 23:31:59 +0000 (Thu, 14 Aug 2008) Log Message: ----------- Add bigint->int32_t marshalling routine. Modified Paths: -------------- pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-08-14 23:16:09 UTC (rev 502) +++ pure/trunk/runtime.cc 2008-08-14 23:31:59 UTC (rev 503) @@ -1147,6 +1147,15 @@ } extern "C" +int32_t pure_get_int(pure_expr *x) +{ + uint32_t v = + (sizeof(mp_limb_t) == 8) ? (uint32_t)(uint64_t)mpz_getlimbn(x->data.z, 0) : + mpz_getlimbn(x->data.z, 0); + return (mpz_sgn(x->data.z) < 0) ? -(int32_t)v : (int32_t)v; +} + +extern "C" void *pure_get_bigint(pure_expr *x) { assert(x && x->tag == EXPR::BIGINT); Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-08-14 23:16:09 UTC (rev 502) +++ pure/trunk/runtime.h 2008-08-14 23:31:59 UTC (rev 503) @@ -318,11 +318,12 @@ char *pure_get_cstring(pure_expr *x); void pure_free_cstrings(); -/* Convert a bigint expression to a pointer (mpz_t) or a long (64 bit) +/* Convert a bigint expression to a pointer (mpz_t) or a 64 or 32 bit integer. This is used to marshall bigint arguments in the C interface. */ void *pure_get_bigint(pure_expr *x); int64_t pure_get_long(pure_expr *x); +int32_t pure_get_int(pure_expr *x); /* Execute a closure. If the given expression x (or x y in the case of pure_apply) is a parameterless closure (or a saturated application of a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |