Skip to content

Commit

Permalink
Some changes for merging with MathCore
Browse files Browse the repository at this point in the history
Tolerance set to 1e-6 again, should not be changed! (destroys the test suite)
Reading boolean return values from function return values changed. 
Algorithm assigns for record parameters allowed.
Default compiler set to g++
Removed some errors from function generation (should be able to fail from ceval)



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4547 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Björn Zachrisson committed Nov 20, 2009
1 parent bbe6461 commit 16e196b
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 70 deletions.
16 changes: 12 additions & 4 deletions Compiler/Algorithm.mo
Expand Up @@ -52,7 +52,7 @@ public import DAE;
public import SCode;

public
type Ident = String;
type Ident = String;

public type Algorithm = DAE.Algorithm;
public type Statement = DAE.Statement;
Expand Down Expand Up @@ -100,7 +100,7 @@ algorithm (reinits,rest) := matchcontinue(inAlgs)
(reinits,rest) = splitReinits(inAlgs);
then
(reinits,rest);
end matchcontinue;
end matchcontinue;
end splitReinits;

public function makeAssignment
Expand All @@ -126,19 +126,27 @@ algorithm
DAE.Exp lhs,rhs,rhs_1,e1,e2,e3;
DAE.Properties lprop,rprop,lhprop,rhprop;
DAE.ExpType t,crt;
DAE.ComponentRef c;
DAE.ComponentRef c,cr;
tuple<DAE.TType, Option<Absyn.Path>> lt,rt;

/* It is not allowed to assign to a constant */
case (lhs,lprop,rhs,rprop,_,initial_)
equation
DAE.C_CONST() = Types.propAnyConst(lprop);
lhs_str = Exp.printExpStr(lhs);
lhs_str = Exp.printExpStr(lhs);
rhs_str = Exp.printExpStr(rhs);
Error.addMessage(Error.ASSIGN_CONSTANT_ERROR, {lhs_str,rhs_str});
then
fail();

/* assign to parameter in algorithm okay if record */
case ((lhs as DAE.CREF(componentRef=cr)),lhprop,rhs,rhprop,_,SCode.NON_INITIAL())
equation
DAE.C_PARAM() = Types.propAnyConst(lhprop);
true = Exp.isRecord(cr);
outStatement = makeAssignment2(lhs,lhprop,rhs,rhprop);
then outStatement;

/* assign to parameter in algorithm produce error */
case (lhs,lprop,rhs,rprop,_,SCode.NON_INITIAL())
equation
Expand Down
8 changes: 5 additions & 3 deletions Compiler/Ceval.mo
Expand Up @@ -60,6 +60,7 @@ public import Env;
public import Interactive;
public import Values;


public
uniontype Msg
record MSG "Give error message" end MSG;
Expand Down Expand Up @@ -90,8 +91,7 @@ protected import InstanceHierarchy;
protected import Prefix;
protected import Connect;

public function ceval
"function: ceval
public function ceval "
This function is used when the value of a constant expression is
needed. It takes an environment and an expression and calculates
its value.
Expand Down Expand Up @@ -209,6 +209,7 @@ algorithm
local
DAE.ComponentRef c;
equation
print(" metamodelica non implemented\n");
Debug.fprintln("failtrace", "Ceval.ceval not working for function references");
then
fail();
Expand All @@ -217,6 +218,7 @@ algorithm
local
DAE.ComponentRef c;
equation
print(" metamodelica non implemented\n");
Debug.fprintln("failtrace", "Ceval.ceval not working for function references");
then
fail();
Expand Down Expand Up @@ -1208,7 +1210,7 @@ algorithm
(cache,newval,NONE());

case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl,builtin = builtin)),vallst,impl,st,dim,msg)
equation
equation
error_Str = Absyn.pathString(funcpath);
//TODO: readd this when testsuite is okay.
//Error.addMessage(Error.FAILED_TO_EVALUATE_FUNCTION, {error_Str});
Expand Down
19 changes: 7 additions & 12 deletions Compiler/DAEUtil.mo
Expand Up @@ -1374,26 +1374,21 @@ public function getStartAttrEmpty "
Return the start attribute.
"
input Option<DAE.VariableAttributes> inVariableAttributesOption;
input DAE.Type tp;
input DAE.Exp optExp;
output DAE.Exp start;
algorithm
start:=
matchcontinue (inVariableAttributesOption,tp)
start := matchcontinue (inVariableAttributesOption,optExp)
local
DAE.Exp r;
case (SOME(DAE.VAR_ATTR_REAL(initial_ = SOME(r))),_) then r;
case (SOME(DAE.VAR_ATTR_INT(initial_ = SOME(r))),_) then r;
case (SOME(DAE.VAR_ATTR_BOOL(initial_ = SOME(r))),_) then r;
case (SOME(DAE.VAR_ATTR_STRING(initial_ = SOME(r))),_) then r;
case (_,(DAE.T_REAL(_),_)) then DAE.RCONST(0.0);
case (_,(DAE.T_INTEGER(_),_)) then DAE.ICONST(0);
case (_,(DAE.T_BOOL(_),_)) then DAE.BCONST(false);
case (_,(DAE.T_STRING(_),_)) then DAE.SCONST("");
case(_,_) then DAE.RCONST(0.0);
case(_,optExp) then optExp;
end matchcontinue;
end getStartAttrEmpty;

public function getMinMax "
public function getMinMax "
Author: BZ, returns a list of optional exp, {opt<Min> opt<Max}
"
input Option<DAE.VariableAttributes> inVariableAttributesOption;
Expand Down Expand Up @@ -4499,9 +4494,9 @@ algorithm
{el};
case (path,((el as DAE.RECORD_CONSTRUCTOR(path = elpath)) :: rest))
equation
true = ModUtil.pathEqual(path, elpath);
then
{el};
true = ModUtil.pathEqual(path, elpath);
then
{el};
case (path,(el :: rest))
equation
res = getNamedFunction(path, rest);
Expand Down
36 changes: 23 additions & 13 deletions Compiler/Exp.mo
Expand Up @@ -61,12 +61,12 @@ public import DAE;
public import Graphviz;

public type ComponentRef = DAE.ComponentRef;
public type Exp = DAE.Exp;
public type Exp = DAE.Exp;
public type Ident = String;
public type Operator = DAE.Operator;
public type Operator = DAE.Operator;
public type Type = DAE.ExpType;
public type Subscript = DAE.Subscript;
public type Var = DAE.ExpVar;
public type Var = DAE.ExpVar;

protected import RTOpts;
protected import Util;
Expand All @@ -79,16 +79,15 @@ protected import Debug;
protected import Static;
protected import Env;
protected import System;
protected import DAELow;

protected constant Exp rconstone=DAE.RCONST(1.0);


public uniontype IntOp
public uniontype IntOp
record MULOP end MULOP;
record DIVOP end DIVOP;
record ADDOP end ADDOP;
record SUBOP end SUBOP;
record SUBOP end SUBOP;
record POWOP end POWOP;
end IntOp;

Expand Down Expand Up @@ -730,6 +729,17 @@ algorithm
nb := boolNot(b);
end isNotConst;

public function isRecord ""
input ComponentRef cr;
output Boolean b;
algorithm
b := matchcontinue(cr)
case(DAE.CREF_IDENT(identType = DAE.ET_COMPLEX(complexClassType=ClassInf.RECORD(_)))) then true;
case(DAE.CREF_QUAL(identType = DAE.ET_COMPLEX(complexClassType=ClassInf.RECORD(_)))) then true;
case(_) then false;
end matchcontinue;
end isRecord;

public function isRelation
"function: isRelation
Returns true if expression is a function expression."
Expand Down Expand Up @@ -1084,8 +1094,8 @@ algorithm
end matchcontinue;
end intSubscripts;

public function subscriptsInt
"function: subscriptsInt
public function subscriptsInt "
function: subscriptsInt
author: PA
This function creates a list of ints from
a subscript list, see also intSubscripts."
Expand Down Expand Up @@ -3726,7 +3736,7 @@ algorithm
end unliftArray;

public function typeof
"function typeof
"function typeof
Retrieves the Type of the Expression"
input Exp inExp;
output Type outType;
Expand Down Expand Up @@ -6514,7 +6524,7 @@ algorithm

case (e)
equation
//debug_print("unknown expression: ", e);
//debug_print("unknown expression: ", e);
then
"#UNKNOWN EXPRESSION# ----eee ";
end matchcontinue;
Expand Down Expand Up @@ -7153,7 +7163,7 @@ algorithm
name = printComponentRefStr(cr);
false = Util.stringContainsChar(name,"$");
id = Util.stringAppendList({"$",id});
id = Util.stringReplaceChar(id,".",DAELow.pointStr);
id = Util.stringReplaceChar(id,".","$p");
then
(DAE.CREF(DAE.CREF_IDENT(id,t2,ssl),ety),1);
case (e,s,_) then (e,0);
Expand Down Expand Up @@ -10097,8 +10107,8 @@ algorithm
outExp := DAE.BINARY(e1,DAE.SUB(tp),e2);
end expSub;

public function expDiv
"function expDiv
public function expDiv "
function expDiv
author: PA
Divides two scalar expressions."
input Exp e1;
Expand Down
7 changes: 4 additions & 3 deletions Compiler/Lookup.mo
Expand Up @@ -1992,9 +1992,10 @@ algorithm
(_,mod_1) = Mod.elabMod(Env.emptyCache(), env, Prefix.NOPRE(), mod, false);
mod_1 = Mod.merge(mods,mod_1,env,Prefix.NOPRE());
// adrpo: this was wrong, you won't find any id modification there!!!
// compMod = Mod.lookupModificationP(mod_1,Absyn.IDENT(id));
// umod = Mod.unelabMod(compMod);
umod = Mod.unelabMod(mod_1);
// bjozac: This was right, you will find id modification unless modifers does not belong to component!
compMod = Mod.lookupModificationP(mod_1,Absyn.IDENT(id));
umod = Mod.unelabMod(compMod);
//umod = Mod.unelabMod(mod_1);
res = buildRecordConstructorElts(rest, mods, env);
// - Prefixes (constant, parameter, final, discrete, input, output, ...) of the remaining record components are removed.
var = SCode.VAR();
Expand Down
9 changes: 4 additions & 5 deletions Compiler/Mod.mo
Expand Up @@ -1811,14 +1811,11 @@ algorithm
end matchcontinue;
end eqModEqual;

public function printModStr "- Printing
!ignorecode
function: print_mod
public function printModStr "
This function prints a modification. It uses a few other function
to do its stuff.
The functions are excluded from the report for brevity.

"
input DAE.Mod inMod;
output String outString;
Expand Down Expand Up @@ -1854,6 +1851,7 @@ algorithm
str = Util.stringAppendList({finalPrefixstr,s1_1,s2});
then
str;
case(_) equation print(" failure in printModStr \n"); then fail();
end matchcontinue;
end printModStr;

Expand Down Expand Up @@ -2087,6 +2085,7 @@ algorithm
res = stringAppend(" =(untyped) ", str);
then
res;
case(_) equation print(" ---printEqmodStr FAILED--- "); then fail();
end matchcontinue;
end printEqmodStr;
end Mod;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/ModUtil.mo
Expand Up @@ -534,15 +534,15 @@ algorithm
end matchcontinue;
end pathString;

protected function pathString2
public function pathString2
"function: pathString2
Helper function to path_string."
input Absyn.Path inPath;
input String inString;
output String outString;
algorithm
outString:=
matchcontinue (inPath,inString)
matchcontinue (inPath,inString)
local
String s,ns,s1,ss,str;
Absyn.Path n;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/PartFn.mo
Expand Up @@ -971,7 +971,7 @@ end elabExpOption;

protected function elabExp
"function: elabExp
looks for a function call, checks the arguments for Exp.PARTEVALFUNCTION
looks for a function call, checks the arguments for DAE.PARTEVALFUNCTION
creates new functions and replaces the call as necessary"
input tuple<DAE.Exp, list<DAE.Element>> inTuple;
output tuple<DAE.Exp, list<DAE.Element>> outTuple;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Prefix.mo
Expand Up @@ -445,13 +445,13 @@ algorithm
local Prefix p;
then
(cache,DAE.ARRAY(t,a,{}));
case (cache,env,DAE.ARRAY(ty = t,scalar = a,array = es),p as PREFIX(PRE(_,{i},_),_))
local Prefix p; Integer i; DAE.Exp e;
/*case (cache,env,Exp.ARRAY(ty = t,scalar = a,array = es),p as PREFIX(PRE(_,{i},_),_))
local Prefix p; Integer i; Exp.Exp e;
equation
e = listNth(es, i-1);
Debug.fprint("prefix", "{v1,v2,v3}[" +& intString(i) +& "] => " +& Exp.printExp2Str(e) +& "\n");
then
(cache,e);
(cache,e); */
case (cache,env,DAE.ARRAY(ty = t,scalar = a,array = es),p)
local Prefix p;
equation
Expand Down
10 changes: 5 additions & 5 deletions Compiler/Static.mo
Expand Up @@ -6552,7 +6552,7 @@ algorithm
(cache,numberOfIntervals) = getOptionalNamedArg(cache,env, SOME(st), impl, "numberOfIntervals",
(DAE.T_INTEGER({}),NONE), args, DAE.ICONST(500));
(cache,tolerance) = getOptionalNamedArg(cache,env, SOME(st), impl, "tolerance", (DAE.T_REAL({}),NONE),
args, DAE.RCONST(1e-4));
args, DAE.RCONST(1e-6));
(cache,method) = getOptionalNamedArg(cache,env, SOME(st), impl, "method", (DAE.T_STRING({}),NONE),
args, DAE.SCONST("dassl"));
(cache,options) = getOptionalNamedArg(cache,env, SOME(st), impl, "options", (DAE.T_STRING({}),NONE),
Expand All @@ -6577,16 +6577,16 @@ algorithm
(cache,startTime) = getOptionalNamedArg(cache,env, SOME(st), impl, "startTime", (DAE.T_REAL({}),NONE),
args, DAE.RCONST(0.0));
(cache,stopTime) = getOptionalNamedArg(cache,env, SOME(st), impl, "stopTime", (DAE.T_REAL({}),NONE),
args, DAE.RCONST(1.0));
args, DAE.RCONST(1.0));
(cache,numberOfIntervals) = getOptionalNamedArg(cache,env, SOME(st), impl, "numberOfIntervals",
(DAE.T_INTEGER({}),NONE), args, DAE.ICONST(500));
(cache,tolerance) = getOptionalNamedArg(cache,env, SOME(st), impl, "tolerance", (DAE.T_REAL({}),NONE),
args, DAE.RCONST(1e-4));
args, DAE.RCONST(1e-6));
(cache,method) = getOptionalNamedArg(cache,env, SOME(st), impl, "method", (DAE.T_STRING({}),NONE),
args, DAE.SCONST("dassl"));
(cache,options) = getOptionalNamedArg(cache,env, SOME(st), impl, "options", (DAE.T_STRING({}),NONE),
args, DAE.SCONST(""));
cname_str = Absyn.pathString(className);
cname_str = Absyn.pathString(className);
(cache,filenameprefix) = getOptionalNamedArg(cache,env, SOME(st), impl, "fileNamePrefix",
(DAE.T_STRING({}),NONE), args, DAE.SCONST(cname_str));
(cache,storeInTemp) = getOptionalNamedArg(cache,env, SOME(st), impl, "storeInTemp",
Expand All @@ -6612,7 +6612,7 @@ algorithm
(cache,numberOfIntervals) = getOptionalNamedArg(cache,env, SOME(st), impl, "numberOfIntervals",
(DAE.T_INTEGER({}),NONE), args, DAE.ICONST(500));
(cache,tolerance) = getOptionalNamedArg(cache,env, SOME(st), impl, "tolerance", (DAE.T_REAL({}),NONE),
args, DAE.RCONST(1e-4));
args, DAE.RCONST(1e-6));
(cache,method) = getOptionalNamedArg(cache,env, SOME(st), impl, "method", (DAE.T_STRING({}),NONE),
args, DAE.SCONST("dassl"));
classname = componentRefToPath(cr_1) "this extracts the fileNamePrefix which is used when generating code and init-file" ;
Expand Down

0 comments on commit 16e196b

Please sign in to comment.