git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: fix an issue with new maps on Visual Studio compiler
19efe37Andy Arvanitis
pcc/include/purescript.cc+4−4
@@ -90,8 +90,8 @@ static const any invalid_key(nullptr);
90
90
91auto any::operator[](const symbol_t key) const -> const any& {
91auto any::operator[](const symbol_t key) const -> const any& {
92 // TODO: assumes at least one element -- safe assumption?
92 // TODO: assumes at least one element -- safe assumption?
93− const auto& m = cast<map<1>>(*this);
93+ const auto& m = cast<map<unknown_size>>(*this);
94− any::map<1>::size_type i = 0;
94+ std::remove_reference<decltype(m)>::type::size_type i = 0;
95 do {
95 do {
96 if (m[i].first == key) {
96 if (m[i].first == key) {
97 return m[i].second;
97 return m[i].second;
@@ -113,8 +113,8 @@ auto any::operator[](const any& rhs) const -> const any& {
113
113
114auto any::contains(const symbol_t key) const -> bool {
114auto any::contains(const symbol_t key) const -> bool {
115 // TODO: assumes at least one element -- safe assumption?
115 // TODO: assumes at least one element -- safe assumption?
116− const auto& m = cast<map<1>>(*this);
116+ const auto& m = cast<map<unknown_size>>(*this);
117− any::map<1>::size_type i = 0;
117+ std::remove_reference<decltype(m)>::type::size_type i = 0;
118 do {
118 do {
119 if (m[i].first == key) {
119 if (m[i].first == key) {
120 return true;
120 return true;
pcc/include/purescript.hh+5−2
@@ -60,8 +60,11 @@ public:
60 runtime_error(const char message[]) : std::runtime_error(std::string(message)) {}
60 runtime_error(const char message[]) : std::runtime_error(std::string(message)) {}
61};
61};
62
62
63−const bool undefined = false;
63+constexpr bool undefined = false;
64−const size_t constructor = 0;
64+constexpr size_t constructor = 0;
65+
66+// Not a real limit, just used for simpler accessors
67+static constexpr size_t unknown_size = 64;
65
68
66// A variant data class designed to provide some features of dynamic typing.
69// A variant data class designed to provide some features of dynamic typing.
67//
70//
src/Language/PureScript/CodeGen/Cpp.hs+1−1
@@ -879,7 +879,7 @@ dictIndexerToEnum repls (CppIndexer (CppSymbol prop) dict)
879 CppBinary Dot
879 CppBinary Dot
880 (CppIndexer
880 (CppIndexer
881 (CppAccessor (CppVar . identToCpp $ Ident prop) cls)
881 (CppAccessor (CppVar . identToCpp $ Ident prop) cls)
882− (CppCast (mapType 1) dict))
882+ (CppCast (mapType 0) dict))
883 (CppVar "second")
883 (CppVar "second")
884dictIndexerToEnum _ cpp = cpp
884dictIndexerToEnum _ cpp = cpp
885
885
src/Language/PureScript/CodeGen/Cpp/Common.hs+1
@@ -179,6 +179,7 @@ nameIsCppReserved name =
179 , "typename"
179 , "typename"
180 , "typeof"
180 , "typeof"
181 , "union"
181 , "union"
182+ , "unknown_size"
182 , "unsigned"
183 , "unsigned"
183 , "using"
184 , "using"
184 , "virtual"
185 , "virtual"
src/Language/PureScript/CodeGen/Cpp/Types.hs+5−1
@@ -128,7 +128,11 @@ voidType :: CppType
128voidType = CppPrimitive "void"
128voidType = CppPrimitive "void"
129
129
130mapType :: Int -> CppType
130mapType :: Int -> CppType
131+mapType = maptype
132+ where
133+ maptype 0 = mapprim "unknown_size"
134+ maptype n = mapprim $ show n
131−mapType n = CppPrimitive $ "any::map<" ++ show n ++ ">"
135+ mapprim s = CppPrimitive $ "any::map<" ++ s ++ ">"
132
136
133dataType :: Int -> CppType
137dataType :: Int -> CppType
134dataType n = CppPrimitive $ "any::data<" ++ show n ++ ">"
138dataType n = CppPrimitive $ "any::data<" ++ show n ++ ">"