Skip to content

Commit

Permalink
- More functions on tail-recursive form
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9492 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jul 16, 2011
1 parent 1ae2f26 commit c505f91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
24 changes: 17 additions & 7 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -1444,7 +1444,20 @@ protected function updateAliasVars
input BackendDAE.AliasVariables inAliases;
output BackendDAE.AliasVariables outAliases;
algorithm
(outAliases) := matchcontinue(inTableList1,inExp1,inExp2,inAliases)
(outAliases) := Util.listFold_3(inTableList1,updateAliasVarsFold,inAliases,inExp1,inExp2);
end updateAliasVars;

protected function updateAliasVarsFold
" Helper function to changeAliasVariables.
Collect all variables and update the alias exp binding.
"
input BackendDAE.AliasVariables inAliases;
input tuple<HashTable4.Key,HashTable4.Value> item;
input DAE.Exp inExp1;
input DAE.Exp inExp2;
output BackendDAE.AliasVariables outAliases;
algorithm
(outAliases) := matchcontinue(inAliases,item,inExp1,inExp2)
local
list<tuple<HashTable4.Key,HashTable4.Value>> rest;
DAE.Exp exp,exp2;
Expand All @@ -1455,8 +1468,7 @@ algorithm
DAE.ExpType ty;
Boolean b;

case ({},_,_,inAliases) then inAliases;
case (((exp,cref))::rest,inExp1,inExp2,inAliases as BackendDAE.ALIASVARS(aliasVars=aliasvars))
case (inAliases as BackendDAE.ALIASVARS(aliasVars=aliasvars),(exp,cref),inExp1,inExp2)
equation
Debug.fcall("debugAlias",BackendDump.debugStrExpStr,("*** search for: ",inExp1,"\n"));
ty = Expression.typeof(inExp2);
Expand All @@ -1471,15 +1483,13 @@ algorithm
v = BackendVariable.mergeVariableOperations(v,Util.if_(Expression.expEqual(exp,exp2),{},{DAE.SUBSTITUTION({exp2},exp)}));
aliasVariables = addAliasVariables({v},inAliases);
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("RES *** ComponentRef : ",cref," = Exp : ",exp2,"\n"));
aliasVariables = updateAliasVars(rest,inExp1,inExp2,aliasVariables);
then aliasVariables;
case (((exp,cref))::rest,inExp1,inExp2,aliasVariables)
case (aliasVariables,(exp,cref),_,_)
equation
Debug.fcall("debugAlias",BackendDump.debugStrCrefStrExpStr,("*** let ",cref," with binding Exp : ",exp,"\n"));
aliasVariables = updateAliasVars(rest,inExp1,inExp2,aliasVariables);
then aliasVariables;
end matchcontinue;
end updateAliasVars;
end updateAliasVarsFold;

protected function compareExpAlias
"function helper function to getAllValues.
Expand Down
39 changes: 10 additions & 29 deletions Compiler/Util/BaseHashTable.mo
Expand Up @@ -495,14 +495,15 @@ algorithm
case ((n,size,arr))
equation
lastpos = n - 1;
lst = valueArrayList2(arr, 0, lastpos, {});
lst = valueArrayList2(arr, false, 0, lastpos, {});
then
lst;
end matchcontinue;
end valueArrayList;

protected function valueArrayList2 "Helper function to valueArrayList"
input array<Option<tuple<Key,Value>>> inVarOptionArray1;
input Boolean posEq;
input Integer inInteger2;
input Integer inInteger3;
input list<tuple<Key,Value>> acc;
Expand All @@ -511,45 +512,25 @@ protected function valueArrayList2 "Helper function to valueArrayList"
replaceable type Key subtypeof Any;
replaceable type Value subtypeof Any;
algorithm
outVarLst := matchcontinue (inVarOptionArray1,inInteger2,inInteger3, acc)
outVarLst := match (inVarOptionArray1,posEq,inInteger2,inInteger3, acc)
local
tuple<Key,Value> v;
array<Option<tuple<Key,Value>>> arr;
Integer pos,lastpos,pos_1;
list<tuple<Key,Value>> res;

case (arr,pos,lastpos,acc)
case (arr,true,pos,lastpos,acc)
equation
(pos == lastpos) = true;
SOME(v) = arr[pos + 1];
acc = listReverse(v::acc);
then
acc;

case (arr,pos,lastpos,acc)
equation
(pos == lastpos) = true;
NONE() = arr[pos + 1];
acc = listReverse(acc);
then
acc;
acc = Util.listConsOption(arr[pos + 1],acc);
then listReverse(acc);

case (arr,pos,lastpos,acc)
case (arr,false,pos,lastpos,acc)
equation
pos_1 = pos + 1;
SOME(v) = arr[pos + 1];
res = valueArrayList2(arr, pos_1, lastpos, v::acc);
then
res;
acc = Util.listConsOption(arr[pos + 1],acc);
then valueArrayList2(arr, pos_1==lastpos, pos_1, lastpos, acc);

case (arr,pos,lastpos,acc)
equation
pos_1 = pos + 1;
NONE() = arr[pos + 1];
res = valueArrayList2(arr, pos_1, lastpos, acc);
then
res;
end matchcontinue;
end match;
end valueArrayList2;

public function hashTableCurrentSize
Expand Down

0 comments on commit c505f91

Please sign in to comment.