git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
6a9cb43Andy Arvanitis
pcc/runtime/purescript.hh+12−6
@@ -251,14 +251,9 @@ class any {
251 any(T&& val, typename std::enable_if<std::is_assignable<managed<void>,T>::value>::type* = 0) noexcept
251 any(T&& val, typename std::enable_if<std::is_assignable<managed<void>,T>::value>::type* = 0) noexcept
252 : tag(Tag::Pointer), p(std::move(val)) {}
252 : tag(Tag::Pointer), p(std::move(val)) {}
253
253
254− // Explicit void* to raw pointer value
255− template <typename T>
256− any(const T& val, typename std::enable_if<std::is_same<T,void*>::value>::type* = 0) noexcept
257− : tag(Tag::RawPointer), v(val) {}
254+ any(void * val) noexcept : tag(Tag::RawPointer), v(val) {}
258−
259 any(nullptr_t) noexcept : tag(Tag::RawPointer), v(nullptr) {}
255 any(nullptr_t) noexcept : tag(Tag::RawPointer), v(nullptr) {}
260
256
261−
262#if !defined(USE_GC)
257#if !defined(USE_GC)
263 private:
258 private:
264 auto destruct() const noexcept -> void {
259 auto destruct() const noexcept -> void {
@@ -337,6 +332,17 @@ class any {
337 operator const array&() const;
332 operator const array&() const;
338 operator const record&() const;
333 operator const record&() const;
339
334
335+ operator void *() const {
336+ return extractPointer(IF_DEBUG(Tag::RawPointer));
337+ }
338+
339+ template <typename T,
340+ typename = typename std::enable_if<std::is_pointer<T>::value &&
341+ std::is_class<typename std::remove_pointer<T>::type>::value>::type>
342+ operator T() const {
343+ return static_cast<T>(extractPointer(IF_DEBUG(Tag::RawPointer)));
344+ }
345+
340 auto operator[](const size_t) const -> const any&;
346 auto operator[](const size_t) const -> const any&;
341 auto at(const char *) const -> const any&;
347 auto at(const char *) const -> const any&;
342 auto size() const -> size_t;
348 auto size() const -> size_t;
src/Language/PureScript/CodeGen/Cpp.hs+7−16
@@ -358,10 +358,10 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
358 valueToCpp (Var (_, _, _, Just IsNewtype) ident) = return $ varToCpp ident
358 valueToCpp (Var (_, _, _, Just IsNewtype) ident) = return $ varToCpp ident
359 valueToCpp (Var (_, _, _, Just (IsConstructor _ [])) ident) = return $ CppApp (varToCpp ident) []
359 valueToCpp (Var (_, _, _, Just (IsConstructor _ [])) ident) = return $ CppApp (varToCpp ident) []
360 valueToCpp (Var (_, _, Just ty, _) ident@(Qualified (Just _) _))
360 valueToCpp (Var (_, _, Just ty, _) ident@(Qualified (Just _) _))
361− | arity ty > 0 = return . curriedName' $ varToCpp ident
361+ | arity ty > 0 = return . curriedVar $ varToCpp ident
362 valueToCpp (Var (_, _, Nothing, _) ident@(Qualified (Just _) _))
362 valueToCpp (Var (_, _, Nothing, _) ident@(Qualified (Just _) _))
363 | Just (ty, _, _) <- M.lookup ident (E.names env)
363 | Just (ty, _, _) <- M.lookup ident (E.names env)
364− , arity ty > 0 = return . curriedName' $ varToCpp ident
364+ , arity ty > 0 = return . curriedVar $ varToCpp ident
365 valueToCpp (Var _ ident) = return $ varToCpp ident
365 valueToCpp (Var _ ident) = return $ varToCpp ident
366 valueToCpp (Literal _ (NumericLiteral n)) = return (CppNumericLiteral n)
366 valueToCpp (Literal _ (NumericLiteral n)) = return (CppNumericLiteral n)
367 valueToCpp (Literal _ (StringLiteral s)) = return (CppStringLiteral s)
367 valueToCpp (Literal _ (StringLiteral s)) = return (CppStringLiteral s)
@@ -410,7 +410,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
410 zip
410 zip
411 (CppSymbol . mkString <$> (sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
411 (CppSymbol . mkString <$> (sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
412 args'
412 args'
413− Var _ (Qualified (Just _) _) -> applied f args' curriedName'
413+ Var _ (Qualified (Just _) _) -> applied f args' curriedVar
414 _ -> applied f args' id
414 _ -> applied f args' id
415 where
415 where
416 applied f args g = flip (foldl (\fn a -> CppApp (g fn) [a])) args <$> valueToCpp f
416 applied f args g = flip (foldl (\fn a -> CppApp (g fn) [a])) args <$> valueToCpp f
@@ -745,20 +745,11 @@ optIndexers classes = everywhereOnCpp dictIndexerToEnum
745 dictIndexerToEnum cpp = cpp
745 dictIndexerToEnum cpp = cpp
746
746
747---------------------------------------------------------------------------------------------------
747---------------------------------------------------------------------------------------------------
748−curriedName :: Text -> Text
748+curriedVar :: Cpp -> Cpp
749---------------------------------------------------------------------------------------------------
749---------------------------------------------------------------------------------------------------
750−curriedName name
751− | Text.null name = name
752−curriedName name
753− | Text.head name == '*' = name
754− | otherwise = '*' `Text.cons` name
755−
756−---------------------------------------------------------------------------------------------------
757−curriedName' :: Cpp -> Cpp
758−---------------------------------------------------------------------------------------------------
759−curriedName' (CppVar name) = CppVar (curriedName name)
750+curriedVar (CppVar name) = CppVar (curriedName name)
760−curriedName' (CppAccessor a b) = CppAccessor (curriedName' a) b
751+curriedVar (CppAccessor a b) = CppAccessor (curriedVar a) b
761−curriedName' cpp = cpp
752+curriedVar cpp = cpp
762
753
763---------------------------------------------------------------------------------------------------
754---------------------------------------------------------------------------------------------------
764primFn :: T.Type -> ([CppType], Maybe CppType)
755primFn :: T.Type -> ([CppType], Maybe CppType)
src/Language/PureScript/CodeGen/Cpp/Common.hs+10−4
@@ -186,8 +186,6 @@ nameIsCppReserved name =
186 , "noexcept"
186 , "noexcept"
187 , "not"
187 , "not"
188 , "not_eq"
188 , "not_eq"
189− , "NULL"
190− , "null"
191 , "nullptr"
189 , "nullptr"
192 , "nullptr_t"
190 , "nullptr_t"
193 , "operator"
191 , "operator"
@@ -263,8 +261,16 @@ moduleNameToCpp (ModuleName pns) =
263--
261--
264properNameIsCppReserved :: Text -> Bool
262properNameIsCppReserved :: Text -> Bool
265properNameIsCppReserved name =
263properNameIsCppReserved name =
264+ name `elem` [ "DEFINE_SYMBOL"
265+ , "NULL"
266− name `elem` [ "Private"
266+ , "Private"
267 , "PureScript"
267 , "PureScript"
268 , "SYM"
268 , "SYM"
269− , "DEFINE_SYMBOL"
270 ]
269 ]
270+
271+curriedName :: Text -> Text
272+curriedName name
273+ | T.null name = name
274+curriedName name
275+ | T.head name == '*' = name
276+ | otherwise = '*' `T.cons` name
src/Language/PureScript/CodeGen/Cpp/Optimizer/Common.hs+3−2
@@ -18,9 +18,10 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Common where
18import Prelude.Compat
18import Prelude.Compat
19
19
20import Data.Maybe (fromMaybe)
20import Data.Maybe (fromMaybe)
21−import Data.Text (Text, cons)
21+import Data.Text (Text)
22
22
23import Language.PureScript.CodeGen.Cpp.AST
23import Language.PureScript.CodeGen.Cpp.AST
24+import Language.PureScript.CodeGen.Cpp.Common
24
25
25applyAll :: [a -> a] -> a -> a
26applyAll :: [a -> a] -> a -> a
26applyAll = foldl1 (.)
27applyAll = foldl1 (.)
@@ -82,7 +83,7 @@ removeFromBlock _ cpp = cpp
82
83
83isFn :: (Text, Text) -> Cpp -> Bool
84isFn :: (Text, Text) -> Cpp -> Bool
84isFn (moduleName, fnName) (CppAccessor (CppVar x) (CppVar y)) =
85isFn (moduleName, fnName) (CppAccessor (CppVar x) (CppVar y)) =
85− (x == fnName || x == ('*' `cons` fnName)) && y == moduleName
86+ (x == fnName || x == curriedName fnName) && y == moduleName
86isFn _ _ = False
87isFn _ _ = False
87
88
88isDict :: (Text, Text) -> Cpp -> Bool
89isDict :: (Text, Text) -> Cpp -> Bool
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+13−3
@@ -28,7 +28,7 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
28 ) where
28 ) where
29
29
30import Prelude.Compat
30import Prelude.Compat
31−import Data.Text (Text, cons)
31+import Data.Text (Text)
32
32
33import Control.Monad.Supply.Class (MonadSupply, freshName)
33import Control.Monad.Supply.Class (MonadSupply, freshName)
34
34
@@ -144,7 +144,17 @@ inlineNonClassFunction (m, op) f = everywhereOnCpp convert
144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
145 convert other = other
145 convert other = other
146 isOp (CppAccessor (CppVar longForm) (CppVar m')) =
146 isOp (CppAccessor (CppVar longForm) (CppVar m')) =
147− m == m' && (longForm == safeName op || longForm == ('*' `cons` safeName op))
147+ m == m' && (longForm == safeName op || longForm == (curriedName $ safeName op))
148+ isOp _ = False
149+
150+inlineFunctionWithDict :: (Text, Text) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
151+inlineFunctionWithDict (m, op) f = everywhereOnCpp convert
152+ where
153+ convert :: Cpp -> Cpp
154+ convert (CppApp (CppApp (CppApp op' [_]) [x]) [y]) | isOp op' = f x y
155+ convert other = other
156+ isOp (CppAccessor (CppVar longForm) (CppVar m')) =
157+ m == m' && (longForm == safeName op || longForm == (curriedName $ safeName op))
148 isOp _ = False
158 isOp _ = False
149
159
150inlineCommonOperators :: Cpp -> Cpp
160inlineCommonOperators :: Cpp -> Cpp
@@ -206,7 +216,7 @@ inlineCommonOperators = applyAll $
206
216
207 , inlineNonClassFunction (C.dataFunction, C.apply) $ \f x -> CppApp f [x]
217 , inlineNonClassFunction (C.dataFunction, C.apply) $ \f x -> CppApp f [x]
208 , inlineNonClassFunction (C.dataFunction, C.applyFlipped) $ \x f -> CppApp f [x]
218 , inlineNonClassFunction (C.dataFunction, C.applyFlipped) $ \x f -> CppApp f [x]
209− , inlineNonClassFunction (C.dataArray, C.unsafeIndex) $ flip CppIndexer
219+ , inlineFunctionWithDict (C.dataArray, C.unsafeIndex) $ flip CppIndexer
210 ] ++
220 ] ++
211 []
221 []
212 -- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
222 -- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs+3−2
@@ -86,7 +86,8 @@ magicDo' = everywhereOnCpp undo . everywhereOnCppTopDown convert
86 -- Check if an expression represents the polymorphic pure or return function
86 -- Check if an expression represents the polymorphic pure or return function
87 isPurePoly = isFn (C.controlApplicative, C.pure')
87 isPurePoly = isFn (C.controlApplicative, C.pure')
88 -- Check if an expression represents a function in the Eff module
88 -- Check if an expression represents a function in the Eff module
89− isEffFunc name (CppAccessor (CppVar name') (CppVar eff)) = eff == C.eff && name == name'
89+ isEffFunc name (CppAccessor (CppVar name') (CppVar eff)) =
90+ eff == C.eff && (name == name' || curriedName name == name')
90 isEffFunc _ _ = False
91 isEffFunc _ _ = False
91
92
92 -- Remove __do function applications which remain after desugaring
93 -- Remove __do function applications which remain after desugaring
@@ -131,7 +132,7 @@ inlineST = everywhereOnCpp convertBlock
131 if agg then CppAssignment ref (CppApp func [ref]) else CppAssignment (CppAccessor (CppVar C.stRefValue) ref) (CppApp func [CppAccessor (CppVar C.stRefValue) ref])
132 if agg then CppAssignment ref (CppApp func [ref]) else CppAssignment (CppAccessor (CppVar C.stRefValue) ref) (CppApp func [CppAccessor (CppVar C.stRefValue) ref])
132 convert _ other = other
133 convert _ other = other
133 -- Check if an expression represents a function in the ST module
134 -- Check if an expression represents a function in the ST module
134− isSTFunc name (CppAccessor (CppVar name') (CppVar st)) = st == C.st && name == name'
135+ isSTFunc name (CppAccessor (CppVar name') (CppVar st)) = st == C.st && (name == name' || curriedName name == name')
135 isSTFunc _ _ = False
136 isSTFunc _ _ = False
136 -- Find all ST Refs initialized in this block
137 -- Find all ST Refs initialized in this block
137 findSTRefsIn = everythingOnCpp (++) isSTRef
138 findSTRefsIn = everythingOnCpp (++) isSTRef