git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: switch to standard C/C++ int
d67d12eAndy Arvanitis
pcc/include/purescript.cc+2−2
@@ -45,7 +45,7 @@ auto any::operator()() const -> any {
45 return (*variant.e)();
45 return (*variant.e)();
46}
46}
47
47
48−any::operator integer() const {
48+any::operator int() const {
49 RETURN_VALUE(Type::Integer, i,)
49 RETURN_VALUE(Type::Integer, i,)
50}
50}
51
51
@@ -121,7 +121,7 @@ auto any::operator[](const size_t rhs) const -> const any& {
121auto any::operator[](const any& rhs) const -> const any& {
121auto any::operator[](const any& rhs) const -> const any& {
122 const any& variant = unthunkVariant(*this);
122 const any& variant = unthunkVariant(*this);
123 assert(variant.type == Type::Array);
123 assert(variant.type == Type::Array);
124− return (*variant.a)[cast<integer>(rhs)];
124+ return (*variant.a)[cast<int>(rhs)];
125}
125}
126
126
127auto any::contains(const char key[]) const -> bool {
127auto any::contains(const char key[]) const -> bool {
pcc/include/purescript.hh+12−29
@@ -36,7 +36,6 @@
36
36
37namespace PureScript {
37namespace PureScript {
38
38
39−using integer = std::intptr_t;
40using cstring = const char *;
39using cstring = const char *;
41using nullptr_t = std::nullptr_t;
40using nullptr_t = std::nullptr_t;
42
41
@@ -46,9 +45,6 @@ public:
46 runtime_error(const char message[]) : std::runtime_error(std::string(message)) {}
45 runtime_error(const char message[]) : std::runtime_error(std::string(message)) {}
47};
46};
48
47
49−const integer INTEGER_MIN = INTPTR_MIN;
50−const integer INTEGER_MAX = INTPTR_MAX;
51−
52const bool undefined = false;
48const bool undefined = false;
53const size_t constructor = 0;
49const size_t constructor = 0;
54
50
@@ -128,7 +124,7 @@ class any {
128 private:
124 private:
129 union {
125 union {
130 mutable thunk t;
126 mutable thunk t;
131− mutable integer i;
127+ mutable int i;
132 mutable double d;
128 mutable double d;
133 mutable char c;
129 mutable char c;
134 mutable bool b;
130 mutable bool b;
@@ -147,9 +143,11 @@ class any {
147
143
148 public:
144 public:
149
145
150− any(const integer val) noexcept : type(Type::Integer), i(val) {}
151 any(const int val) noexcept : type(Type::Integer), i(val) {}
146 any(const int val) noexcept : type(Type::Integer), i(val) {}
152− any(const unsigned int val) noexcept : type(Type::Integer), i(val) {}
147+ any(const long int_value) noexcept : type(Type::Integer), i(int_value) {
148+ assert(int_value >= INT_MIN && int_value <= INT_MAX);
149+ }
150+
153 any(const double val) noexcept : type(Type::Double), d(val) {}
151 any(const double val) noexcept : type(Type::Double), d(val) {}
154 any(const char val) noexcept : type(Type::Character), c(val) {}
152 any(const char val) noexcept : type(Type::Character), c(val) {}
155
153
@@ -305,7 +303,7 @@ class any {
305 auto operator()(const as_thunk) const -> const any&;
303 auto operator()(const as_thunk) const -> const any&;
306 auto operator()() const -> any;
304 auto operator()() const -> any;
307
305
308− operator integer() const;
306+ operator int() const;
309 operator double() const;
307 operator double() const;
310 operator bool() const;
308 operator bool() const;
311 operator char() const;
309 operator char() const;
@@ -338,21 +336,12 @@ class any {
338 return lhs op (ty)rhs; \
336 return lhs op (ty)rhs; \
339 } \
337 } \
340
338
341− #define DEFINE_INT_OPERATOR(op, rty) \
342− inline friend auto operator op (const any& lhs, int rhs) -> rty { \
343− return (integer)lhs op (integer)rhs; \
344− } \
345− inline friend auto operator op (int lhs, const any& rhs) -> rty { \
346− return (integer)lhs op (integer)rhs; \
347− }
348−
349 #define DECLARE_COMPARISON_OPERATOR(op) \
339 #define DECLARE_COMPARISON_OPERATOR(op) \
350 friend auto operator op (const any&, const any&) -> bool; \
340 friend auto operator op (const any&, const any&) -> bool; \
351− DEFINE_OPERATOR(op, integer, bool) \
341+ DEFINE_OPERATOR(op, int, bool) \
352 DEFINE_OPERATOR(op, double, bool) \
342 DEFINE_OPERATOR(op, double, bool) \
353 DEFINE_OPERATOR(op, char, bool) \
343 DEFINE_OPERATOR(op, char, bool) \
354 DEFINE_OPERATOR(op, bool, bool) \
344 DEFINE_OPERATOR(op, bool, bool) \
355− DEFINE_INT_OPERATOR(op, bool) \
356 friend auto operator op (const any&, const char * const) -> bool; \
345 friend auto operator op (const any&, const char * const) -> bool; \
357 friend auto operator op (const char * const, const any&) -> bool;
346 friend auto operator op (const char * const, const any&) -> bool;
358
347
@@ -365,39 +354,34 @@ class any {
365
354
366 friend auto operator+(const any&, const any&) -> any;
355 friend auto operator+(const any&, const any&) -> any;
367
356
368− DEFINE_OPERATOR(+, integer, integer)
357+ DEFINE_OPERATOR(+, int, int)
369 DEFINE_OPERATOR(+, double, double)
358 DEFINE_OPERATOR(+, double, double)
370 DEFINE_OPERATOR(+, char, char)
359 DEFINE_OPERATOR(+, char, char)
371− DEFINE_INT_OPERATOR(+, integer)
372 friend auto operator+(const any& lhs, const char * const rhs) -> std::string;
360 friend auto operator+(const any& lhs, const char * const rhs) -> std::string;
373 friend auto operator+(const char * const lhs, const any& rhs) -> std::string;
361 friend auto operator+(const char * const lhs, const any& rhs) -> std::string;
374
362
375 friend auto operator-(const any&, const any&) -> any;
363 friend auto operator-(const any&, const any&) -> any;
376
364
377− DEFINE_OPERATOR(-, integer, integer)
365+ DEFINE_OPERATOR(-, int, int)
378 DEFINE_OPERATOR(-, double, double)
366 DEFINE_OPERATOR(-, double, double)
379 DEFINE_OPERATOR(-, char, char)
367 DEFINE_OPERATOR(-, char, char)
380− DEFINE_INT_OPERATOR(-, integer)
381
368
382 friend auto operator*(const any&, const any&) -> any;
369 friend auto operator*(const any&, const any&) -> any;
383
370
384− DEFINE_OPERATOR(*, integer, integer)
371+ DEFINE_OPERATOR(*, int, int)
385 DEFINE_OPERATOR(*, double, double)
372 DEFINE_OPERATOR(*, double, double)
386 DEFINE_OPERATOR(*, char, char)
373 DEFINE_OPERATOR(*, char, char)
387− DEFINE_INT_OPERATOR(*, integer)
388
374
389 friend auto operator/(const any&, const any&) -> any;
375 friend auto operator/(const any&, const any&) -> any;
390
376
391− DEFINE_OPERATOR(/, integer, integer)
377+ DEFINE_OPERATOR(/, int, int)
392 DEFINE_OPERATOR(/, double, double)
378 DEFINE_OPERATOR(/, double, double)
393 DEFINE_OPERATOR(/, char, char)
379 DEFINE_OPERATOR(/, char, char)
394− DEFINE_INT_OPERATOR(/, integer)
395
380
396 friend auto operator%(const any&, const any&) -> any;
381 friend auto operator%(const any&, const any&) -> any;
397
382
398− DEFINE_OPERATOR(%, integer, integer)
383+ DEFINE_OPERATOR(%, int, int)
399 DEFINE_OPERATOR(%, char, char)
384 DEFINE_OPERATOR(%, char, char)
400− DEFINE_INT_OPERATOR(%, integer)
401
385
402 friend auto operator-(const any&) -> any; // unary negate
386 friend auto operator-(const any&) -> any; // unary negate
403};
387};
@@ -436,7 +420,6 @@ inline auto cast(const any& a) ->
436#undef WITH_ALLOCATOR
420#undef WITH_ALLOCATOR
437#undef IS_POINTER_TYPE
421#undef IS_POINTER_TYPE
438#undef DEFINE_OPERATOR
422#undef DEFINE_OPERATOR
439−#undef DEFINE_INT_OPERATOR
440#undef DECLARE_COMPARISON_OPERATOR
423#undef DECLARE_COMPARISON_OPERATOR
441
424
442#endif // PureScript_HH
425#endif // PureScript_HH
src/Language/PureScript/CodeGen/Cpp/Common.hs−1
@@ -129,7 +129,6 @@ nameIsCppReserved name =
129 , "import"
129 , "import"
130 , "inline"
130 , "inline"
131 , "int"
131 , "int"
132− , "integer"
133 , "list"
132 , "list"
134 , "long"
133 , "long"
135 , "mutable"
134 , "mutable"
src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1
@@ -100,7 +100,7 @@ boolType :: CppType
100boolType = CppPrimitive "bool"
100boolType = CppPrimitive "bool"
101
101
102intType :: CppType
102intType :: CppType
103−intType = CppPrimitive "integer"
103+intType = CppPrimitive "int"
104
104
105doubleType :: CppType
105doubleType :: CppType
106doubleType = CppPrimitive "double"
106doubleType = CppPrimitive "double"