Changed signature of 'Array.transform' function.

This commit is contained in:
Erik Svedäng 2017-10-13 13:44:27 +02:00
parent aee6e713b3
commit b9f57a9511
4 changed files with 27 additions and 15 deletions

View File

@ -116,7 +116,7 @@
(defn map-filter-reduce-stuff []
(let [stuff [3 5 8 9 10]
after (reduce + 0 (transform square (filter even? stuff)))]
after (reduce + 0 (transform square &(filter even? stuff)))]
(println (refstr after))))
(defn get-last-string [xs] ;; Should be generic preferably...

View File

@ -1,2 +1,9 @@
(defn print-char [c]
(IO.println &(Char.str c)))
(defn to-robber-lang [s]
)
(let [cs (String.chars s)]
(let [temp (Array.transform print-char &cs)] ())))
(defn main []
(to-robber-lang "erik"))

View File

@ -14,7 +14,7 @@ import Debug.Trace
templateCopyingMap :: (String, Binder)
templateCopyingMap = defineTypeParameterizedTemplate templateCreator path t
where fTy = FuncTy [VarTy "a"] (VarTy "b")
aTy = StructTy "Array" [VarTy "a"]
aTy = RefTy (StructTy "Array" [VarTy "a"])
bTy = StructTy "Array" [VarTy "b"]
path = SymPath ["Array"] "transform"
t = FuncTy [fTy, aTy] bTy
@ -22,23 +22,27 @@ templateCopyingMap = defineTypeParameterizedTemplate templateCreator path t
\typeEnv env ->
Template
t
(const (toTemplate "Array $NAME($(Fn [a] b) f, Array a)"))
(\(FuncTy [(FuncTy [_] _), _] _) ->
(const (toTemplate "Array $NAME($(Fn [a] b) f, Array* a)"))
(\(FuncTy [(FuncTy [_] outputTy), _] _) ->
(toTemplate $ unlines $
[ "$DECL { "
, " Array b;"
, " b.len = a.len;"
, " b.data = CARP_MALLOC(sizeof($b) * a.len);"
, " for(int i = 0; i < a.len; ++i) {"
, " (($b*)b.data)[i] = f((($a*)a.data)[i]); "
, " b.len = a->len;"
, " b.data = CARP_MALLOC(sizeof($b) * a->len);"
, " for(int i = 0; i < a->len; ++i) {"
, if outputTy == UnitTy
then " f((($a*)a->data)[i]); "
else " (($b*)b.data)[i] = f((($a*)a->data)[i]);"
, " }"
, " CARP_FREE(a.data);"
, " return b;"
, "}"
]))
(\(FuncTy [ft@(FuncTy [insideTypeA] _), arrayTypeA] arrayTypeB) ->
[defineFunctionTypeAlias ft, defineArrayTypeAlias arrayTypeA, defineArrayTypeAlias arrayTypeB] ++
depsForDeleteFunc typeEnv env insideTypeA)
(\(FuncTy [ft@(FuncTy [_] _), (RefTy arrayTypeA)] arrayTypeB) ->
[defineFunctionTypeAlias ft,
defineArrayTypeAlias arrayTypeA,
defineArrayTypeAlias arrayTypeB] ++
depsForDeleteFunc typeEnv env arrayTypeA ++
depsForDeleteFunc typeEnv env arrayTypeB)
-- | "Endofunctor Map"
templateEMap :: (String, Binder)

View File

@ -137,8 +137,9 @@ initialTypes rootEnv root = evalState (visit rootEnv root) 0
return $ do okBody <- visitedBody
okArgs <- sequence visitedArgs
return (XObj (Lst [defn, nameSymbol, XObj (Arr okArgs) argsi argst, okBody]) i funcTy)
XObj Defn _ _ : _ -> return (Left (InvalidObj Defn xobj))
XObj Defn _ _ : (XObj (Sym _) _ _) : (XObj (Arr _) _ _) : [] -> return (Left (NoFormsInBody xobj))
XObj Defn _ _ : _ -> return (Left (InvalidObj Defn xobj))
-- Def
def@(XObj Def _ _) : nameSymbol : expression : [] ->