mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Give up on making range a template, was probably a bad idea...
This commit is contained in:
parent
1ede414759
commit
571f46bd9d
@ -1,7 +1,7 @@
|
||||
(defmodule Array
|
||||
;; TODO: Move these to Template.hs so that the proper helper functions are generated
|
||||
(register str (Fn [(Ref (Array t))] String))
|
||||
(register range (Fn [Int Int] (Array Int)))
|
||||
;;(register range (Fn [Int Int] (Array Int)))
|
||||
(register sum (Fn [(Ref (Array Int))] Int))
|
||||
)
|
||||
|
||||
|
@ -42,16 +42,16 @@
|
||||
[val Int])
|
||||
|
||||
(defn set-stuff-in-array []
|
||||
(let [xs (range 0 10)]
|
||||
(let [xs [0 1 2 3 4 5 6 7 8 9]]
|
||||
(do
|
||||
(aset! (ref xs) 4 666)
|
||||
(aset! &xs 4 666)
|
||||
(println (ref (str (ref xs)))))))
|
||||
|
||||
(defn more-array []
|
||||
(let [xs [1 2 3 4]
|
||||
xs2 (pop-back xs)]
|
||||
(do
|
||||
(println (ref (str (ref (push-back xs2 500))))))))
|
||||
(println (refstr &(push-back xs2 500))))))
|
||||
|
||||
(defn using-the-form-to-specialize [x y]
|
||||
(+ x (the Double y)))
|
||||
|
@ -27,5 +27,5 @@
|
||||
(println &(Array.str (ref (ArrayExtension.fmap inc [10 20 30 40 50]))))
|
||||
))
|
||||
|
||||
;; (build)
|
||||
;; (run)
|
||||
(build)
|
||||
(run)
|
||||
|
@ -7,5 +7,4 @@
|
||||
(import String)
|
||||
(import Char)
|
||||
|
||||
(defn f [] (Array.nth [1 2 3] 0))
|
||||
(defn g [] (Array.count [1 2 3]))
|
||||
|
||||
|
@ -4,6 +4,7 @@ module Template where
|
||||
|
||||
import qualified Text.Parsec as Parsec
|
||||
import Text.Parsec ((<|>))
|
||||
import qualified Data.Set as Set
|
||||
import Debug.Trace
|
||||
|
||||
import Util
|
||||
@ -27,8 +28,9 @@ defineTemplate :: SymPath -> Ty -> [Token] -> [Token] -> (Ty -> [XObj]) -> (Stri
|
||||
defineTemplate path t declaration definition depsFunc =
|
||||
let (SymPath _ name) = path
|
||||
template = Template t (const declaration) (const definition) depsFunc
|
||||
i = Info 0 0 Set.empty 0
|
||||
defLst = [XObj (Deftemplate (TemplateCreator (\_ _ -> template))) Nothing Nothing, XObj (Sym path) Nothing Nothing]
|
||||
in (name, Binder (XObj (Lst defLst) Nothing (Just t)))
|
||||
in (name, Binder (XObj (Lst defLst) (Just i) (Just t)))
|
||||
|
||||
-- | The more advanced version of a template, where the code can vary depending on the type.
|
||||
defineTypeParameterizedTemplate :: TemplateCreator -> SymPath -> Ty -> (String, Binder)
|
||||
@ -368,6 +370,22 @@ templateCount = defineTemplate
|
||||
(toTemplate "$DECL { return (*a).len; }")
|
||||
(\(FuncTy [arrayType] _) -> [defineArrayTypeAlias arrayType])
|
||||
|
||||
-- templateRange :: (String, Binder)
|
||||
-- templateRange = defineTemplate
|
||||
-- (SymPath ["Array"] "range")
|
||||
-- (FuncTy [(VarTy "t"), (VarTy "t")] (StructTy "Array" [(VarTy "t")]))
|
||||
-- (toTemplate "Array $NAME ($t start, $t end)")
|
||||
-- (toTemplate (unlines [ "$DECL { "
|
||||
-- , " assert(end > start);"
|
||||
-- , " int length = end - start;"
|
||||
-- , " Array a = { .len = length, .data = malloc(sizeof($t) * length) };"
|
||||
-- , " for(int i = 0; i < length; i++) {"
|
||||
-- , " (($t*)a.data)[i] = start + ($t)i;"
|
||||
-- , " }"
|
||||
-- , " return a;"
|
||||
-- , "}"]))
|
||||
-- (\(FuncTy [t, _] _) -> [defineArrayTypeAlias (StructTy "Array" [t])] ++ )
|
||||
|
||||
templateDeleteArray :: (String, Binder)
|
||||
templateDeleteArray = defineTypeParameterizedTemplate templateCreator path t
|
||||
where templateCreator = TemplateCreator $
|
||||
|
Loading…
Reference in New Issue
Block a user