git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: keep 'undefined' and make it a (dummy) value
6dd8b1dAndy Arvanitis
pcc/include/purescript.cc+7−15
@@ -157,28 +157,20 @@ any::~any() {
157 return (*t)(unthunk);
157 return (*t)(unthunk);
158 }
158 }
159
159
160− auto any::call(const any& a) -> any {
161− assert(a.type == Type::EffFunction || a.type == Type::Function);
162− if (a.type == Type::EffFunction) {
163− return (*a.e)();
164− } else {
165− return (*a.f)(false);
166− }
167− }
168−
169 auto any::operator()() const -> any {
160 auto any::operator()() const -> any {
170− if (type == Type::EffFunction || type == Type::Function) {
161+ if (type == Type::EffFunction) {
171− return call(*this);
162+ return (*e)();
172 }
163 }
173− assert(type == Type::Thunk);
174 const any* valuePtr = this;
164 const any* valuePtr = this;
175 do {
165 do {
166+ assert(valuePtr->type == Type::Thunk);
176 const any& value = (*valuePtr->t)(unthunk);
167 const any& value = (*valuePtr->t)(unthunk);
177− if (value.type != Type::Thunk) {
168+ if (value.type == Type::EffFunction) {
178− return call(value);
169+ return (*value.e)();
179 }
170 }
180 valuePtr = &value;
171 valuePtr = &value;
181− } while (true);
172+ } while (valuePtr->type != Type::Unknown);
173+ return nullptr;
182 }
174 }
183
175
184 any::operator long() const {
176 any::operator long() const {
pcc/include/purescript.hh+2−2
@@ -41,6 +41,8 @@ using string = std::string;
41using runtime_error = std::runtime_error;
41using runtime_error = std::runtime_error;
42using nullptr_t = std::nullptr_t;
42using nullptr_t = std::nullptr_t;
43
43
44+const bool undefined = false;
45+
44// A variant data class designed to provide some features of dynamic typing.
46// A variant data class designed to provide some features of dynamic typing.
45//
47//
46class any {
48class any {
@@ -246,8 +248,6 @@ class any {
246
248
247 auto operator()() const -> any;
249 auto operator()() const -> any;
248
250
249− static auto call(const any& a) -> any;
250−
251 operator long() const;
251 operator long() const;
252 operator double() const;
252 operator double() const;
253 operator bool() const;
253 operator bool() const;
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs−1
@@ -73,7 +73,6 @@ optimize' cpp = do
73 , magicDo opts
73 , magicDo opts
74 , removeCodeAfterReturnStatements
74 , removeCodeAfterReturnStatements
75 , removeUnusedArg
75 , removeUnusedArg
76− , removeUndefinedApp
77 , unThunk
76 , unThunk
78 , etaConvert
77 , etaConvert
79 , evaluateIifes
78 , evaluateIifes
src/Language/PureScript/CodeGen/Cpp/Optimizer/Unused.hs−6
@@ -35,9 +35,3 @@ removeUnusedArg = everywhereOnCpp convert
35 convert (CppFunction name [(arg,atyp)] rtyp qs body)
35 convert (CppFunction name [(arg,atyp)] rtyp qs body)
36 | arg == C.__unused = CppFunction name [("",atyp)] rtyp qs body
36 | arg == C.__unused = CppFunction name [("",atyp)] rtyp qs body
37 convert cpp = cpp
37 convert cpp = cpp
38−
39−removeUndefinedApp :: Cpp -> Cpp
40−removeUndefinedApp = everywhereOnCpp convert
41− where
42− convert (CppApp fn [CppVar arg]) | arg == C.undefined = CppApp fn []
43− convert cpp = cpp