@@ -3227,6 +3227,16 @@ template functionBody(Function fn, Boolean inFunc)
32273227 case fn as RECORD_CONSTRUCTOR(__) then functionBodyRecordConstructor(fn)
32283228end functionBody;
32293229
3230+ template addRoots(Variable var)
3231+ "template to add the roots, only the meta-types are added!"
3232+ ::=
3233+ match var
3234+ case var as VARIABLE(__) then
3235+ match ty
3236+ case ET_METATYPE(__)
3237+ case ET_BOXED(__) then 'mmc_GC_add_root(<%contextCref(var.name,contextFunction)%>);'
3238+ end match
3239+ end addRoots;
32303240
32313241template functionBodyRegularFunction(Function fn, Boolean inFunc)
32323242 "Generates the body for a Modelica/MetaModelica function."
@@ -3243,6 +3253,8 @@ case FUNCTION(__) then
32433253 let _ = (variableDeclarations |> var hasindex i1 from 1 =>
32443254 varInit(var, "", i1, &varDecls /*BUFD*/, &varInits /*BUFC*/)
32453255 )
3256+ let addRootsInputs = (functionArguments |> var => addRoots(var) ;separator="\n")
3257+ let addRootsOutputs = (outVars |> var => addRoots(var) ;separator="\n")
32463258 let funArgs = (functionArguments |> var => functionArg(var, &varInits) ;separator="\n")
32473259 let bodyPart = (body |> stmt => funStatement(stmt, &varDecls /*BUFD*/) ;separator="\n")
32483260 let &outVarInits = buffer ""
@@ -3256,6 +3268,11 @@ case FUNCTION(__) then
32563268 <<
32573269 <%retType%> _<%fname%>(<%functionArguments |> var => funArgDefinition(var) ;separator=", "%>)
32583270 {
3271+ /* disable GC for now
3272+ <% if acceptMetaModelicaGrammar() then ' <%addRootsInputs%>' %>
3273+ <% if acceptMetaModelicaGrammar() then if addRootsInputs then ' mmc_GC_push_roots_mark();' %>
3274+ */
3275+
32593276 <% funArgs%>
32603277 <% varDecls%>
32613278 <% outVarInits%>
@@ -3269,6 +3286,21 @@ case FUNCTION(__) then
32693286 <% outVarCopy%>
32703287 <% if not acceptMetaModelicaGrammar() then ' restore_memory_state(<%stateVar%>);' %>
32713288 <% outVarAssign%>
3289+
3290+ /* disable GC for now
3291+ <% if acceptMetaModelicaGrammar() then ' <%addRootsOutputs%>' %>
3292+ <% if acceptMetaModelicaGrammar() then if addRootsOutputs then ' mmc_GC_push_roots_mark();' %>
3293+ <%
3294+ if acceptMetaModelicaGrammar()
3295+ then if addRootsInputs
3296+ then ' mmc_GC_collect();'
3297+ else if addRootsOutputs
3298+ then ' mmc_GC_collect();'
3299+ %>
3300+ <% if acceptMetaModelicaGrammar() then if addRootsOutputs then ' mmc_GC_pop_roots_mark();' %>
3301+ <% if acceptMetaModelicaGrammar() then if addRootsInputs then ' mmc_GC_pop_roots_mark();' %>
3302+ */
3303+
32723304 return<% if outVars then ' <%retVar%>' %> ;
32733305 }
32743306
@@ -3992,7 +4024,7 @@ template algStatement(DAE.Statement stmt, Context context, Text &varDecls /*BUFP
39924024 case s as STMT_THROW(__) then 'MMC_THROW();<%\n%>'
39934025 case s as STMT_RETURN(__) then 'goto _return;<%\n%>'
39944026 case s as STMT_NORETCALL(__) then algStmtNoretcall(s, context, &varDecls /*BUFD*/)
3995- case s as STMT_REINIT(__) then algStmtReinit(s, context, &varDecls /*BUFD*/)
4027+ case s as STMT_REINIT(__) then algStmtReinit(s, context, &varDecls /*BUFD*/)
39964028 else "#error NOT_IMPLEMENTED_ALG_STATEMENT"
39974029 <<
39984030 /*#modelicaLine <%statementInfoString(stmt)%>*/
@@ -6390,7 +6422,7 @@ template literalExpConst(Exp lit, Integer index) "These should all be declared s
63906422::=
63916423 let name = '_OMC_LIT<%index%>'
63926424 let tmp = '_OMC_LIT_STRUCT<%index%>'
6393- let meta = 'static modelica_metatype const <%name%>'
6425+ let meta = 'static modelica_metatype /* const */ <%name%>'
63946426 match lit
63956427 case SCONST(__) then
63966428 let escstr = Util.escapeModelicaStringToCString(string)
@@ -6403,7 +6435,7 @@ template literalExpConst(Exp lit, Integer index) "These should all be declared s
64036435 <<
64046436 #define <%name%>_data "<%escstr%>"
64056437 static const size_t <%name%>_strlen = <%unescapedStringLength(escstr)%>;
6406- static const MMC_DEFSTRINGLIT(<%tmp%>,<%name%>_strlen,<%name%>_data);
6438+ static /* const */ MMC_DEFSTRINGLIT(<%tmp%>,<%name%>_strlen,<%name%>_data);
64076439 <%meta%> = MMC_REFSTRINGLIT(<%tmp%>);
64086440 >>
64096441 else
@@ -6422,28 +6454,28 @@ template literalExpConst(Exp lit, Integer index) "These should all be declared s
64226454 >>
64236455 case BOX(exp=exp as RCONST(__)) then
64246456 <<
6425- static const MMC_DEFREALLIT(<%tmp%>,<%exp.real%>);
6457+ static /* const */ MMC_DEFREALLIT(<%tmp%>,<%exp.real%>);
64266458 <%meta%> = MMC_REFREALLIT(<%tmp%>);
64276459 >>
64286460 case CONS(__) then
64296461 <<
6430- static const MMC_DEFSTRUCTLIT(<%tmp%>,2,1) { <% literalExpConstBoxedVal(car)%> ,<% literalExpConstBoxedVal(cdr)%> } };
6462+ static /* const */ MMC_DEFSTRUCTLIT(<%tmp%>,2,1) { <% literalExpConstBoxedVal(car)%> ,<% literalExpConstBoxedVal(cdr)%> } };
64316463 <%meta%> = MMC_REFSTRUCTLIT(<%tmp%>);
64326464 >>
64336465 case META_TUPLE(__) then
64346466 <<
6435- static const MMC_DEFSTRUCTLIT(<%tmp%>,<%listLength(listExp)%>,0) { <% listExp |> exp => literalExpConstBoxedVal(exp); separator= " ," %> } };
6467+ static /* const */ MMC_DEFSTRUCTLIT(<%tmp%>,<%listLength(listExp)%>,0) { <% listExp |> exp => literalExpConstBoxedVal(exp); separator= " ," %> } };
64366468 <%meta%> = MMC_REFSTRUCTLIT(<%tmp%>);
64376469 >>
64386470 case META_OPTION(exp=SOME(exp)) then
64396471 <<
6440- static const MMC_DEFSTRUCTLIT(<%tmp%>,1,1) { <% literalExpConstBoxedVal(exp)%> } };
6472+ static /* const */ MMC_DEFSTRUCTLIT(<%tmp%>,1,1) { <% literalExpConstBoxedVal(exp)%> } };
64416473 <%meta%> = MMC_REFSTRUCTLIT(<%tmp%>);
64426474 >>
64436475 case METARECORDCALL(__) then
64446476 let newIndex = getValueCtor(index)
64456477 <<
6446- static const MMC_DEFSTRUCTLIT(<%tmp%>,<%intAdd(1,listLength(args))%>,<%newIndex%>) { &<% underscorePath(path)%> __desc,<% args |> exp => literalExpConstBoxedVal(exp); separator= " ," %> } };
6478+ static /* const */ MMC_DEFSTRUCTLIT(<%tmp%>,<%intAdd(1,listLength(args))%>,<%newIndex%>) { &<% underscorePath(path)%> __desc,<% args |> exp => literalExpConstBoxedVal(exp); separator= " ," %> } };
64476479 <%meta%> = MMC_REFSTRUCTLIT(<%tmp%>);
64486480 >>
64496481 else '<%\n%>#error "literalExpConst failed: <%printExpStr(lit)%>"<%\n%>'
0 commit comments