Skip to content

Commit

Permalink
Add MetaModelica.Dangerous.listArrayLiteral
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#1928
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Oct 19, 2017
1 parent ec1d292 commit 09c37cd
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 17 deletions.
67 changes: 50 additions & 17 deletions Compiler/FrontEnd/Ceval.mo
Expand Up @@ -1166,23 +1166,24 @@ algorithm
true = intGe(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), 33);
then cevalBuiltinClock; */
// MetaModelica type conversions
case "intString" equation true = Config.acceptMetaModelicaGrammar(); then cevalIntString;
case "realString" equation true = Config.acceptMetaModelicaGrammar(); then cevalRealString;
case "stringCharInt" equation true = Config.acceptMetaModelicaGrammar(); then cevalStringCharInt;
case "intStringChar" equation true = Config.acceptMetaModelicaGrammar(); then cevalIntStringChar;
case "stringLength" equation true = Config.acceptMetaModelicaGrammar(); then cevalStringLength;
case "stringInt" equation true = Config.acceptMetaModelicaGrammar(); then cevalStringInt;
case "stringListStringChar" equation true = Config.acceptMetaModelicaGrammar(); then cevalStringListStringChar;
case "listStringCharString" equation true = Config.acceptMetaModelicaGrammar(); then cevalListStringCharString;
case "stringAppendList" equation true = Config.acceptMetaModelicaGrammar(); then cevalStringAppendList;
case "stringDelimitList" equation true = Config.acceptMetaModelicaGrammar(); then cevalStringDelimitList;
case "listLength" equation true = Config.acceptMetaModelicaGrammar(); then cevalListLength;
case "listAppend" equation true = Config.acceptMetaModelicaGrammar(); then cevalListAppend;
case "listReverse" equation true = Config.acceptMetaModelicaGrammar(); then cevalListReverse;
case "listHead" equation true = Config.acceptMetaModelicaGrammar(); then cevalListFirst;
case "listRest" equation true = Config.acceptMetaModelicaGrammar(); then cevalListRest;
case "listMember" equation true = Config.acceptMetaModelicaGrammar(); then cevalListMember;
case "anyString" equation true = Config.acceptMetaModelicaGrammar(); then cevalAnyString;
case "intString" guard Config.acceptMetaModelicaGrammar() then cevalIntString;
case "realString" guard Config.acceptMetaModelicaGrammar() then cevalRealString;
case "stringCharInt" guard Config.acceptMetaModelicaGrammar() then cevalStringCharInt;
case "intStringChar" guard Config.acceptMetaModelicaGrammar() then cevalIntStringChar;
case "stringLength" guard Config.acceptMetaModelicaGrammar() then cevalStringLength;
case "stringInt" guard Config.acceptMetaModelicaGrammar() then cevalStringInt;
case "stringListStringChar" guard Config.acceptMetaModelicaGrammar() then cevalStringListStringChar;
case "listStringCharString" guard Config.acceptMetaModelicaGrammar() then cevalListStringCharString;
case "stringAppendList" guard Config.acceptMetaModelicaGrammar() then cevalStringAppendList;
case "stringDelimitList" guard Config.acceptMetaModelicaGrammar() then cevalStringDelimitList;
case "listLength" guard Config.acceptMetaModelicaGrammar() then cevalListLength;
case "listAppend" guard Config.acceptMetaModelicaGrammar() then cevalListAppend;
case "listReverse" guard Config.acceptMetaModelicaGrammar() then cevalListReverse;
case "listHead" guard Config.acceptMetaModelicaGrammar() then cevalListFirst;
case "listRest" guard Config.acceptMetaModelicaGrammar() then cevalListRest;
case "listMember" guard Config.acceptMetaModelicaGrammar() then cevalListMember;
case "anyString" guard Config.acceptMetaModelicaGrammar() then cevalAnyString;
case "listArrayLiteral" guard Config.acceptMetaModelicaGrammar() then cevalListArrayLiteral;
case "numBits" then cevalNumBits;
case "integerMax" then cevalIntegerMax;
case "getLoadedLibraries" then cevalGetLoadedLibraries;
Expand Down Expand Up @@ -2602,6 +2603,38 @@ algorithm
end match;
end cevalListMember;

protected function cevalListArrayLiteral
input FCore.Cache inCache;
input FCore.Graph inEnv;
input list<DAE.Exp> inExpExpLst;
input Boolean inBoolean;
input Option<GlobalScript.SymbolTable> inST;
input Absyn.Msg inMsg;
input Integer numIter;
output FCore.Cache outCache;
output Values.Value outValue;
output Option<GlobalScript.SymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outValue,outInteractiveInteractiveSymbolTableOption):=
match (inCache,inEnv,inExpExpLst,inBoolean,inST,inMsg,numIter)
local
FCore.Graph env;
DAE.Exp exp;
Boolean impl;
Option<GlobalScript.SymbolTable> st;
Absyn.Msg msg;
FCore.Cache cache;
list<Values.Value> vals;
Values.Value val;
Boolean b;
case (cache,env,{exp},impl,st,msg,_)
equation
(cache,Values.LIST(vals),st) = ceval(cache,env,exp,impl,st,msg,numIter+1);
then
(cache,Values.META_ARRAY(vals),st);
end match;
end cevalListArrayLiteral;

protected function cevalAnyString
input FCore.Cache inCache;
input FCore.Graph inEnv;
Expand Down
7 changes: 7 additions & 0 deletions Compiler/FrontEnd/MetaModelicaBuiltin.mo
Expand Up @@ -958,6 +958,13 @@ NOTE: Make sure you do NOT create cycles as infinite lists are not handled well
external "builtin";
end listSetRest;

function listArrayLiteral<A>
"O(n)"
input list<A> lst;
output array<A> arr;
external "builtin";
end listArrayLiteral;

end Dangerous;

end MetaModelica;
Expand Down
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/ValuesUtil.mo
Expand Up @@ -920,6 +920,14 @@ algorithm
(explist,_) = Types.matchTypes(explist, typelist, vt, true);
then DAE.LIST(explist);

case (Values.META_ARRAY(vallist))
equation
explist = List.map(vallist, valueExp);
typelist = List.map(vallist, Types.typeOfValue);
vt = Types.boxIfUnboxedType(List.reduce(typelist,Types.superType));
(explist,_) = Types.matchTypes(explist, typelist, vt, true);
then Expression.makeBuiltinCall("listArrayLiteral", explist, DAE.T_METAARRAY(vt), false);

/* MetaRecord */
case (Values.RECORD(path,vallist,namelst,ix))
equation
Expand Down
1 change: 1 addition & 0 deletions Compiler/SimCode/SimCodeFunctionUtil.mo
Expand Up @@ -1324,6 +1324,7 @@ algorithm
case DAE.META_TUPLE(expl) equation List.map_0(expl, isLiteralExp); then ();
case DAE.METARECORDCALL(args=expl) equation List.map_0(expl, isLiteralExp); then ();
case DAE.SHARED_LITERAL() then ();
case DAE.CALL(path=Absyn.IDENT("listArrayLiteral"), expLst=expl) algorithm List.map_0(expl, isLiteralExp); then ();
else fail();
end match;
end isLiteralExp;
Expand Down
7 changes: 7 additions & 0 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -3417,6 +3417,13 @@ template literalExpConst(Exp lit, Integer litindex) "These should all be declare
%>static const MMC_DEFSTRUCTLIT(<%tmp%>,<%intAdd(1,listLength(args))%>,<%newIndex%>) {&<%underscorePath(path)%>__desc,<%args |> exp hasindex i0 => literalExpConstBoxedVal(exp,litindex+"_"+i0); separator=","%>}};
#define <%name%> MMC_REFSTRUCTLIT(<%tmp%>)
>>
case CALL(path=IDENT(name="listArrayLiteral"), expLst=args) then
/* We need to use #define's to be C-compliant. Yea, total crap :) */
<<
<%args |> exp hasindex i0 => literalExpConstBoxedValPreLit(exp,litindex+"_"+i0) ; empty
%>static const MMC_DEFSTRUCTLIT(<%tmp%>,<%listLength(args)%>,MMC_ARRAY_TAG) {<%args |> exp hasindex i0 => literalExpConstBoxedVal(exp,litindex+"_"+i0); separator=","%>}};
#define <%name%> MMC_REFSTRUCTLIT(<%tmp%>)
>>
else error(sourceInfo(), 'literalExpConst failed: <%ExpressionDumpTpl.dumpExp(lit,"\"")%>')
end literalExpConst;

Expand Down

0 comments on commit 09c37cd

Please sign in to comment.