Give Array.str more memory (quick fix).

This commit is contained in:
Erik Svedäng 2017-12-01 11:43:18 +01:00
parent 9625afa194
commit d654d92459
2 changed files with 11 additions and 5 deletions

View File

@ -6,6 +6,8 @@
* 1.0 - The completed version of the language with all planned features and extra nice ergonomics.
## Critical Bugs
* [0.3] Reloading destroys interfaces!!!
* [0.3] Allocate enough memory in the Array.str and struct.str functions
* [0.3] Can't define globals with heap allocated types (String, structs, etc.)
* [0.3] The compiler can crash when defining invalid struct types, it should present nice errors instead
* [0.3] When loading game.carp the SDL modules fail because of invalid paths, the CARP_DIR + path isn't searched it seems

View File

@ -462,11 +462,11 @@ templateStrArray = defineTypeParameterizedTemplate templateCreator path t
strTy :: TypeEnv -> Env -> Ty -> [Token]
strTy typeEnv env (StructTy "Array" [innerType]) =
[ TokC ""
, TokC " string buffer = CARP_MALLOC(1024);\n"
, TokC " string buffer = CARP_MALLOC(32768); // very arbitrary! TODO: CALCULATE!\n"
, TokC " string bufferPtr = buffer;\n"
, TokC " string temp = NULL;\n"
, TokC "\n"
, TokC " snprintf(buffer, 1024, \"[\");\n"
, TokC " snprintf(buffer, 32768, \"[\");\n"
, TokC " bufferPtr += 1;\n"
, TokC "\n"
, TokC " for(int i = 0; i < a->len; i++) {\n"
@ -474,7 +474,7 @@ strTy typeEnv env (StructTy "Array" [innerType]) =
, TokC " }\n"
, TokC "\n"
, TokC " if(a->len > 0) { bufferPtr -= 1; }\n"
, TokC " snprintf(bufferPtr, 1024, \"]\");\n"
, TokC " snprintf(bufferPtr, 32768, \"]\");\n"
, TokC " return buffer;\n"
]
strTy _ _ _ = []
@ -485,9 +485,13 @@ insideArrayStr typeEnv env t =
FunctionFound functionFullName ->
let takeAddressOrNot = if isManaged typeEnv t then "&" else ""
in unlines [ " temp = " ++ functionFullName ++ "(" ++ takeAddressOrNot ++ "((" ++ tyToC t ++ "*)a->data)[i]);"
, " snprintf(bufferPtr, 1024, \"%s \", temp);"
, " snprintf(bufferPtr, 32768, \"%s \", temp);"
, " bufferPtr += strlen(temp) + 1;"
, " if(temp) { CARP_FREE(temp); temp = NULL; }"
, " assert((bufferPtr - buffer) < 16000); // out of bounds"
, " if(temp) {"
, " CARP_FREE(temp);"
, " temp = NULL;"
, " }"
]
FunctionNotFound msg -> error msg
FunctionIgnored -> " /* Ignore type inside Array: '" ++ show t ++ "' ??? */\n"