mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Tweaks to the memory logger. Also, replicate now takes a reference.
This commit is contained in:
parent
b17780aa79
commit
65d17b732c
@ -112,7 +112,11 @@ void String_delete(string s) {
|
||||
}
|
||||
|
||||
string String_copy(string *s) {
|
||||
return strdup(*s);
|
||||
char *ptr = strdup(*s);
|
||||
#if LOG_MEMORY
|
||||
printf("STRDUP: %p\n", ptr);
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
bool String__EQ_(string *a, string *b) {
|
||||
|
@ -10,5 +10,5 @@
|
||||
(defn exclaim [x] (String.append x @"!"))
|
||||
|
||||
(defn main []
|
||||
(let [stuff (map exclaim (replicate 2 @"Yo"))]
|
||||
(let [stuff (replicate 3 "Yo")]
|
||||
(println &(Array.str &stuff))))
|
||||
|
@ -181,12 +181,12 @@ templateNth =
|
||||
templateReplicate :: (String, Binder)
|
||||
templateReplicate = defineTypeParameterizedTemplate templateCreator path t
|
||||
where path = SymPath ["Array"] "replicate"
|
||||
t = FuncTy [IntTy, VarTy "t"] (StructTy "Array" [VarTy "t"])
|
||||
t = FuncTy [IntTy, (RefTy (VarTy "t"))] (StructTy "Array" [VarTy "t"])
|
||||
templateCreator = TemplateCreator $
|
||||
\typeEnv env ->
|
||||
Template
|
||||
t
|
||||
(const (toTemplate "Array $NAME(int n, $t elem)"))
|
||||
(const (toTemplate "Array $NAME(int n, $t *elem)"))
|
||||
(\(FuncTy [_, _] arrayType) ->
|
||||
let StructTy _ [insideType] = arrayType
|
||||
copierType = (FuncTy [(RefTy insideType)] insideType)
|
||||
@ -200,8 +200,8 @@ templateReplicate = defineTypeParameterizedTemplate templateCreator path t
|
||||
, " Array a; a.len = n; a.data = CARP_MALLOC(sizeof($t) * n);"
|
||||
, " for(int i = 0; i < n; ++i) {"
|
||||
, " (($t*)a.data)[i] = " ++ case copierPath of
|
||||
Just p -> pathToC p ++ "(&elem);"
|
||||
Nothing -> "elem;"
|
||||
Just p -> pathToC p ++ "(elem);"
|
||||
Nothing -> "*elem;"
|
||||
, " }"
|
||||
, " return a;"
|
||||
, "}"]))
|
||||
|
Loading…
Reference in New Issue
Block a user