On Sat, Feb 10, 2024 at 02:32:16PM +0200, Al wrote: > That would be fine but where does that happen? csc actually barfs on my > Scheme code (as per the subject line), instead of emitting C code to > encode/decode into a string at runtime, as you mention.
That's because you're using fixnum mode. As I explained, using literals that might be too large for fixnums break the fixnum mode's premise that everything must be a fixnum. > It won't even let me use string->number by hand. That's because string->number gets constant-folded and evaluated at compile-time. > The only thing that worked was > > (cond-expand > (csi > (define INT32_MAX #x7fffffff) > (define INT32_MIN #x-80000000) > (define UINT32_MAX #xffffffff) > ) > (else > ; chicken csc only does 31-bit literals in fixnum mode > (define INT32_MIN (foreign-value "((int32_t) 0x80000000)" integer32)) > (define INT32_MAX (foreign-value "((int32_t) 0x7fffffff)" integer32)) > (define UINT32_MAX (foreign-value "((uint32_t) 0xffffffff)" > unsigned-integer32)) > ) > ) It would help if you tried to explain exactly _what_ you're trying to do here, instead of _how_ you're trying to do it. Why do you need these constants? > ... and I'm not sure what the implications of using a "foreign value" > further down in my program are. If I assign them to another variable, does > that variable also become a "foreign value"? A foreign value is simply a value that gets calculated using the FFI. The value itself, once calculated, won't be "special" in any way. It's just another fixnum. > How about if I do (bitwise-and > IMAX32 int) to truncate a signed number to unsigned32 (which is what I'm > actually using them for)? Again, what are you trying to accomplish? > > There's (currently) no option to force fixnum mode in a way that ignores > > the existence 32-bit platforms. Theoretically, it should be possible to > > compile your code assuming fixnums (so it emits C integer literals) and > > make it barf at compilation time if one tried to build for a 32-bit > > platform using a #ifdef or something. We just don't have the required > > code to do this, and I'm not sure this is something we'd all want. > > Well if csc emitted string->number code in fixnum mode when necessary, that > would at least work. It does that (more or less), as I explained. And it *wouldn't* work, because it can't make the assumption it won't be compiled on a system that's 32 bits. Cheers, Peter
signature.asc
Description: PGP signature