Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c2nim fails to remove "LL" suffixes on types #247

Open
omentic opened this issue Jul 29, 2022 · 1 comment
Open

c2nim fails to remove "LL" suffixes on types #247

omentic opened this issue Jul 29, 2022 · 1 comment

Comments

@omentic
Copy link

omentic commented Jul 29, 2022

c2nim correctly identifies the size of integers appended with LL or similar, but fails to remove those suffixes in the generated code.

Here is an example:

static inline double wl_fixed_to_double(wl_fixed_t f) {
	union {
		double d;
		int64_t i;
	} u;
	u.i = ((1023LL + 44LL) << 52) + (1LL << 51) + f;
	return u.d - (3LL << 43);
}
proc wl_fixed_to_double*(f: wl_fixed_t): cdouble {.inline.} =
  type
    INNER_C_UNION_wayland-util_616 {.bycopy, union.} = object
      d: cdouble
      i: int64_t

  var u: INNER_C_UNION_wayland-util_616
  u.i = ((1023LL'i64 + 44LL'i64) shl 52) + (1LL'i64 shl 51) + f
  return u.d - (3LL'i64 shl 43)
@PMunch
Copy link

PMunch commented Jan 22, 2025

I've ran into the same issue while evaluating c2nim performance for embedding into Futharks macro translation. This test case from Futhark:

#define TEST_PLAIN_INT                     (123)
#define TEST_PLAIN_LONG                    (-2147483648L)
#define TEST_PLAIN_LONGLONG                (-9223372036854775808LL)

#define TEST_PLAIN_FLOAT_1                 (123.123f)
#define TEST_PLAIN_FLOAT_2                 (.123f)
#define TEST_PLAIN_FLOAT_3                 (123.f)
#define TEST_PLAIN_FLOAT_4                 (-.0f)
#define TEST_PLAIN_FLOAT_5                 (-0.f)
#define TEST_PLAIN_FLOAT_6                 (0.0f)

#define TEST_PLAIN_DOUBLE_1                (123.0)

#define TEST_PLAIN_LONG_DOUBLE_1           (100.0L)

Turns into this by c2nim:

const
  TEST_PLAIN_INT* = (123)
  TEST_PLAIN_LONG* = (-2147483648'i32)
  TEST_PLAIN_LONGLONG* = (-9223372036854775808'i64)
  TEST_PLAIN_FLOAT_1* = (123.123f)
  TEST_PLAIN_FLOAT_2* = (0.123f)
  TEST_PLAIN_FLOAT_3* = (123.f)
  TEST_PLAIN_FLOAT_4* = (-0.0f)
  TEST_PLAIN_FLOAT_5* = (-0.f)
  TEST_PLAIN_FLOAT_6* = (0.0f)
  TEST_PLAIN_DOUBLE_1* = (123.0)
  TEST_PLAIN_LONG_DOUBLE_1* = (100.0L)

So it works for L and LL for integer values, but fails on f and L on floats.

It does seem that the original issue with leaving the LL when adding 'i64 is gone though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants