acton icon indicating copy to clipboard operation
acton copied to clipboard

Fixed size integer unboxing not working correctly

Open plajjan opened this issue 1 year ago • 2 comments

Defining a function that returns one of our fixed width integers results in a compilation error. For example, this program:

def ret_u16() -> u16:
    return u16(1)

results in this error:

/private/tmp/actonc-cfef1cf64e95363b/out/types/u64.c:5:12: error: incompatible pointer to integer conversion returning 'B_u16' (aka 'struct B_u16 *') from a function with result type 'uint16_t' (aka 'unsigned short')

based on this generated code:

#include "rts/common.h"
#include "out/types/u64.h"
uint16_t u64Q_U_ret_u16 () {
    B_u16 N_tmp = B_u16G_new(((B_atom)to$int(1)), B_None);
    return ((B_u16)N_tmp);
}
B_u16 u64Q_ret_u16 () {
    return toB_u16(u64Q_U_ret_u16());
}
int u64Q_done$ = 0;
void u64Q___init__ () {
    if (u64Q_done$) return;
    u64Q_done$ = 1;
}

I'm not sure exactly where things go wrong but it looks like around the unboxing somewhere since the top function is meant to return an unboxed value but instead returns the boxed version, I think!?

plajjan avatar Jul 01 '24 13:07 plajjan

@sydow can you take a look at this?

plajjan avatar Jul 01 '24 13:07 plajjan

FWIW, I was able to work around this by assigning the value to a variable and return the variable, e.g.

def ret_u16() -> u16:
    r = u16(1)
    return r

plajjan avatar Sep 03 '24 11:09 plajjan