git.iko.soy/rowtype-yoga/purescript-native
on cpp help sign in
59 lines 1.7 kB history raw
1///////////////////////////////////////////////////////////////////////////////
2//
3// Module : purescript.cpp
4// Copyright : (c) Andy Arvanitis 2019
5// License : BSD
6//
7// Maintainer : Andy Arvanitis
8// Stability : experimental
9// Portability :
10//
11// Basic types and functions to support purescript-to-C++ rendering
12//
13///////////////////////////////////////////////////////////////////////////////
14//
15#include "purescript.h"
17namespace purescript {
19template class _template_::fn_t<boxed>;
20template class _template_::eff_fn_t<boxed>;
21template class _template_::dict_t<boxed>;
22template class _template_::weak<boxed>;
23template class _template_::recur<boxed>;
25boxed::boxed(const long n) : _int_(static_cast<int>(n)) {
26#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
27 if (n < std::numeric_limits<int>::min() || n > std::numeric_limits<int>::max()) {
28 throw std::runtime_error("integer out of range");
29 }
30#endif
33boxed::boxed(const unsigned long n) : _int_(static_cast<int>(n)) {
34#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
35 if (n > std::numeric_limits<int>::max()) {
36 throw std::runtime_error("integer out of range");
37 }
38#endif
41auto boxed::operator[](const int index) const -> const boxed& {
42#if !defined(NDEBUG)
43 return static_cast<const array_t*>(shared.get())->at(index);
44#else
45 return (*static_cast<const array_t*>(shared.get()))[index];
46#endif
49auto boxed::operator[](const int index) -> boxed& {
50#if !defined(NDEBUG)
51 return static_cast<array_t*>(shared.get())->at(index);
52#else
53 return (*static_cast<array_t*>(shared.get()))[index];
54#endif
57const boxed undefined;
59} // namespace purescript