git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: fix an issue with new maps on Visual Studio compiler
commit19efe3733fbf0b62bf839843b167085086b37f37 authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 30 Oct 2016, 17:34 (10 years ago) parent5480ee9
5 files changed+16−8
pcc/include/purescript.cc+4−4 pcc/include/purescript.hh+5−2 src/Language/PureScript/CodeGen/Cpp.hs+1−1 src/Language/PureScript/CodeGen/Cpp/Common.hs+1 src/Language/PureScript/CodeGen/Cpp/Types.hs+5−1
pcc/include/purescript.cc+4−4
@@ -90,8 +90,8 @@ static const any invalid_key(nullptr);
9090
9191auto any::operator[](const symbol_t key) const -> const any& {
9292 // TODO: assumes at least one element -- safe assumption?
93− const auto& m = cast<map<1>>(*this);
94− any::map<1>::size_type i = 0;
93+ const auto& m = cast<map<unknown_size>>(*this);
94+ std::remove_reference<decltype(m)>::type::size_type i = 0;
9595 do {
9696 if (m[i].first == key) {
9797 return m[i].second;
@@ -113,8 +113,8 @@ auto any::operator[](const any& rhs) const -> const any& {
113113
114114auto any::contains(const symbol_t key) const -> bool {
115115 // TODO: assumes at least one element -- safe assumption?
116− const auto& m = cast<map<1>>(*this);
117− any::map<1>::size_type i = 0;
116+ const auto& m = cast<map<unknown_size>>(*this);
117+ std::remove_reference<decltype(m)>::type::size_type i = 0;
118118 do {
119119 if (m[i].first == key) {
120120 return true;
pcc/include/purescript.hh+5−2
@@ -60,8 +60,11 @@ public:
6060 runtime_error(const char message[]) : std::runtime_error(std::string(message)) {}
6161};
6262
63−const bool undefined = false;
64−const size_t constructor = 0;
63+constexpr bool undefined = false;
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;
6568
6669// A variant data class designed to provide some features of dynamic typing.
6770//
src/Language/PureScript/CodeGen/Cpp.hs+1−1
@@ -879,7 +879,7 @@ dictIndexerToEnum repls (CppIndexer (CppSymbol prop) dict)
879879 CppBinary Dot
880880 (CppIndexer
881881 (CppAccessor (CppVar . identToCpp $ Ident prop) cls)
882− (CppCast (mapType 1) dict))
882+ (CppCast (mapType 0) dict))
883883 (CppVar "second")
884884dictIndexerToEnum _ cpp = cpp
885885
src/Language/PureScript/CodeGen/Cpp/Common.hs+1
@@ -179,6 +179,7 @@ nameIsCppReserved name =
179179 , "typename"
180180 , "typeof"
181181 , "union"
182+ , "unknown_size"
182183 , "unsigned"
183184 , "using"
184185 , "virtual"
src/Language/PureScript/CodeGen/Cpp/Types.hs+5−1
@@ -128,7 +128,11 @@ voidType :: CppType
128128voidType = CppPrimitive "void"
129129
130130mapType :: Int -> CppType
131−mapType n = CppPrimitive $ "any::map<" ++ show n ++ ">"
131+mapType = maptype
132+ where
133+ maptype 0 = mapprim "unknown_size"
134+ maptype n = mapprim $ show n
135+ mapprim s = CppPrimitive $ "any::map<" ++ s ++ ">"
132136
133137dataType :: Int -> CppType
134138dataType n = CppPrimitive $ "any::data<" ++ show n ++ ">"