Skip to content

Commit

Permalink
partly fixed bug #105 (1 and 2).
Browse files Browse the repository at this point in the history
Fixed bug with looking up external object.
Fixed bug with sign bultin function.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2435 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jun 27, 2006
1 parent 5c8b937 commit a4539e4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 32 deletions.
38 changes: 36 additions & 2 deletions Compiler/Ceval.mo
Expand Up @@ -247,7 +247,8 @@ algorithm
case "sqrt" then cevalBuiltinSqrt;
case "div" then cevalBuiltinDiv;
case "sin" then cevalBuiltinSin;
case "cos" then cevalBuiltinCos;
case "cos" then cevalBuiltinCos;
case "log" then cevalBuiltinLog;
case "asin" then cevalBuiltinAsin;
case "acos" then cevalBuiltinAcos;
case "atan" then cevalBuiltinAtan;
Expand Down Expand Up @@ -994,7 +995,6 @@ algorithm
funcpath2:=Absyn.stripLast(funcpath);
(_,tp,_) := Lookup.lookupType(cache,env,funcpath2,true);
Types.externalObjectConstructorType(tp);
print("isExternalObjectConstructor: ");print(Absyn.pathString(funcpath));print("\n");
end cevalIsExternalObjectConstructor;

protected function cevalKnownExternalFuncs "function: cevalKnownExternalFuncs
Expand Down Expand Up @@ -3794,6 +3794,40 @@ algorithm
end matchcontinue;
end cevalBuiltinCos;

protected function cevalBuiltinLog "function cevalBuiltinLog
author: LP
Evaluates the builtin Log function.
"
input Env.Cache inCache;
input Env.Env inEnv;
input list<Exp.Exp> inExpExpLst;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Msg inMsg;
output Env.Cache outCache;
output Values.Value outValue;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outValue,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inExpExpLst,inBoolean,inInteractiveInteractiveSymbolTableOption,inMsg)
local
Real rv,rv_1;
list<Env.Frame> env;
Exp.Exp exp;
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st;
Msg msg;
Env.Cache cache;
case (cache,env,{exp},impl,st,msg)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st, NONE, msg);
rv_1 = System.log(rv);
then
(cache,Values.REAL(rv_1),st);
end matchcontinue;
end cevalBuiltinLog;

protected function cevalBuiltinTan "function cevalBuiltinTan
author: LP
Expand Down
23 changes: 22 additions & 1 deletion Compiler/Derive.mo
Expand Up @@ -134,7 +134,7 @@ algorithm
Exp.Type tp;
Exp.ComponentRef cr;
String cr_str,cr_str_1,e_str,str,s1;
Exp.Exp e,e_1,e1_1,e2_1,e1,e2,e3_1,e3;
Exp.Exp e,e_1,e1_1,e2_1,e1,e2,e3_1,e3,d_e1,exp,e0;
DAELow.Variables timevars,tv;
Exp.Operator op,rel;
list<Exp.Exp> expl_1,expl;
Expand Down Expand Up @@ -172,7 +172,28 @@ algorithm
then
Exp.UNARY(Exp.UMINUS(Exp.REAL()),Exp.BINARY(e_1,Exp.MUL(Exp.REAL()),
Exp.CALL(Absyn.IDENT("sin"),{e},false,true)));

// *** Addition by JA 20060621
case (Exp.CALL(path = fname,expLst = {e},tuple_ = false,builtin = true),timevars)
equation
isLog(fname);
e_1 = differentiateExpTime(e, timevars) "der(log(x)) = der(x)/x" ;
then
Exp.BINARY(e_1,Exp.DIV(Exp.REAL()),e);

case (e0 as Exp.BINARY(exp1 = e1,operator = Exp.POW(tp),exp2 = (e2 as Exp.RCONST(_))),timevars) /* ax^(a-1) */
equation
d_e1 = differentiateExpTime(e1, timevars) "e^x => xder(e)e^x-1" ;
//false = Exp.expContains(e2, Exp.CREF(tv,tp));
//const_one = differentiateExp(Exp.CREF(tv,tp), tv);
exp = Exp.BINARY(
Exp.BINARY(d_e1,Exp.MUL(tp),e2),Exp.MUL(tp),
Exp.BINARY(e1,Exp.POW(tp),Exp.BINARY(e2,Exp.SUB(tp),Exp.RCONST(1.0))));
print(Exp.printExpStr(e0) +& " => " +& Exp.printExpStr(exp)+&"\n");
then
exp;

// *** End of addition by JA 20060621
case ((e as Exp.CREF(componentRef = cr,ty = tp)),timevars) /* list_member(cr,timevars) => false */ then Exp.RCONST(0.0);
case (Exp.BINARY(exp1 = e1,operator = Exp.ADD(ty = tp),exp2 = e2),tv)
equation
Expand Down
38 changes: 20 additions & 18 deletions Compiler/Lookup.mo
Expand Up @@ -85,12 +85,6 @@ protected import OpenModelica.Compiler.Connect;

protected import OpenModelica.Compiler.Error;

protected import OpenModelica.Compiler.ErrorExt;

protected import OpenModelica.Compiler.Values;

protected import OpenModelica.Compiler.Util;

/* - Lookup functions
These functions look up class and variable names in the environment.
Expand Down Expand Up @@ -137,17 +131,15 @@ algorithm
(cache,t,env_1);

/* Classes that are external objects. Implicityly instantiate to get type */
case (cache,env,path ,msg) local String s;
case (cache,env,path ,msg) local String ident,s;
equation
(cache,c ,env_1) = lookupClass(cache,env, path, false);
true = Inst.classIsExternalObject(c);
(cache,_,env_1,_,_,_) = Inst.instClass(cache,env_1, Types.NOMOD(), Prefix.NOPRE(), Connect.emptySet, c,
(cache,_,_::env_1,_,_,_) = Inst.instClass(cache,env_1, Types.NOMOD(), Prefix.NOPRE(), Connect.emptySet, c,
{}, false, Inst.TOP_CALL());
//s = Env.printEnvStr(env_1);
//print("instantiated external object2, env:");
//print(s);
//print("\n");
(cache,t,env_2) = lookupTypeInEnv(cache,env_1, path);
ident = Absyn.pathLastIdent(path); /* Once class has instantiated we only need to look up the last
part of the name as a type */
(cache,t,env_2) = lookupTypeInEnv(cache,env_1, Absyn.IDENT(ident));
then
(cache,t,env_2);

Expand All @@ -170,6 +162,7 @@ algorithm
case (cache,env,path,true)
equation
classname = Absyn.pathString(path);
classname = stringAppend(classname," (its type) ");
scope = Env.printEnvPathStr(env);
Error.addMessage(Error.LOOKUP_ERROR, {classname,scope});
then
Expand Down Expand Up @@ -963,12 +956,13 @@ algorithm
(cache,attr,ty,bind) = lookupVar(cache,bcframes, cref);
then
(cache,attr,ty,bind);

/* Search among qualified imports, e.g. import A.B; or import D=A.B; */
case (cache,(env as (Env.FRAME(class_1 = sid,list_4 = items) :: _)),(cr as Exp.CREF_IDENT(ident = id,subscriptLst = sb)))
equation
(cache,attr,ty,bind) = lookupQualifiedImportedVarInFrame(cache,items, env, id);
then
(cache,attr,ty,bind);
/* Search among unqualified imports, e.g. import A.B.* */
case (cache,(env as (Env.FRAME(class_1 = sid,list_4 = items) :: _)),(cr as Exp.CREF_IDENT(ident = id,subscriptLst = sb)))
local Boolean unique;
equation
Expand Down Expand Up @@ -1751,28 +1745,36 @@ algorithm
String id,name;
list<Env.Item> items;
Env.Cache cache;
/* Check this scope for class */
case (cache,Env.FRAME(class_1 = sid,list_2 = ht),totenv,id,_)
equation
Env.CLASS(c,env) = Env.treeGet(ht, id, Env.myhash) "print \"looking for class \" & print id & print \" in frame\\n\" & & print \"found \" & print id & print \"\\n\"" ;
Env.CLASS(c,env) = Env.treeGet(ht, id, Env.myhash) ;
then
(cache,c,totenv);

/* Searching for class, found component*/
case (cache,Env.FRAME(class_1 = sid,list_2 = ht),_,id,true)
equation
Env.VAR(_,_,_,_) = Env.treeGet(ht, id, Env.myhash);
Error.addMessage(Error.LOOKUP_TYPE_FOUND_COMP, {id});
then
fail();
case (cache,Env.FRAME(list_5 = (bcframes as (_ :: _))),totenv,name,_) /* Search base classes */

/* Search base classes */
case (cache,Env.FRAME(list_5 = (bcframes as (_ :: _))),totenv,name,_)
equation
(cache,c,env) = lookupClass(cache,bcframes, Absyn.IDENT(name), false) "print \"Searching baseclasses for \" & print name & print \"\\n\" &
Env.print_env_str bcframes => s & print \"env:\" & print s & print \"\\n\" &" ;
(cache,c,env) = lookupClass(cache,bcframes, Absyn.IDENT(name), false);
then
(cache,c,env);

/* Search among the qualified imports, e.g. import A.B; or import D=A.B; */
case (cache,Env.FRAME(class_1 = sid,list_4 = items),totenv,name,_)
equation
(cache,c,env_1) = lookupQualifiedImportedClassInFrame(cache,items, totenv, name);
then
(cache,c,env_1);

/* Search among the unqualified imports, e.g. import A.B.*; */
case (cache,Env.FRAME(class_1 = sid,list_4 = items),totenv,name,_)
local Boolean unique;
equation
Expand Down
22 changes: 11 additions & 11 deletions Compiler/Static.mo
Expand Up @@ -3405,24 +3405,24 @@ algorithm
local
Exp.Exp exp_1,exp_2;
list<Env.Frame> env;
list<Absyn.Exp> expl;
Absyn.Exp exp;
Boolean impl;
Types.Const c;
Types.Type tp1;
Env.Cache cache;
case (cache,env,{exp},impl) /* impl Constness: C_VAR */
case (cache,env,{exp},impl) /* Argument to sign must be an Integer or Real expression */
equation
(cache,exp_1,Types.PROP((Types.T_BOOL({}),_),Types.C_VAR()),_) = elabExp(cache,env, exp, impl, NONE);
then
(cache,Exp.CALL(Absyn.IDENT("sign"),{exp_1},false,true),Types.PROP((Types.T_BOOL({}),NONE),Types.C_VAR()));
case (cache,env,{exp},impl) /* constness: C_PARAM & C_CONST */
equation
(cache,exp_1,Types.PROP((Types.T_BOOL({}),_),c),_) = elabExp(cache,env, exp, impl, NONE);
exp_2 = valueExp(Values.BOOL(false));
(cache,exp_1,Types.PROP(tp1,c),_) = elabExp(cache,env, exp, impl, NONE);
Types.integerOrReal(tp1);
then
(cache,exp_2,Types.PROP((Types.T_BOOL({}),NONE),c));
case (cache,env,_,_)
(cache,Exp.CALL(Absyn.IDENT("sign"),{exp_1},false,true),Types.PROP(tp1,c));
case (cache,env,expl,_)
local String s;
equation
Error.addMessage(Error.WRONG_TYPE_OR_NO_OF_ARGS, {"sign"});
s = Util.stringDelimitList(Util.listMap(expl, Dump.printExpStr),", ");
s = Util.stringAppendList({"sign(",s,")"});
Error.addMessage(Error.WRONG_TYPE_OR_NO_OF_ARGS, {s});
then
fail();
end matchcontinue;
Expand Down

0 comments on commit a4539e4

Please sign in to comment.