Re: [q-lang-users] Memory management in libqint
Brought to you by:
agraef
From: John C. <co...@cc...> - 2006-06-12 21:50:22
|
Albert Graef scripsit: > Well, if you can check whether that UTF-8 "egg" is loaded (what a funny > name for a module ;-) then you can omit the conversion if so. Not only that, but Chicken itself is now available as an egg (if you have a Chicken loaded, you can upgrade to a later version by installing the egg). Which leads to a curious philosophical question.... > In that case you should be able to check what kind of integer you have > in Chicken? Then just pass it as an mpz_t if it already is one (don't > forget to copy it since mpz_t objects become owned by Q when you pass > them to qmkmpz). Which will involve poking about in the GMP docs to figure out how to copy an mpz_t, since Chicken's FFI doesn't provide any help as it does with strings. > When decoding a Q integer, you should convert to the > smallest type able to represent the number (i.e., first try qisuint [if > there's a separate unsigned integer type in Chicken], then qisint and > finally qismpz). Internally, unmodified Chicken has only fixnums (integers in the range -2^30 to 2^30-1) and flonums. The Chicken FFI, however, can deal in longs and unsigned longs, which are converted to fixnums if possible and flonums if not. Therefore it does not seem to matter whether I use qisint or qisuint first: the Chicken value will be the same in either case. > If the number is only representable as a bignum but the > bignum "egg" hasn't been loaded in Chicken, then you must either give up > or convert it to something which fits into a machine integer (take the > lowest limb or something). Unfortunately, the FFI is not aware of whether bignums are available or not. I'm not sure how to coerce Chicken to believe that an mpz_t object is really a bignum internally. If I can't find out or bignums aren't loaded, I'll have to use ismpz_float and pass that to Chicken. PROBLEM: there doesn't seem to be a way to convert a qexpr to a symbol number, the opposite of mksym. I had assumed that issym does this, but the second argument is of type int, not int*, so it only tests if the qexpr is some specific, already-known symbol. This is good for qistrue etc., but not for me. I need to be able to find out which symbol it is so that I can return a corresponding Chicken symbol. -- John Cowan co...@cc... http://ccil.org/~cowan Sound change operates regularly to produce irregularities; analogy operates irregularly to produce regularities. --E.H. Sturtevant, ca. 1945, probably at Yale |