git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add some support for platforms without exceptions (tested with Arduino)
commit9651f537f31b5ffb11a278f10e3ed1f153ea93d4 authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 17 Mar 2019, 20:01 (8 years ago) parent167944d
4 files changed+13−5
runtime/dictionary.h+1−1 runtime/purescript.cpp+2−2 runtime/purescript.h+8 src/CodeGen/Cpp/Printer.hs+2−2
runtime/dictionary.h+1−1
@@ -52,7 +52,7 @@ namespace purescript {
5252 return it->second;
5353 }
5454 }
55−#if !defined(NDEBUG) // if debug build
55+#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
5656 throw std::runtime_error("dictionary key \"" + std::string(key) + "\" not found");
5757#endif
5858 return null();
runtime/purescript.cpp+2−2
@@ -23,7 +23,7 @@ template class _template_::weak<boxed>;
2323template class _template_::recur<boxed>;
2424
2525boxed::boxed(const long n) : _int_(static_cast<int>(n)) {
26−#if !defined(NDEBUG)
26+#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
2727 if (n < std::numeric_limits<int>::min() || n > std::numeric_limits<int>::max()) {
2828 throw std::runtime_error("integer out of range");
2929 }
@@ -31,7 +31,7 @@ boxed::boxed(const long n) : _int_(static_cast<int>(n)) {
3131}
3232
3333boxed::boxed(const unsigned long n) : _int_(static_cast<int>(n)) {
34−#if !defined(NDEBUG)
34+#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
3535 if (n > std::numeric_limits<int>::max()) {
3636 throw std::runtime_error("integer out of range");
3737 }
runtime/purescript.h+8
@@ -21,6 +21,8 @@
2121#include <utility>
2222#if !defined(NDEBUG)
2323#include <limits>
24+#endif
25+#if !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
2426#include <stdexcept>
2527#endif
2628#include "functions.h"
@@ -218,6 +220,12 @@ namespace purescript {
218220
219221} // namespace purescript
220222
223+#if !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
224+#define THROW_(e) throw std::runtime_error(s)
225+#else
226+#define THROW_(e) return undefined
227+#endif
228+
221229#define DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR() \
222230 inline auto foreign() -> dict_t& {\
223231 static dict_t _;\
src/CodeGen/Cpp/Printer.hs+2−2
@@ -254,8 +254,8 @@ literals = mkPattern' match'
254254 match (ReturnNoResult _) = return $ emit "return undefined"
255255 -- match (Throw _ _) = return mempty
256256 match (Throw _ value) = mconcat <$> sequence
257− [ return $ emit "throw "
258− , return $ emit "std::runtime_error(\"PatternMatchFailure: \""
257+ [ return $ emit "THROW_("
258+ , return $ emit "\"PatternMatchFailure: \""
259259 , prettyPrintCpp' value
260260 , return $ emit ")"
261261 ]