Skip to content

Commit

Permalink
Fix bootstrapping/tail recursion
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15230 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 18, 2013
1 parent 4e60107 commit eb1f9b8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ public function findLiterals
algorithm
(ofns, (_, _, literals)) := DAEUtil.traverseDAEFunctions(
fns, findLiteralsHelper,
(0, HashTableExpToIndex.emptyHashTableSized(BaseHashTable.bigBucketSize), {}));
(0, HashTableExpToIndex.emptyHashTableSized(BaseHashTable.bigBucketSize), {}), {});
literals := listReverse(literals);
end findLiterals;

Expand All @@ -1180,7 +1180,7 @@ protected function simulationFindLiterals
algorithm
(ofns, literals) := DAEUtil.traverseDAEFunctions(
fns, findLiteralsHelper,
(0, HashTableExpToIndex.emptyHashTableSized(BaseHashTable.bigBucketSize), {}));
(0, HashTableExpToIndex.emptyHashTableSized(BaseHashTable.bigBucketSize), {}), {});
// Broke things :(
// ((i, ht, literals)) := BackendDAEUtil.traverseBackendDAEExpsNoCopyWithUpdate(dae, findLiteralsHelper, (i, ht, literals));
end simulationFindLiterals;
Expand Down
13 changes: 7 additions & 6 deletions Compiler/FrontEnd/DAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3904,23 +3904,24 @@ expression, use an extra helper function."
input list<DAE.Function> ifuncLst;
input FuncExpType func;
input Type_a iextraArg;
input list<DAE.Function> acc;
output list<DAE.Function> outFuncLst;
output Type_a oextraArg;
partial function FuncExpType input tuple<DAE.Exp,Type_a> arg; output tuple<DAE.Exp,Type_a> oarg; end FuncExpType;
replaceable type Type_a subtypeof Any;
algorithm
(outFuncLst,oextraArg) := match(ifuncLst,func,iextraArg)
(outFuncLst,oextraArg) := match(ifuncLst,func,iextraArg,acc)
local
DAE.Function daeFunc;
list<DAE.Function> funcLst;
Type_a extraArg;

case({},_,extraArg) then ({},extraArg);
case(daeFunc::funcLst,_,extraArg)
case({},_,extraArg,_) then (listReverse(acc),extraArg);
case(daeFunc::funcLst,_,extraArg,_)
equation
(daeFunc,extraArg) = traverseDAEFunc(daeFunc,func,extraArg);
(funcLst,extraArg) = traverseDAEFunctions(funcLst,func,extraArg);
then (daeFunc::funcLst,extraArg);
(funcLst,extraArg) = traverseDAEFunctions(funcLst,func,extraArg,daeFunc::acc);
then (funcLst,extraArg);
end match;
end traverseDAEFunctions;

Expand Down Expand Up @@ -5942,7 +5943,7 @@ algorithm
list<DAE.Element> els,els1,els2;
case _
equation
(_,(_,els1)) = traverseDAEFunctions(elements, Expression.traverseSubexpressionsHelper, (collectLocalDecls,{}));
(_,(_,els1)) = traverseDAEFunctions(elements, Expression.traverseSubexpressionsHelper, (collectLocalDecls,{}), {});
els2 = getFunctionsElements(elements);
els = listAppend(els1, els2);
outPaths = getUniontypePathsElements(els);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4594,7 +4594,7 @@ algorithm
cache = instantiateDaeFunctions(cache, env, paths);
funcs = Env.getFunctionTree(cache);
d = List.map1(paths, DAEUtil.getNamedFunction, funcs);
(_,(_,dependencies)) = DAEUtil.traverseDAEFunctions(d,Expression.traverseSubexpressionsHelper,(matchQualifiedCalls,{}));
(_,(_,dependencies)) = DAEUtil.traverseDAEFunctions(d,Expression.traverseSubexpressionsHelper,(matchQualifiedCalls,{}),{});
print(name +& " has dependencies: " +& stringDelimitList(dependencies,",") +& "\n");
acc = (name,dependencies)::acc;
dependencies = List.map1(dependencies,stringAppend,".h\"");
Expand Down
37 changes: 22 additions & 15 deletions Compiler/Util/BaseHashTable.mo
Original file line number Diff line number Diff line change
Expand Up @@ -366,28 +366,35 @@ protected function get2
input FuncEq keyEqual;
output Integer index;
algorithm
index := matchcontinue (key,keyIndices,keyEqual)
index := match (key,keyIndices,keyEqual)
local
Key key2;
HashNode xs;
// search for the key, found the good one
case (_, (key2,index) :: _, _)
Boolean eq;
// search for the key, found the good one? stop and use the index
case (_, (key2,index) :: xs, _)
equation
true = keyEqual(key, key2);
then
index;
eq = keyEqual(key, key2);
then get3(eq, index, key, xs, keyEqual);

// search more
case (_, _ :: xs, _)
equation
index = get2(key, xs, keyEqual);
then
index;

end matchcontinue;
end match;
end get2;

protected function get3
"Helper function to get"
input Boolean b;
input Integer indexIfTrue;
input Key key;
input HashNode keyIndices;
input FuncEq keyEqual;
output Integer index;
algorithm
index := match (b,indexIfTrue,key,keyIndices,keyEqual)
case (true,_,_,_,_) then indexIfTrue;
else get2(key, keyIndices, keyEqual);
end match;
end get3;

public function dumpHashTable
input HashTable t;
protected
Expand Down

0 comments on commit eb1f9b8

Please sign in to comment.