Skip to content

Commit

Permalink
Stack overflow (instantiation of HumMod can now be done in 512kB stac…
Browse files Browse the repository at this point in the history
…k on bootstrapped omc)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17052 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 3, 2013
1 parent d65ed85 commit 4997fd7
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 43 deletions.
44 changes: 16 additions & 28 deletions Compiler/FrontEnd/ConnectUtil.mo
Expand Up @@ -1999,47 +1999,35 @@ algorithm
case ({set}) then {set};
case (set::rest)
equation
(set, rest) = mergeWithRest(set, rest);
(set, rest) = mergeWithRest(set, rest, {});
sets = mergeEquSetsAsCrefs(rest);
then
set::sets;
end matchcontinue;
end mergeEquSetsAsCrefs;

function mergeWithRest
protected function mergeWithRest
input list<DAE.ComponentRef> inSet;
input list<list<DAE.ComponentRef>> inSets;
input list<list<DAE.ComponentRef>> inAcc;
output list<DAE.ComponentRef> outSet;
output list<list<DAE.ComponentRef>> outSets;
algorithm
(outSet, outSets) := matchcontinue(inSet, inSets)
(outSet, outSets) := match (inSet, inSets, inAcc)
local
list<DAE.ComponentRef> set, set1, set2;
list<list<DAE.ComponentRef>> rest;

case (_, {}) then (inSet, inSets);
// we can't merge it
case (set1, set2::rest)
equation
{} = List.intersectionOnTrue(set1, set2, ComponentReference.crefEqualNoStringCompare);
//print("NotMerge Set1:\n\t" +& stringDelimitList(List.map(set1, ComponentReference.printComponentRefStr), "\n\t") +& "\n");
//print("NotMerge Set2:\n\t" +& stringDelimitList(List.map(set2, ComponentReference.printComponentRefStr), "\n\t") +& "\n");
(set, rest) = mergeWithRest(set1, rest);
then
(set, set2::rest);

// we can merge it
case (set1, set2::rest)
equation
_::_ = List.intersectionOnTrue(set1, set2, ComponentReference.crefEqualNoStringCompare);
set = List.unionOnTrue(set1, set2, ComponentReference.crefEqualNoStringCompare);
// print("Merge Set1:\n\t" +& stringDelimitList(List.map(set1, ComponentReference.printComponentRefStr), "\n\t") +& "\n");
// print("Merge Set2:\n\t" +& stringDelimitList(List.map(set2, ComponentReference.printComponentRefStr), "\n\t") +& "\n");
// print("Resulting Set:\n\t" +& stringDelimitList(List.map(set, ComponentReference.printComponentRefStr), "\n\t") +& "\n");
(set, rest) = mergeWithRest(set, rest);
then
(set, rest);
end matchcontinue;
list<list<DAE.ComponentRef>> rest, acc;
Boolean b;
case (_, {}, _) then (inSet, listReverse(inAcc));
case (set1, set2::rest, acc)
equation
// Could be faster if we had a function for intersectionExist in a set
b = List.isEmpty(List.intersectionOnTrue(set1, set2, ComponentReference.crefEqualNoStringCompare));
set = Debug.bcallret3(not b, List.unionOnTrue, set1, set2, ComponentReference.crefEqualNoStringCompare, set1);
acc = List.consOnTrue(b, set2, acc);
(set, rest) = mergeWithRest(set, rest, acc);
then (set, rest);
end match;
end mergeWithRest;

protected function getOnlyExpandableConnectedCrefs
Expand Down
109 changes: 95 additions & 14 deletions Compiler/Util/List.mo
Expand Up @@ -7077,20 +7077,36 @@ public function exist
output Boolean out;
end FindFunc;
algorithm
outList := match (inList,inFindFunc)
outList := exist_work(false,inList,inFindFunc);
end exist;

protected function exist_work
"Returns true if the and element is found on the list using a function. Example
filter({1,2}, isEven) => true
filter({1,3,5,7}, isEven) => false"
input Boolean found;
input list<ElementType> inList;
input FindFunc inFindFunc;
output Boolean outList;

partial function FindFunc
input ElementType inElement;
output Boolean out;
end FindFunc;
algorithm
outList := match (found,inList,inFindFunc)
local
list<ElementType> t;
ElementType h;
Boolean ret,b;
case({},_)
then false;
case(h::t,_)
case(true,_,_) then true;
case(_,{},_) then false;
case(_,h::t,_)
equation
b = inFindFunc(h);
b = Debug.bcallret2(not b, exist, t, inFindFunc, true);
then b;
then exist_work(b, t, inFindFunc);
end match;
end exist;
end exist_work;

public function exist1
"Returns true if the and element is found on the list using a function and an extra argument."
Expand All @@ -7105,19 +7121,84 @@ public function exist1
output Boolean out;
end FindFunc;
algorithm
outList := match (inList,inFindFunc,inExtraArg)
outList := exist1_work(false,inList,inFindFunc,inExtraArg);
end exist1;

protected function exist1_work
"Returns true if the and element is found on the list using a function and an extra argument."
input Boolean found;
input list<ElementType1> inList;
input FindFunc inFindFunc;
input ElementType2 inExtraArg;
output Boolean outList;

partial function FindFunc
input ElementType1 inElement;
input ElementType2 inExtraArg;
output Boolean out;
end FindFunc;
algorithm
outList := match (found,inList,inFindFunc,inExtraArg)
local
list<ElementType1> t;
ElementType1 h;
Boolean ret,b;
case ({},_,_) then false;
case (h::t,_,_)
case(true,_,_,_) then true;
case(_,{},_,_) then false;
case(_,h::t,_,_)
equation
b = inFindFunc(h,inExtraArg);
b = Debug.bcallret3(not b, exist1, t, inFindFunc, inExtraArg, true);
then b;
b = inFindFunc(h, inExtraArg);
then exist1_work(b, t, inFindFunc, inExtraArg);
end match;
end exist1;
end exist1_work;

public function exist2
"Returns true if the and element is found on the list using a function and an extra argument."
input list<ElementType1> inList;
input FindFunc inFindFunc;
input ElementType2 inExtraArg1;
input ElementType3 inExtraArg2;
output Boolean outList;

partial function FindFunc
input ElementType1 inElement;
input ElementType2 inExtraArg1;
input ElementType3 inExtraArg2;
output Boolean out;
end FindFunc;
algorithm
outList := exist2_work(false,inList,inFindFunc,inExtraArg1,inExtraArg2);
end exist2;

protected function exist2_work
"Returns true if the and element is found on the list using a function and an extra argument."
input Boolean found;
input list<ElementType1> inList;
input FindFunc inFindFunc;
input ElementType2 inExtraArg1;
input ElementType3 inExtraArg2;
output Boolean outList;

partial function FindFunc
input ElementType1 inElement;
input ElementType2 inExtraArg1;
input ElementType3 inExtraArg2;
output Boolean out;
end FindFunc;
algorithm
outList := match (found,inList,inFindFunc,inExtraArg1,inExtraArg2)
local
list<ElementType1> t;
ElementType1 h;
Boolean ret,b;
case(true,_,_,_,_) then true;
case(_,{},_,_,_) then false;
case(_,h::t,_,_,_)
equation
b = inFindFunc(h, inExtraArg1, inExtraArg2);
then exist2_work(b, t, inFindFunc, inExtraArg1, inExtraArg2);
end match;
end exist2_work;

public function extractOnTrue
"Takes a list of values and a filter function over the values and returns a
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -103,7 +103,7 @@ bootstrap-from-compiled:
$(MAKE) -C testsuite/openmodelica/bootstrapping -f LinkMain.makefile bootstrap-from-compiled
$(MAKE) omlibrary

bootstrap-dependencies: omc-diff interactive docs fmi fmil opencl_rt
bootstrap-dependencies: omc-diff interactive docs fmi fmil opencl_rt lis
$(MAKE) -C Compiler/runtime install
$(MAKE) -C Compiler builtin install_scripts
$(MAKE) -C Parser install
Expand Down

0 comments on commit 4997fd7

Please sign in to comment.