Skip to content

Commit

Permalink
- Added ceval for listReverse
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7362 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 12, 2010
1 parent c1bf18d commit 9a8534f
Show file tree
Hide file tree
Showing 7 changed files with 1,006 additions and 1,096 deletions.
119 changes: 98 additions & 21 deletions Compiler/Builtin.mo
Expand Up @@ -55,7 +55,6 @@ protected import ClassInf;
protected import Parser;
protected import SCodeUtil;
protected import Util;
protected import Values;

protected constant String initialFunctionStr =
"
Expand Down Expand Up @@ -613,6 +612,97 @@ function stringHashSdbm
external \"builtin\";
end stringHashSdbm;

function listAppend
input list<TypeA> lst1;
input list<TypeA> lst2;
output list<TypeA> lst;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listAppend;
function listReverse
input list<TypeA> inLst;
output list<TypeA> outLst;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listReverse;

function listLength
input list<TypeA> lst;
output Integer length;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listLength;

function listMember
input TypeA element;
input list<TypeA> lst;
output Boolean isMember;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listMember;

function listGet
input list<TypeA> lst;
input Integer index;
output TypeA element;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listGet;

function listNth
input list<TypeA> lst;
input Integer index;
output TypeA element;
replaceable type TypeA subtypeof Any;
annotation(Inline = true);
algorithm
element := listGet(lst,index+1);
end listNth;

function listRest
input list<TypeA> lst;
output list<TypeA> rest;
replaceable type TypeA subtypeof Any;
annotation(Inline = true);
algorithm
(_::rest) := lst;
end listRest;

function listHead
input list<TypeA> lst;
output TypeA head;
replaceable type TypeA subtypeof Any;
annotation(Inline = true);
algorithm
(head::_) := lst;
end listHead;

function listDelete
input list<TypeA> inLst;
input Integer index;
output list<TypeA> outLst;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listDelete;

function listEmpty
input list<TypeA> lst;
output Boolean isEmpty;
replaceable type TypeA subtypeof Any;
external \"builtin\";
end listEmpty;
function cons
input TypeA element;
input list<TypeA> inLst;
output list<TypeA> outLst;
replaceable type TypeA subtypeof Any;
annotation(Inline = true);
algorithm
outLst := element::inLst;
end cons;

function arrayLength
input array<TypeA> arr;
output Integer length;
Expand Down Expand Up @@ -676,7 +766,6 @@ function arrayCopy
external \"builtin\";
end arrayCopy;


function arrayAdd \"An arrayAppend operation would be more useful; this might be slow if used improperly!\"
input array<TypeA> arr;
input TypeA a;
Expand Down Expand Up @@ -759,9 +848,14 @@ end referenceEq;

function clock
output Real t;
external \"builtin\" t=mmc_clock();
external \"builtin\";
end clock;

function optionNone
input Option<TypeA> opt;
output Boolean isNone;
external \"builtin\";
end optionNone;
"
;

Expand Down Expand Up @@ -3581,25 +3675,8 @@ algorithm
case (env)
equation
true = RTOpts.acceptMetaModelicaGrammar();

// List Operations
env = Env.extendFrameT(env, "listAppend", listAListA2listA);
env = Env.extendFrameT(env, "listReverse", listA2listA);
env = Env.extendFrameT(env, "listLength", list2int);
env = Env.extendFrameT(env, "listMember", AlistA2boolean);
env = Env.extendFrameT(env, "listGet", listAInt2A);
env = Env.extendFrameT(env, "listNth", listAInt2A);
env = Env.extendFrameT(env, "listRest", listA2listA);
env = Env.extendFrameT(env, "listDelete", listAint2listA);
env = Env.extendFrameT(env, "listEmpty", list2boolean);
env = Env.extendFrameT(env, "cons", AlistA2listA);

// Option Operations
env = Env.extendFrameT(env, "optionNone", option2boolean);

// getGlobalRoot can not be represented by a regular function...
env = Env.extendFrameT(env, "getGlobalRoot", int2boxed);

env = Env.extendFrameT(env, "getGlobalRoot", int2boxed);
then env;
case env then env;
end matchcontinue;
Expand Down
35 changes: 35 additions & 0 deletions Compiler/Ceval.mo
Expand Up @@ -1092,6 +1092,7 @@ algorithm
case "stringAppendList" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalStringAppendList;
case "listLength" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListLength;
case "listAppend" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListAppend;
case "listReverse" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListReverse;
// Box/Unbox
case "mmc_mk_bcon" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
case "mmc_mk_icon" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
Expand Down Expand Up @@ -2939,6 +2940,40 @@ algorithm
end matchcontinue;
end cevalListAppend;

protected function cevalListReverse
input Env.Cache inCache;
input Env.Env inEnv;
input list<DAE.Exp> inExpExpLst;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Msg inMsg;
output Env.Cache outCache;
output Values.Value outValue;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outValue,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inExpExpLst,inBoolean,inInteractiveInteractiveSymbolTableOption,inMsg)
local
list<Env.Frame> env;
DAE.Exp exp,exp1,exp2;
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st;
Msg msg;
Env.Cache cache;
String str;
Integer i;
Real r;
list<String> chList;
list<Values.Value> valList,valList1,valList2;
case (cache,env,{exp1},impl,st,msg)
equation
(cache,Values.LIST(valList1),st) = ceval(cache,env, exp1, impl, st,NONE(), msg);
valList = listReverse(valList1);
then
(cache,Values.LIST(valList),st);
end matchcontinue;
end cevalListReverse;

protected function extractValueStringChar
input Values.Value val;
output String str;
Expand Down
7 changes: 7 additions & 0 deletions Compiler/SimCode.mo
Expand Up @@ -1249,6 +1249,13 @@ algorithm
(fns, rt_2, decls, includes, libs) = elaborateFunctions2(rest, accfns, rt, decls, includes, libs);
then
(fns, rt_2, decls, includes, libs);
case (DAE.FUNCTION(functions = DAE.FUNCTION_EXT(externalDecl = DAE.EXTERNALDECL(returnType="builtin"))::_)::rest,accfns,rt,decls,includes,libs)
equation
// skip over builtin functions
(fns, rt_2, decls, includes, libs) = elaborateFunctions2(rest, accfns, rt, decls, includes, libs);
then
(fns, rt_2, decls, includes, libs);

case ((fel :: rest), accfns, rt, decls, includes, libs)
equation
(fn, rt_1, decls, includes, libs) = elaborateFunction(fel, rt, decls, includes, libs);
Expand Down

0 comments on commit 9a8534f

Please sign in to comment.