Tweaks to the memory logger. Also, replicate now takes a reference.

This commit is contained in:
Erik Svedäng 2017-09-29 14:54:49 +02:00
parent b17780aa79
commit 65d17b732c
3 changed files with 10 additions and 6 deletions

View File

@ -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) {

View File

@ -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))))

View File

@ -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;"
, "}"]))