-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathpurescript.cpp
More file actions
59 lines (51 loc) · 1.66 KB
/
purescript.cpp
File metadata and controls
59 lines (51 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
///////////////////////////////////////////////////////////////////////////////
//
// Module : purescript.cpp
// Copyright : (c) Andy Arvanitis 2019
// License : BSD
//
// Maintainer : Andy Arvanitis
// Stability : experimental
// Portability :
//
// Basic types and functions to support purescript-to-C++ rendering
//
///////////////////////////////////////////////////////////////////////////////
//
#include "purescript.h"
namespace purescript {
template class _template_::fn_t<boxed>;
template class _template_::eff_fn_t<boxed>;
template class _template_::dict_t<boxed>;
template class _template_::weak<boxed>;
template class _template_::recur<boxed>;
boxed::boxed(const long n) : _int_(static_cast<int>(n)) {
#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
if (n < std::numeric_limits<int>::min() || n > std::numeric_limits<int>::max()) {
throw std::runtime_error("integer out of range");
}
#endif
}
boxed::boxed(const unsigned long n) : _int_(static_cast<int>(n)) {
#if !defined(NDEBUG) && !defined(PURESCRIPT_DISABLE_EXCEPTIONS)
if (n > std::numeric_limits<int>::max()) {
throw std::runtime_error("integer out of range");
}
#endif
}
auto boxed::operator[](const int index) const -> const boxed& {
#if !defined(NDEBUG)
return static_cast<const array_t*>(shared.get())->at(index);
#else
return (*static_cast<const array_t*>(shared.get()))[index];
#endif
}
auto boxed::operator[](const int index) -> boxed& {
#if !defined(NDEBUG)
return static_cast<array_t*>(shared.get())->at(index);
#else
return (*static_cast<array_t*>(shared.get()))[index];
#endif
}
const boxed undefined;
} // namespace purescript