Skip to content

Commit

Permalink
Changed interactive commands such as simulate, buildModel, etc, evalu…
Browse files Browse the repository at this point in the history
…ated in Ceval to use automatic quoting (changed to Code AST construct).

Fixed bugs in cache implementation.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2434 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jun 27, 2006
1 parent 0c7ba61 commit 5c8b937
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 269 deletions.
96 changes: 49 additions & 47 deletions Compiler/Ceval.mo

Large diffs are not rendered by default.

33 changes: 19 additions & 14 deletions Compiler/Env.mo
Expand Up @@ -273,7 +273,7 @@ protected function nameScope "function: nameScope
know what the current class being instantiated is.
Secondly, it is needed when expanding type names in the context of
flattening of the inheritance hierarchy. The reason for this is that types
flattening of the inheritance hiergearchy. The reason for this is that types
of inherited components needs to be expanded such that the types can be
looked up from the environment of the base class.
"
Expand Down Expand Up @@ -1221,6 +1221,7 @@ algorithm
local CacheTree tree;
case (scope,path,CACHE(SOME(ENVCACHE(tree)),_))
equation

env = cacheGetEnv(scope,path,tree);
// print("got cached env for ");print(Absyn.pathString(path)); print("\n");
then env;
Expand All @@ -1246,10 +1247,11 @@ algorithm
then CACHE(SOME(ENVCACHE(tree)),ie);
case (fullpath,CACHE(SOME(ENVCACHE(tree)),ie),env)
equation
//print(" about to Adding ");print(Absyn.pathString(fullpath));print(" to cache:\n");
//print(printCacheStr(CACHE(SOME(ENVCACHE(tree)),ie)));
// print(" about to Adding ");print(Absyn.pathString(fullpath));print(" to cache:\n");
tree = cacheAddEnv(fullpath,tree,env);

//print("Adding ");print(Absyn.pathString(fullpath));print(" to cache\n");
//print(printCacheStr(CACHE(SOME(ENVCACHE(tree)),ie)));
then CACHE(SOME(ENVCACHE(tree)),ie);
case (_,_,_) equation print("cacheAdd failed\n"); then fail();
end matchcontinue;
Expand All @@ -1271,24 +1273,28 @@ algorithm
case (path2,path,tree)
equation
env = cacheGetEnv2(path2,path,tree);
//print("found in cache\n");
//print("found ");print(Absyn.pathString(path));print(" in cache\n");
then env;

// Go up one level.
case (path2,path,tree)
// Go up one level. Only if we search for e.g. M.C.E and in scope M
/* case (path2,path,tree)
local Ident id1,id2;
equation
id1=Absyn.pathFirstIdent(path2);
id2 = Absyn.pathFirstIdent(path);
id1 = id2; // only then because otherwise we might lookup wrong class (Eg. Modelica.Math instead of Modelica.Blocks.Math)
path2 =Absyn.stripLast(path2);
env = cacheGetEnv(path2,path,tree);
//print("found in cache\n");
then env;

// Finally try top level
*/
/* // Finally try top level
case (Absyn.IDENT(_),path,CACHETREE(_,_,children))
equation
env = cacheGetEnv3(path,children);
//print("found in cache\n");
then env;

*/
end matchcontinue;
end cacheGetEnv;

Expand Down Expand Up @@ -1379,11 +1385,11 @@ algorithm
local
Ident id,globalID,id2;
Absyn.Path path;
Env globalEnv;
list<CacheTree> children;
Env globalEnv,oldEnv;
list<CacheTree> children,children2;
CacheTree child;
// simple names already added
case (Absyn.IDENT(id),(tree as CACHETREE(globalID,globalEnv,CACHETREE(id2,_,_)::_)),env)
case (Absyn.IDENT(id),(tree as CACHETREE(globalID,globalEnv,CACHETREE(id2,oldEnv,children)::children2)),env)
equation
//print(id);print(" already added\n");
equality(id=id2);
Expand Down Expand Up @@ -1428,15 +1434,14 @@ algorithm
equation
equality(id=id2);
children2 = cacheAddEnv2(path,children2,env);
//print("qualified name, found matching\n");
then CACHETREE(id2,env2,children2)::children;

// simple name, found matching
case (Absyn.IDENT(id),CACHETREE(id2,env2,children2)::children,env)
equation
equality(id=id2);
//print("single name, found matching\n");
then CACHETREE(id2,env,children2)::children;
then CACHETREE(id2,env2,children2)::children;

// try next
case(path,child::children,env)
Expand Down
16 changes: 16 additions & 0 deletions Compiler/Exp.mo
Expand Up @@ -379,6 +379,10 @@ protected import OpenModelica.Compiler.Error;

protected import OpenModelica.Compiler.Debug;

protected import OpenModelica.Compiler.Static;

protected import OpenModelica.Compiler.Env;

protected constant Exp rconstone=RCONST(1.0);


Expand Down Expand Up @@ -7313,5 +7317,17 @@ algorithm
((e_1,b) :: es_1);
end matchcontinue;
end matrixExpMap1Help;

public function CodeVarToCref
input Exp inExp;
output Exp outExp;
algorithm
outExp:=matchcontinue(inExp)
local ComponentRef e_cref; Absyn.ComponentRef cref;
case(CODE(Absyn.C_VARIABLENAME(cref),_)) equation
(_,e_cref) = Static.elabUntypedCref(Env.emptyCache,Env.emptyEnv,cref,false);
then CREF(e_cref,OTHER());
end matchcontinue;
end CodeVarToCref;
end Exp;

19 changes: 11 additions & 8 deletions Compiler/Inst.mo
Expand Up @@ -1128,8 +1128,8 @@ algorithm
s = realString(time);
s=Util.stringAppendList({"instClassIn ",n," ",s," s\n"});
//print(Util.if_(b,s,""));
//print("instClassDef, outenv:");print(Env.printEnvStr(env));
cache = addCachedEnv(cache,n,env_1);
//print("instClassDef, outenv:");print(Env.printEnvStr(env_1));
cache = addCachedEnv(cache,n,env_1);
then
(cache,l,env_1,csets_1,ci_state_1,tys,bc);
case (_,_,_,_,csets,_,_,_,_,_)
Expand Down Expand Up @@ -1262,7 +1262,10 @@ algorithm
s2 = Env.printEnvPathStr(env);
s=Util.stringAppendList({"PARTIAL instClassIn ",n," in scope ",s2," ",s," s\n"});
//print(Util.if_(b,s,""));
//cache = addCachedEnv(cache,n,env);
//print("inCache:");print(Env.printCacheStr(cache));print("\n");
cache = addCachedEnv(cache,n,env_1);
//print("outCache:");print(Env.printCacheStr(cache));print("\n");
//print("partialInstClassDef, outenv:");print(Env.printEnvStr(env_1));
then
(cache,env_1,ci_state_1);
end matchcontinue;
Expand Down Expand Up @@ -1748,7 +1751,7 @@ algorithm
ErrorExt.errorOff();
(cache,m_1) = Mod.elabMod(cache,env, Prefix.NOPRE(), mod, true) "impl" ;
m_2 = Mod.merge(mods, m_1, env, Prefix.NOPRE());
(_,cdef,cenv) = Lookup.lookupClass(cache,env, path, true);
(cache,cdef,cenv) = Lookup.lookupClass(cache,env, path, true);
(cache,dae,env_1,_,ty,st) = instClassBasictype(cache,env, m_2, Prefix.NOPRE(), Connect.emptySet, cdef,
inst_dims, false, INNER_CALL()) "impl" ;
b1 = Types.basicType(ty);
Expand Down Expand Up @@ -2087,7 +2090,7 @@ algorithm
Env.Cache cache;
case (cache,env,mod,(SCode.EXTENDS(path = tp,mod = emod) :: rest),ci_state,impl) /* inherited initial equations inherited algorithms inherited initial algorithms */
equation
(_,(c as SCode.CLASS(cn,_,encf,r,_)),cenv) = Lookup.lookupClass(cache,env, tp, true);
(cache,(c as SCode.CLASS(cn,_,encf,r,_)),cenv) = Lookup.lookupClass(cache,env, tp, true);
outermod = Mod.lookupModificationP(mod, Absyn.IDENT(cn));
(cache,cenv1,els,eq1,ieq1,alg1,ialg1) = instDerivedClasses(cache,cenv, outermod, c, impl);
(cache,tp_1) = makeFullyQualified(cache,cenv1, tp);
Expand Down Expand Up @@ -2181,7 +2184,7 @@ algorithm
Env.Cache cache;
case (cache,env,mod,(SCode.EXTENDS(path = tp,mod = emod) :: rest),ci_state,impl) /* inherited initial equations inherited algorithms inherited initial algorithms */
equation
(_,(c as SCode.CLASS(cn,_,encf,r,_)),cenv) = Lookup.lookupClass(cache,env, tp, true);
(cache,(c as SCode.CLASS(cn,_,encf,r,_)),cenv) = Lookup.lookupClass(cache,env, tp, true);
outermod = Mod.lookupModificationP(mod, Absyn.IDENT(cn));
(cache,cenv1,els,eq1,ieq1,alg1,ialg1) = instDerivedClasses(cache,cenv, outermod, c, impl);
(cache,tp_1) = makeFullyQualified(cache,cenv1, tp);
Expand Down Expand Up @@ -3051,7 +3054,7 @@ algorithm
end matchcontinue;
end memberCrefs;

protected function instElement "function: instElement
public function instElement "function: instElement
This monster function instantiates an element of a class
definition. An element is either a class definition, a variable,
Expand Down Expand Up @@ -3763,7 +3766,7 @@ algorithm
case (cache,_,_,_,SCode.CLASS(name = "Boolean"),_,_) then (cache,{});
case (cache,env,mods,pre,SCode.CLASS(name = id,restricion = SCode.R_TYPE(),parts = SCode.DERIVED(short = cn,absynArrayDimOption = ad,mod = mod)),dims,impl) /* Derived classes with restriction type, e.g. type Point = Real{3}; */
equation
(_,cl,cenv) = Lookup.lookupClass(cache,env, cn, true);
(cache,cl,cenv) = Lookup.lookupClass(cache,env, cn, true);
owncref = Absyn.CREF_IDENT(id,{});
ad_1 = getOptionArraydim(ad);
(cache,mod_1) = Mod.elabMod(cache,env, pre, mod, impl);
Expand Down

0 comments on commit 5c8b937

Please sign in to comment.