git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add some support for platforms without exceptions (tested with Arduino)
9651f53Andy Arvanitis
runtime/dictionary.h+1−1
@@ -52,7 +52,7 @@ namespace purescript {
52 return it->second;
52 return it->second;
53 }
53 }
54 }
54 }
55−#if !defined(NDEBUG) // if debug build
55+#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
56 throw std::runtime_error("dictionary key \"" + std::string(key) + "\" not found");
56 throw std::runtime_error("dictionary key \"" + std::string(key) + "\" not found");
57#endif
57#endif
58 return null();
58 return null();
runtime/purescript.cpp+2−2
@@ -23,7 +23,7 @@ template class _template_::weak<boxed>;
23template class _template_::recur<boxed>;
23template class _template_::recur<boxed>;
24
24
25boxed::boxed(const long n) : _int_(static_cast<int>(n)) {
25boxed::boxed(const long n) : _int_(static_cast<int>(n)) {
26−#if !defined(NDEBUG)
26+#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
27 if (n < std::numeric_limits<int>::min() || n > std::numeric_limits<int>::max()) {
27 if (n < std::numeric_limits<int>::min() || n > std::numeric_limits<int>::max()) {
28 throw std::runtime_error("integer out of range");
28 throw std::runtime_error("integer out of range");
29 }
29 }
@@ -31,7 +31,7 @@ boxed::boxed(const long n) : _int_(static_cast<int>(n)) {
31}
31}
32
32
33boxed::boxed(const unsigned long n) : _int_(static_cast<int>(n)) {
33boxed::boxed(const unsigned long n) : _int_(static_cast<int>(n)) {
34−#if !defined(NDEBUG)
34+#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
35 if (n > std::numeric_limits<int>::max()) {
35 if (n > std::numeric_limits<int>::max()) {
36 throw std::runtime_error("integer out of range");
36 throw std::runtime_error("integer out of range");
37 }
37 }
runtime/purescript.h+8
@@ -21,6 +21,8 @@
21#include <utility>
21#include <utility>
22#if !defined(NDEBUG)
22#if !defined(NDEBUG)
23#include <limits>
23#include <limits>
24+#endif
25+#if !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
24#include <stdexcept>
26#include <stdexcept>
25#endif
27#endif
26#include "functions.h"
28#include "functions.h"
@@ -218,6 +220,12 @@ namespace purescript {
218
220
219} // namespace purescript
221} // namespace purescript
220
222
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+
221#define DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR() \
229#define DEFINE_FOREIGN_DICTIONARY_AND_ACCESSOR() \
222 inline auto foreign() -> dict_t& {\
230 inline auto foreign() -> dict_t& {\
223 static dict_t _;\
231 static dict_t _;\
src/CodeGen/Cpp/Printer.hs+2−2
@@ -254,8 +254,8 @@ literals = mkPattern' match'
254 match (ReturnNoResult _) = return $ emit "return undefined"
254 match (ReturnNoResult _) = return $ emit "return undefined"
255 -- match (Throw _ _) = return mempty
255 -- match (Throw _ _) = return mempty
256 match (Throw _ value) = mconcat <$> sequence
256 match (Throw _ value) = mconcat <$> sequence
257− [ return $ emit "throw "
257+ [ return $ emit "THROW_("
258− , return $ emit "std::runtime_error(\"PatternMatchFailure: \""
258+ , return $ emit "\"PatternMatchFailure: \""
259 , prettyPrintCpp' value
259 , prettyPrintCpp' value
260 , return $ emit ")"
260 , return $ emit ")"
261 ]
261 ]