Skip to content

Commit

Permalink
* Implemented support, in frontend, for mod/div/rem
Browse files Browse the repository at this point in the history
* Readded Adrians code for handeling zero flow equations of arrays(Connect.mo)
* Change/fixed the "current variable" in error message functionality 
* Added support for having "der(x) := x" in algorithm section. 
* function/operator skew() in Static.mo
* Updated rtest to current Mathcore rtest version.

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@3832 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Björn Zachrisson committed Jan 29, 2009
1 parent 81d39ee commit 38be98d
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 80 deletions.
72 changes: 72 additions & 0 deletions Compiler/Absyn.mo
Expand Up @@ -1474,6 +1474,51 @@ then s1;
end matchcontinue;
end componentRefStr;

public function typeSpecEqual "
Author BZ 2009-01
Check wheter two type specs are equal or not.
"
input TypeSpec a,b;
output Boolean ob;
algorithm ob := matchcontinue(a,b)
local
Path p1,p2;
Option<ArrayDim> oad1,oad2;
list<TypeSpec> lst1,lst2;
case(TPATH(p1,oad1), TPATH(p2,oad2))
equation
true = ModUtil.pathEqual(p1,p2);
true = optArrayDimEqual(oad1,oad2);
then true;
case(TCOMPLEX(p1,lst1,oad1),TCOMPLEX(p2,lst2,oad2))
equation
true = ModUtil.pathEqual(p1,p2);
true = Util.isListEqualWithCompareFunc(lst1,lst2,typeSpecEqual);
true = optArrayDimEqual(oad1,oad2);
then
true;
case(_,_) then false;
end matchcontinue;
end typeSpecEqual;

public function optArrayDimEqual "
Author BZ
helperfunction for typeSpecEqual
"
input Option<ArrayDim> oad1,oad2;
output Boolean b;
algorithm b:= matchcontinue(oad1,oad2)
local
list<Subscript> ad1,ad2;
case(SOME(ad1),SOME(ad2))
equation
true = Util.isListEqualWithCompareFunc(ad1,ad2,subscriptEqual);
then true;
case(NONE,NONE) then true;
case(_,_) then false;
end matchcontinue;
end optArrayDimEqual;

public function typeSpecPathString "function: pathString
This function simply converts a Path to a string."
input TypeSpec tp;
Expand Down Expand Up @@ -1875,6 +1920,19 @@ algorithm
end matchcontinue;
end joinPaths;

public function optPathAppend "
Author BZ, 2009-01
Appends a path to optional 'base'-path.
"
input Option<Path> basePath;
input Path lastPath;
output Path mergedPath;
algorithm mergedPath := matchcontinue(basePath, lastPath)
case(NONE,lastPath) then lastPath;
case(SOME(mergedPath), lastPath) then pathAppendList({mergedPath,lastPath});
end matchcontinue;
end optPathAppend;

public function pathAppendList "function: pathAppendList
author Lucian
This function joins a path list"
Expand Down Expand Up @@ -2334,6 +2392,20 @@ algorithm
end matchcontinue;
end isPackageRestriction;

public function subscriptEqual "
Author BZ, 2009-01
Check if two subscripts are equal.
"
input Subscript ss1,ss2;
output Boolean b;
algorithm b:= matchcontinue(ss1,ss2)
local Exp e1,e2;
case(NOSUB,NOSUB) then true;
case(SUBSCRIPT(e1),SUBSCRIPT(e2)) then expEqual(e1,e2);
case(_,_) then false;
end matchcontinue;
end subscriptEqual;

public function expEqual "Returns true if two expressions are equal"
input Exp exp1;
input Exp exp2;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/Builtin.mo
Expand Up @@ -3205,6 +3205,8 @@ algorithm
env = Env.extendFrameT(env, "skew", array1dimreal2array3dimreal);
env = Env.extendFrameT(env, "sqrt", int2real);
env = Env.extendFrameT(env, "sqrt", real2real);
env = Env.extendFrameT(env, "mod", intInt2int);
env = Env.extendFrameT(env, "mod", realReal2real);
/*
env = Env.extendFrameT(env, "semiLinear", realRealReal2real);
env = Env.extendFrameT(env, "delay", realReal2real);
Expand Down
97 changes: 94 additions & 3 deletions Compiler/Connect.mo
Expand Up @@ -1329,10 +1329,11 @@ algorithm
(outCache,outDAEElementLst) :=
matchcontinue (inCache,inExpComponentRefLst,inEnv,prefix,deletedComponents)
local
list<DAE.Element> res;
list<DAE.Element> res,res1;
Exp.ComponentRef cr;
Env.Env env;
Types.Type tp;
Exp.Type arrType;
list<Exp.ComponentRef> xs;
list<int> dimSizes;
list<Option<Integer>> dimSizesOpt;
Expand All @@ -1349,9 +1350,12 @@ algorithm
dimExps = Util.listMap(dimSizes,Exp.makeIntegerExp);
(cache,res) = generateZeroflowEquations(cache,xs,env,prefix,deletedComponents);
cr2 = Prefix.prefixCref(prefix,cr);
arrType = Exp.T_ARRAY(Exp.REAL(),dimSizesOpt);
dimExps = {Exp.ICONST(0),Exp.ICONST(0),Exp.ICONST(0)};
res1 = generateZeroflowArrayEquations(cr, dimSizes, Exp.RCONST(0.0));
res = listAppend(res1,res);
then
(cache,DAE.EQUATION(Exp.CREF(cr2,Exp.REAL()),Exp.CALL(Absyn.IDENT("fill"),Exp.RCONST(0.0)::dimExps,false,true,Exp.T_ARRAY(Exp.REAL(),dimSizesOpt))) :: res);

(cache,res);
case (cache,(cr :: xs),env,prefix,deletedComponents) // For scalars.
equation
(cache,_,tp,_,_,_) = Lookup.lookupVar(cache,env,cr);
Expand All @@ -1363,6 +1367,93 @@ algorithm
end matchcontinue;
end generateZeroflowEquations;

protected function generateZeroflowArrayEquations
"function generateZeroflowArrayEquations
@author adrpo
Given:
- a component reference (ex. a.b)
- a list of dimensions (ex. {3, 4})
- an expression (ex. expr)
this function will generate a list of equations of the form:
{ a.b[1,1] = expr, a.b[1,2] = expr, a.b[1,3] = expr, a.b[1.4] = expr,
a.b[2,1] = expr, a.b[2,2] = expr, a.b[2,3] = expr, a.b[2.4] = expr,
a.b[3,1] = expr, a.b[3,2] = expr, a.b[3,3] = expr, a.b[3.4] = expr }"
input Exp.ComponentRef cr;
input list<Integer> dimensions;
input Exp.Exp initExp;
output list<DAE.Element> equations;
algorithm
equations := matchcontinue(cr, dimensions, initExp)
local
list<DAE.Element> out;
list<list<Integer>> indexIntegerLists;
list<list<Exp.Subscript>> indexSubscriptLists;
case(cr, dimensions, initExp)
equation
// take the list of dimensions: ex. {2, 5, 3}
// and generate a list of ranges: ex. {{1, 2}, {1, 2, 3, 4, 5}, {1, 2, 3}}
indexIntegerLists = Util.listMap(dimensions, Util.listIntRange);
// from a list like: {{1, 2}, {1, 2, 3, 4, 5}
// generate a list like: { { {Exp.INDEX(Exp.ICONST(1)}, {Exp.INDEX(Exp.ICONST(2)} }, ... }
indexSubscriptLists = Util.listListMap(indexIntegerLists, integer2Subscript);
// now generate a product of all lists in { {lst1}, {lst2}, {lst3} }
// which will generate indexes like [1, 1, 1], [1, 1, 2], [1, 2, 3] ... [2, 5, 3]
indexSubscriptLists = generateAllIndexes(indexSubscriptLists, {});
out = Util.listMap1(indexSubscriptLists, genZeroEquation, (cr, initExp));
then
out;
end matchcontinue;
end generateZeroflowArrayEquations;

protected function genZeroEquation
"@author adrpo
given an integer transform it into an list<Exp.Subscript>"
input list<Exp.Subscript> indexSubscriptList;
input tuple<Exp.ComponentRef, Exp.Exp> crAndInitExp;
output DAE.Element eq;
algorithm
eq := matchcontinue (indexSubscriptList, crAndInitExp)
local
Exp.ComponentRef cr;
Exp.Exp initExp;
case (indexSubscriptList, (cr, initExp))
equation
cr = Exp.subscriptCref(cr, indexSubscriptList);
then
DAE.EQUATION(Exp.CREF(cr,Exp.REAL()), initExp);
end matchcontinue;
end genZeroEquation;

function generateAllIndexes
input list<list<Exp.Subscript>> inIndexLists;
input list<list<Exp.Subscript>> accumulator;
output list<list<Exp.Subscript>> outIndexLists;
algorithm
outIndexLists := matchcontinue (inIndexLists, accumulator)
local
list<Exp.Subscript> hd;
list<list<Exp.Subscript>> tail, res1, res2;
case ({}, accumulator) then accumulator;
case (hd::tail, accumulator)
equation
//print ("generateAllIndexes hd:"); printMe(hd);
res1 = Util.listProduct({hd}, accumulator);
res2 = generateAllIndexes(tail, res1);
//print ("generateAllIndexes res2:"); Util.listMap0(res2, printMe);
then
res2;
end matchcontinue;
end generateAllIndexes;

protected function integer2Subscript
"@author adrpo
given an integer transform it into an Exp.Subscript"
input Integer index;
output Exp.Subscript subscript;
algorithm
subscript := Exp.INDEX(Exp.ICONST(index));
end integer2Subscript;

protected function getAllFlowVariables "function: getAllFlowVariables
Return a list of all flow variables from the connection sets.
Expand Down
9 changes: 8 additions & 1 deletion Compiler/DAELow.mo
Expand Up @@ -4658,7 +4658,14 @@ algorithm
(v,kv,extVars,e,re,ie,ae,al,whenclauses_1,extObjCls) = lower2(DAE.DAE(xs), states, whenclauses);
then
(v,kv,extVars,e,re,ie,ae,al,whenclauses_1,extObjCls);

case (DAE.DAE(elementLst = (ddl :: xs)),_,_)
local DAE.Element ddl; String s3;
equation
print("-DAELow.lower2 failed\n");
s3 = DAE.dumpElementsStr({ddl});
print(s3 +& "\n");
then
fail();
case (_,_,_)
equation
print("-DAELow.lower2 failed\n");
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Error.mo
Expand Up @@ -460,7 +460,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(REDUNDANT_GUESS,TRANSLATION(),WARNING(),
"Start value is assigned for variable: %s, but not used since %s"),
(MISSING_INNER_PREFIX,TRANSLATION(),ERROR(),
"Component must have prefix 'inner' since corresponding outer declaration found for component %s."),
"No corresponding 'INNER' declaration found for component %s declared as '%s'."),
(IMPLICIT_ITERATOR_NOT_FOUND_IN_LOOP_BODY,TRANSLATION(),ERROR(),
"Identificator %s of implicit for iterator must be present as array subscript in the loop body.")
};
Expand Down

0 comments on commit 38be98d

Please sign in to comment.