Skip to content

Commit

Permalink
Added compiling of MetaModelica lists. Added the list type to the typ…
Browse files Browse the repository at this point in the history
…e system files: Types.mo, Values.mo. List constructs in Exp.mo. Handling of lists in Inst.mo, Codegen.mo, Prefix.mo and Static.mo. Minor changes in Absyn.mo and DAE.mo. Also added a new file, MetaUtil, that contains several functions for handling MetaModelica extensions. All the testcases succeded (remember to make clean).

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2833 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Kristian Stavåker committed Jun 17, 2007
1 parent 306a4f1 commit 36fb88f
Show file tree
Hide file tree
Showing 12 changed files with 1,048 additions and 46 deletions.
6 changes: 5 additions & 1 deletion Compiler/Absyn.mo
Expand Up @@ -742,7 +742,11 @@ uniontype Exp "The Exp uniontype is the container of a Modelica expression.
record CONS "list cons or :: operator"
Exp head " head of the list ";
Exp rest " rest of the list ";
end CONS;
end CONS;

record LIST "Part of MetaModelica extension"
list<Exp> exps;
end LIST;

record MATCHEXP "matchcontinue expression"
MatchType matchTy " match or matchcontinue ";
Expand Down
61 changes: 54 additions & 7 deletions Compiler/Codegen.mo
Expand Up @@ -60,6 +60,7 @@ public import Print;
public import Exp;
public import Absyn;
public import Convert;
public import MetaUtil;

public
type Ident = String;
Expand Down Expand Up @@ -1343,7 +1344,8 @@ algorithm
case DAE.REAL() then Exp.REAL();
case DAE.STRING() then Exp.STRING();
case DAE.BOOL() then Exp.BOOL();
case DAE.ENUM() then Exp.ENUM();
case DAE.ENUM() then Exp.ENUM();
case DAE.LIST() then Exp.T_LIST(Exp.OTHER()); // MetaModelica list
case _ then Exp.OTHER();
end matchcontinue;
end daeExpType;
Expand Down Expand Up @@ -1401,7 +1403,14 @@ algorithm
matchcontinue (inType,inBoolean)
local
Lib tstr,str;
Exp.Type t;
Exp.Type t;

//MetaModelica list
case (Exp.T_LIST(_),_)
equation
str = "void*";
then str;

case (t,false) /* array */
equation
tstr = expShortTypeStr(t);
Expand Down Expand Up @@ -1448,7 +1457,10 @@ algorithm
case ((Types.T_INTEGER(varLstInt = _),_)) then "modelica_integer";
case ((Types.T_REAL(varLstReal = _),_)) then "modelica_real";
case ((Types.T_STRING(varLstString = _),_)) then "modelica_string";
case ((Types.T_BOOL(varLstBool = _),_)) then "modelica_boolean";
case ((Types.T_BOOL(varLstBool = _),_)) then "modelica_boolean";

case ((Types.T_LIST(_),_)) then "void*"; // MetaModelica list

case ty
equation
Debug.fprint("failtrace", "#-- generate_type failed\n");
Expand All @@ -1473,7 +1485,10 @@ algorithm
case ((Types.T_INTEGER(varLstInt = _),_)) then "int";
case ((Types.T_REAL(varLstReal = _),_)) then "double";
case ((Types.T_STRING(varLstString = _),_)) then "const char*";
case ((Types.T_BOOL(varLstBool = _),_)) then "int";
case ((Types.T_BOOL(varLstBool = _),_)) then "int";

case ((Types.T_LIST(_),_)) then "void*"; // MetaModelica list

case ((Types.T_ARRAY(arrayDim = dim,arrayType = ty),_))
equation
str = generateTypeExternal(ty);
Expand Down Expand Up @@ -1605,7 +1620,10 @@ algorithm
t_1 = Types.arrayElementType(t);
t_str = arrayTypeString(t_1);
then
t_str;
t_str;

case ((Types.T_LIST(_),_)) then "void*"; // MetaModelica list

case ty
equation
Debug.fprint("failtrace", "#--generate_simple_type failed\n");
Expand Down Expand Up @@ -3749,7 +3767,7 @@ algorithm
Exp.Exp res;
list<Algorithm.Statement> b3;
equation
// Convert back to DAE uniontypes from Exp uniontypes
// Convert back to DAE uniontypes from Exp uniontypes, part of a work-around
ld2 = Convert.fromExpElemsToDAEElems(ld,{});
b2 = Convert.fromExpElemToDAEElem(b);
(cfn,tnr_1) = generateVars(ld2, isVarQ, tnr, funContext);
Expand All @@ -3763,7 +3781,36 @@ algorithm
Debug.fprint("failtrace",
"# Codegen.generate_expression: asub not implemented\n");
then
fail();
fail();

//---------------------------------------------
// MetaModelica list. MetaModelica extension
//---------------------------------------------
case (Exp.CONS(e1,e2),tnr,context)
equation
(cfn1,var1,tnr_1) = generateExpression(e1, tnr, context);
(cfn2,var2,tnr2) = generateExpression(e2, tnr_1, context);
(decl,tvar,tnr1_1) = generateTempDecl("void*", tnr2);

stmt = Util.stringAppendList({tvar," = mk_cons(",var1,", ",var2,");"});
cfn2 = cAddVariables(cfn2,{decl});
cfn2 = cAddStatements(cfn2, {stmt});
cfn1_2 = cMergeFns({cfn1,cfn2});
then
(cfn1_2,tvar,tnr1_1);

case (Exp.LIST(elist),tnr,context)
equation
(cfn1,vars1,tnr1) = generateExpressions(elist, tnr, context);
(decl,tvar,tnr1_1) = generateTempDecl("void*", tnr1);
s = MetaUtil.listToConsCell(vars1);
stmt = Util.stringAppendList({tvar," = ",s,";"});
cfn1_1 = cAddVariables(cfn1,{decl});
cfn1_2 = cAddStatements(cfn1_1, {stmt});
then
(cfn1_2,tvar,tnr1_1);
//---------------------------------------------

case (e,_,_)
equation
Debug.fprintln("failtrace", "# generate_expression failed");
Expand Down
4 changes: 3 additions & 1 deletion Compiler/DAE.mo
Expand Up @@ -94,7 +94,9 @@ uniontype Type
record STRING end STRING;

record ENUM end ENUM;


record LIST end LIST; // MetaModelica list. KS

record ENUMERATION
list<String> stringLst;
end ENUMERATION;
Expand Down
125 changes: 115 additions & 10 deletions Compiler/Exp.mo
Expand Up @@ -93,7 +93,12 @@ uniontype Type "- Basic types
record T_ARRAY
Type ty;
list<Option<Integer>> arrayDimensions "arrayDimensions" ;
end T_ARRAY;
end T_ARRAY;

// MetaModelica list type. MetaModelica extension. KS
record T_LIST
Type ty;
end T_LIST;

end Type;

Expand Down Expand Up @@ -225,7 +230,17 @@ uniontype Exp "Expressions
list<DAEElement> localDecls;
DAEElement body;
Exp result;
end VALUEBLOCK;
end VALUEBLOCK;

/* Part of MetaModelica extension. KS */
record LIST "MetaModelica list"
list<Exp> valList;
end LIST;

record CONS "MetaModelica list cons"
Exp car;
Exp cdr;
end CONS;

end Exp;

Expand Down Expand Up @@ -790,8 +805,6 @@ end Else;
//-------------------------------------------




public
uniontype Operator "Operators which are overloaded in the abstract syntax are here
made type-specific. The integer addition operator (`ADD(INT)\')
Expand Down Expand Up @@ -5735,7 +5748,29 @@ algorithm
str = printExpStr(e);
Print.printBuf(str);
then
();
();

// MetaModelica list
case (LIST(es),_)
local list<Exp> es;
equation
Print.printBuf("<list>{");
printList(es, printExp, ",");
Print.printBuf("}");
then
();

// MetaModelica list cons
case (CONS(e1,e2),_)
equation
Print.printBuf("cons(");
printExp(e1);
Print.printBuf(",");
printExp(e2);
Print.printBuf(")");
then
();

case (_,_)
equation
Print.printBuf("#UNKNOWN EXPRESSION# ----eee ");
Expand Down Expand Up @@ -6553,7 +6588,27 @@ algorithm
iterstr = printExpStr(iterexp);
str = Util.stringAppendList({"<reduction>",fs,"(",expstr," for ",id," in ",iterstr,")"});
then
str;
str;

// MetaModelica list
case (LIST(es))
local list<Exp> es;
equation
s = printListStr(es, printExpStr, ",");
s_1 = stringAppend("list(", s);
s_2 = stringAppend(s_1, ")");
then
s_2;

// MetaModelica list cons
case (CONS(e1,e2))
equation
s1 = printExpStr(e1);
s2 = printExpStr(e2);
s_2 = Util.stringAppendList({"cons(",s1,",",s2,")"});
then
s_2;

case (_) then "#UNKNOWN EXPRESSION# ----eee ";
end matchcontinue;
end printExp2Str;
Expand Down Expand Up @@ -8273,7 +8328,25 @@ algorithm
equation
res = getCrefFromExp(e);
then
res;
res;

/* MetaModelica list */
case (CONS(e1,e2))
local list<list<ComponentRef>> res;
equation
expl = {e1,e2};
res = Util.listMap(expl, getCrefFromExp);
res2 = Util.listFlatten(res);
then res2;

case (LIST(expl))
local list<list<ComponentRef>> res;
equation
res = Util.listMap(expl, getCrefFromExp);
res2 = Util.listFlatten(res);
then res2;
/* --------------------- */

case (_) then {};
end matchcontinue;
end getCrefFromExp;
Expand Down Expand Up @@ -8389,7 +8462,21 @@ algorithm
elist = listAppend(a, {e1});
res = getFunctionCallsList(elist);
then
res;
res;

/* MetaModelica list */
case (CONS(e1,e2))
equation
elist = {e1,e2};
res = getFunctionCallsList(elist);
then res;

case (LIST(elist))
equation
res = getFunctionCallsList(elist);
then res;
/* --------------------- */

case (_) then {};
end matchcontinue;
end getFunctionCalls;
Expand Down Expand Up @@ -8635,12 +8722,30 @@ algorithm
((e2_1,ext_arg_2)) = traverseExp(e2, rel, ext_arg_1);
((REDUCTION(path_1,_,id_1,_),ext_arg_3)) = rel((e,ext_arg_2));
then
((REDUCTION(path_1,e1_1,id_1,e2_1),ext_arg_3));
((REDUCTION(path_1,e1_1,id_1,e2_1),ext_arg_3));

/* MetaModelica list */
case ((e as CONS(e1,e2)),rel,ext_arg)
equation
((e1_1,ext_arg_1)) = traverseExp(e1, rel, ext_arg);
((e2_1,ext_arg_2)) = traverseExp(e2, rel, ext_arg_1);
((CONS(_,_),ext_arg_3)) = rel((e,ext_arg_2));
then
((CONS(e1_1,e2_1),ext_arg_3));

case ((e as LIST(expl)),rel,ext_arg)
equation
(expl_1,ext_arg_1) = Util.listFoldMap(expl, rel, ext_arg);
((e_1,ext_arg_2)) = rel((e,ext_arg_1));
then
((LIST(expl_1),ext_arg_2));
/* --------------------- */

case (e,rel,ext_arg)
equation
((e_1,ext_arg_1)) = rel((e,ext_arg));
then
((e_1,ext_arg_1));
((e_1,ext_arg_1));
end matchcontinue;
end traverseExp;

Expand Down

0 comments on commit 36fb88f

Please sign in to comment.