git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: keep 'undefined' and make it a (dummy) value
commit6dd8b1dfe4deac67f9ef0a9fc77672c374a1cedd authorAndy Arvanitis <andyarvanitis@gmail.com> dateSat 7 Nov 2015, 10:46 (11 years ago) parent502d3bb
4 files changed+9−24
pcc/include/purescript.cc+7−15 pcc/include/purescript.hh+2−2 src/Language/PureScript/CodeGen/Cpp/Optimizer.hs−1 src/Language/PureScript/CodeGen/Cpp/Optimizer/Unused.hs−6
pcc/include/purescript.cc+7−15
@@ -157,28 +157,20 @@ any::~any() {
157157 return (*t)(unthunk);
158158 }
159159
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−
169160 auto any::operator()() const -> any {
170− if (type == Type::EffFunction || type == Type::Function) {
171− return call(*this);
161+ if (type == Type::EffFunction) {
162+ return (*e)();
172163 }
173− assert(type == Type::Thunk);
174164 const any* valuePtr = this;
175165 do {
166+ assert(valuePtr->type == Type::Thunk);
176167 const any& value = (*valuePtr->t)(unthunk);
177− if (value.type != Type::Thunk) {
178− return call(value);
168+ if (value.type == Type::EffFunction) {
169+ return (*value.e)();
179170 }
180171 valuePtr = &value;
181− } while (true);
172+ } while (valuePtr->type != Type::Unknown);
173+ return nullptr;
182174 }
183175
184176 any::operator long() const {
pcc/include/purescript.hh+2−2
@@ -41,6 +41,8 @@ using string = std::string;
4141using runtime_error = std::runtime_error;
4242using nullptr_t = std::nullptr_t;
4343
44+const bool undefined = false;
45+
4446// A variant data class designed to provide some features of dynamic typing.
4547//
4648class any {
@@ -246,8 +248,6 @@ class any {
246248
247249 auto operator()() const -> any;
248250
249− static auto call(const any& a) -> any;
250−
251251 operator long() const;
252252 operator double() const;
253253 operator bool() const;
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs−1
@@ -73,7 +73,6 @@ optimize' cpp = do
7373 , magicDo opts
7474 , removeCodeAfterReturnStatements
7575 , removeUnusedArg
76− , removeUndefinedApp
7776 , unThunk
7877 , etaConvert
7978 , evaluateIifes
src/Language/PureScript/CodeGen/Cpp/Optimizer/Unused.hs−6
@@ -35,9 +35,3 @@ removeUnusedArg = everywhereOnCpp convert
3535 convert (CppFunction name [(arg,atyp)] rtyp qs body)
3636 | arg == C.__unused = CppFunction name [("",atyp)] rtyp qs body
3737 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