git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: switch to standard C/C++ int
commitd67d12ed9ad408a2bd307d0c7210c97975a8df14 authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 14 Aug 2016, 19:43 (10 years ago) parent39204ab
4 files changed+15−33
pcc/include/purescript.cc+2−2 pcc/include/purescript.hh+12−29 src/Language/PureScript/CodeGen/Cpp/Common.hs−1 src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1
pcc/include/purescript.cc+2−2
@@ -45,7 +45,7 @@ auto any::operator()() const -> any {
4545 return (*variant.e)();
4646}
4747
48−any::operator integer() const {
48+any::operator int() const {
4949 RETURN_VALUE(Type::Integer, i,)
5050}
5151
@@ -121,7 +121,7 @@ auto any::operator[](const size_t rhs) const -> const any& {
121121auto any::operator[](const any& rhs) const -> const any& {
122122 const any& variant = unthunkVariant(*this);
123123 assert(variant.type == Type::Array);
124− return (*variant.a)[cast<integer>(rhs)];
124+ return (*variant.a)[cast<int>(rhs)];
125125}
126126
127127auto any::contains(const char key[]) const -> bool {
pcc/include/purescript.hh+12−29
@@ -36,7 +36,6 @@
3636
3737namespace PureScript {
3838
39−using integer = std::intptr_t;
4039using cstring = const char *;
4140using nullptr_t = std::nullptr_t;
4241
@@ -46,9 +45,6 @@ public:
4645 runtime_error(const char message[]) : std::runtime_error(std::string(message)) {}
4746};
4847
49−const integer INTEGER_MIN = INTPTR_MIN;
50−const integer INTEGER_MAX = INTPTR_MAX;
51−
5248const bool undefined = false;
5349const size_t constructor = 0;
5450
@@ -128,7 +124,7 @@ class any {
128124 private:
129125 union {
130126 mutable thunk t;
131− mutable integer i;
127+ mutable int i;
132128 mutable double d;
133129 mutable char c;
134130 mutable bool b;
@@ -147,9 +143,11 @@ class any {
147143
148144 public:
149145
150− any(const integer val) noexcept : type(Type::Integer), i(val) {}
151146 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+
153151 any(const double val) noexcept : type(Type::Double), d(val) {}
154152 any(const char val) noexcept : type(Type::Character), c(val) {}
155153
@@ -305,7 +303,7 @@ class any {
305303 auto operator()(const as_thunk) const -> const any&;
306304 auto operator()() const -> any;
307305
308− operator integer() const;
306+ operator int() const;
309307 operator double() const;
310308 operator bool() const;
311309 operator char() const;
@@ -338,21 +336,12 @@ class any {
338336 return lhs op (ty)rhs; \
339337 } \
340338
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−
349339 #define DECLARE_COMPARISON_OPERATOR(op) \
350340 friend auto operator op (const any&, const any&) -> bool; \
351− DEFINE_OPERATOR(op, integer, bool) \
341+ DEFINE_OPERATOR(op, int, bool) \
352342 DEFINE_OPERATOR(op, double, bool) \
353343 DEFINE_OPERATOR(op, char, bool) \
354344 DEFINE_OPERATOR(op, bool, bool) \
355− DEFINE_INT_OPERATOR(op, bool) \
356345 friend auto operator op (const any&, const char * const) -> bool; \
357346 friend auto operator op (const char * const, const any&) -> bool;
358347
@@ -365,39 +354,34 @@ class any {
365354
366355 friend auto operator+(const any&, const any&) -> any;
367356
368− DEFINE_OPERATOR(+, integer, integer)
357+ DEFINE_OPERATOR(+, int, int)
369358 DEFINE_OPERATOR(+, double, double)
370359 DEFINE_OPERATOR(+, char, char)
371− DEFINE_INT_OPERATOR(+, integer)
372360 friend auto operator+(const any& lhs, const char * const rhs) -> std::string;
373361 friend auto operator+(const char * const lhs, const any& rhs) -> std::string;
374362
375363 friend auto operator-(const any&, const any&) -> any;
376364
377− DEFINE_OPERATOR(-, integer, integer)
365+ DEFINE_OPERATOR(-, int, int)
378366 DEFINE_OPERATOR(-, double, double)
379367 DEFINE_OPERATOR(-, char, char)
380− DEFINE_INT_OPERATOR(-, integer)
381368
382369 friend auto operator*(const any&, const any&) -> any;
383370
384− DEFINE_OPERATOR(*, integer, integer)
371+ DEFINE_OPERATOR(*, int, int)
385372 DEFINE_OPERATOR(*, double, double)
386373 DEFINE_OPERATOR(*, char, char)
387− DEFINE_INT_OPERATOR(*, integer)
388374
389375 friend auto operator/(const any&, const any&) -> any;
390376
391− DEFINE_OPERATOR(/, integer, integer)
377+ DEFINE_OPERATOR(/, int, int)
392378 DEFINE_OPERATOR(/, double, double)
393379 DEFINE_OPERATOR(/, char, char)
394− DEFINE_INT_OPERATOR(/, integer)
395380
396381 friend auto operator%(const any&, const any&) -> any;
397382
398− DEFINE_OPERATOR(%, integer, integer)
383+ DEFINE_OPERATOR(%, int, int)
399384 DEFINE_OPERATOR(%, char, char)
400− DEFINE_INT_OPERATOR(%, integer)
401385
402386 friend auto operator-(const any&) -> any; // unary negate
403387};
@@ -436,7 +420,6 @@ inline auto cast(const any& a) ->
436420#undef WITH_ALLOCATOR
437421#undef IS_POINTER_TYPE
438422#undef DEFINE_OPERATOR
439−#undef DEFINE_INT_OPERATOR
440423#undef DECLARE_COMPARISON_OPERATOR
441424
442425#endif // PureScript_HH
src/Language/PureScript/CodeGen/Cpp/Common.hs−1
@@ -129,7 +129,6 @@ nameIsCppReserved name =
129129 , "import"
130130 , "inline"
131131 , "int"
132− , "integer"
133132 , "list"
134133 , "long"
135134 , "mutable"
src/Language/PureScript/CodeGen/Cpp/Types.hs+1−1
@@ -100,7 +100,7 @@ boolType :: CppType
100100boolType = CppPrimitive "bool"
101101
102102intType :: CppType
103−intType = CppPrimitive "integer"
103+intType = CppPrimitive "int"
104104
105105doubleType :: CppType
106106doubleType = CppPrimitive "double"