Skip to content

Commit

Permalink
- Tons of API functions updated and/or added (regularFileExist uses M…
Browse files Browse the repository at this point in the history
…odelicaInternal now, etc)

- Made it possible to easily change the error-messages to print more detailed file locations in the future (will be added today or tomorrow; will need to update a lot of tests)
- Modified uriToFileName (it now uses the scripting environment and builtin functions that also work at runtime). The reason it works is that we can read the paths of each library at compile-time and use that information to resolve the URI at runtime.
- ModelicaServices now uses uriToFileName to resolve URIs
- More ModelicaExternalC functions have a builtin compiler implementation now
- Assigning to arrays with unknown dimensions is now a little more stable at runtime
- runtest.pl now knows of the directive partest-link: (see UriLookup.mos for an example)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14920 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 24, 2013
1 parent 0f80740 commit 021b098
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 95 deletions.
134 changes: 131 additions & 3 deletions Compiler/FrontEnd/Ceval.mo
Expand Up @@ -1072,6 +1072,7 @@ algorithm
case "anyString" equation true = Config.acceptMetaModelicaGrammar(); then cevalAnyString;
case "numBits" then cevalNumBits;
case "integerMax" then cevalIntegerMax;
case "getLoadedLibraries" then cevalGetLoadedLibraries;

//case "semiLinear" then cevalBuiltinSemiLinear;
//case "delay" then cevalBuiltinDelay;
Expand Down Expand Up @@ -1142,9 +1143,12 @@ algorithm
case ("ModelicaInternal_print") then ();
case ("ModelicaInternal_countLines") then ();
case ("ModelicaInternal_readLine") then ();
case ("ModelicaInternal_stat") then ();
case ("ModelicaInternal_fullPathName") then ();
case ("ModelicaStrings_scanReal") then ();
case ("ModelicaStrings_skipWhiteSpace") then ();
case ("ModelicaError") then ();
case ("System_regexModelica") then ();
end match;
end isKnownExternalFunc;

Expand All @@ -1157,9 +1161,13 @@ algorithm
outValue := match (id,inValuesValueLst,inMsg)
local
Real rv_1,rv,rv1,rv2,sv,cv,r;
String str,fileName;
Integer start, stop, i, lineNumber;
Boolean b;
String str,fileName,re;
Integer start, stop, i, lineNumber, n;
Boolean b, extended, insensitive;
list<String> strs;
list<Values.Value> vals;
Values.Value v;
Absyn.Path p;

case ("acos",{Values.REAL(real = rv)},_)
equation
Expand Down Expand Up @@ -1260,6 +1268,17 @@ algorithm
equation
(str,b) = ModelicaExternalC.Streams_readLine(fileName,lineNumber);
then Values.TUPLE({Values.STRING(str),Values.BOOL(b)});
case ("ModelicaInternal_fullPathName",{Values.STRING(fileName)},_)
equation
fileName = ModelicaExternalC.File_fullPathName(fileName);
then Values.STRING(fileName);
case ("ModelicaInternal_stat",{Values.STRING(str)},_)
equation
i = ModelicaExternalC.File_stat(str);
str = listGet({"NoFile", "RegularFile", "Directory", "SpecialFile"}, i);
p = Absyn.stringListPath({"OpenModelica","Scripting","Internal","FileType",str});
v = Values.ENUM_LITERAL(p,i);
then v;

case ("ModelicaStrings_scanReal",{Values.STRING(str),Values.INTEGER(i),Values.BOOL(b)},_)
equation
Expand All @@ -1271,9 +1290,42 @@ algorithm
i = ModelicaExternalC.Strings_advanced_skipWhiteSpace(str,i);
then Values.INTEGER(i);

case ("System_regexModelica",{Values.STRING(str),Values.STRING(re),Values.INTEGER(i),Values.BOOL(extended),Values.BOOL(insensitive)},_)
equation
v = cevalRegex(str,re,i,extended,insensitive);
then v;

end match;
end cevalKnownExternalFuncs2;

protected function cevalRegex
input String str;
input String re;
input Integer i;
input Boolean extended;
input Boolean insensitive;
output Values.Value v;
algorithm
v := matchcontinue (str,re,i,extended,insensitive)
local
Integer n;
list<String> strs;
list<Values.Value> vals;
case (_,_,_,_,_)
equation
(n,strs) = System.regex(str,re,i,extended,insensitive);
vals = List.map(strs,ValuesUtil.makeString);
v = Values.ARRAY(vals,{i});
then Values.TUPLE({Values.INTEGER(n),v});
else
equation
strs = List.fill("",i);
vals = List.map(strs,ValuesUtil.makeString);
v = Values.ARRAY(vals,{i});
then Values.TUPLE({Values.INTEGER(-1),v});
end matchcontinue;
end cevalRegex;

protected function cevalMatrixElt "function: cevalMatrixElt
Evaluates the expression of a matrix constructor, e.g. {1,2;3,4}"
input Env.Cache inCache;
Expand Down Expand Up @@ -2685,6 +2737,82 @@ algorithm
end match;
end cevalIntegerMax;

protected function cevalGetLoadedLibraries
input Env.Cache inCache;
input Env.Env inEnv;
input list<DAE.Exp> inExpExpLst;
input Boolean inBoolean;
input Option<Interactive.SymbolTable> inST;
input Msg inMsg;
output Env.Cache outCache;
output Values.Value outValue;
output Option<Interactive.SymbolTable> outST;
algorithm
(outCache,outValue,outST) := match (inCache,inEnv,inExpExpLst,inBoolean,inST,inMsg)
local
Env.Cache cache;
Env.Env env;
Env.Frame fr;
list<SCode.Element> classes;
list<Absyn.Class> absynclasses;
Values.Value v;
case (cache,env,{},_,SOME(Interactive.SYMBOLTABLE(ast=Absyn.PROGRAM(classes=absynclasses))),_)
equation
v = ValuesUtil.makeArray(List.fold(absynclasses,makeLoadLibrariesEntryAbsyn,{}));
then (cache,v,inST);
case (cache,env,{},_,_,_)
equation
fr::_ = listReverse(env);
classes = Env.getClassesInFrame(fr);
v = ValuesUtil.makeArray(List.fold(classes,makeLoadLibrariesEntry,{}));
then (cache,v,inST);
end match;
end cevalGetLoadedLibraries;

protected function makeLoadLibrariesEntry "Needed to be able to resolve modelica:// during runtime, etc.
Should not be part of CevalScript since ModelicaServices needs this feature and the frontend needs to take care of it."
input SCode.Element cl;
input list<Values.Value> acc;
output list<Values.Value> out;
algorithm
out := match (cl,acc)
local
String name,fileName,dir;
Values.Value v;
Boolean b;
case (SCode.CLASS(info=Absyn.INFO(fileName="<interactive>")),_) then acc;
case (SCode.CLASS(name=name,info=Absyn.INFO(fileName=fileName)),_)
equation
dir = System.dirname(fileName);
fileName = System.basename(fileName);
v = ValuesUtil.makeArray({Values.STRING(name),Values.STRING(dir)});
b = stringEq(fileName,"ModelicaBuiltin.mo") or stringEq(fileName,"MetaModelicaBuiltin.mo") or stringEq(dir,".");
then List.consOnTrue(not b,v,acc);
end match;
end makeLoadLibrariesEntry;

protected function makeLoadLibrariesEntryAbsyn "Needed to be able to resolve modelica:// during runtime, etc.
Should not be part of CevalScript since ModelicaServices needs this feature and the frontend needs to take care of it."
input Absyn.Class cl;
input list<Values.Value> acc;
output list<Values.Value> out;
algorithm
out := match (cl,acc)
local
String name,fileName,dir;
Values.Value v;
Boolean b;
case (Absyn.CLASS(info=Absyn.INFO(fileName="<interactive>")),_) then acc;
case (Absyn.CLASS(name=name,info=Absyn.INFO(fileName=fileName)),_)
equation
dir = System.dirname(fileName);
fileName = System.basename(fileName);
v = ValuesUtil.makeArray({Values.STRING(name),Values.STRING(dir)});
b = stringEq(fileName,"ModelicaBuiltin.mo") or stringEq(fileName,"MetaModelicaBuiltin.mo") or stringEq(dir,".");
then List.consOnTrue(not b,v,acc);
end match;
end makeLoadLibrariesEntryAbsyn;

protected function cevalListFirst
input Env.Cache inCache;
input Env.Env inEnv;
Expand Down
80 changes: 44 additions & 36 deletions Compiler/FrontEnd/Env.mo
Expand Up @@ -139,10 +139,8 @@ public uniontype Cache
end Cache;

public uniontype EnvCache
record ENVCACHE
"Cache for environments. The cache consists of a tree
of environments from which lookupcan be performed."
CacheTree envTree;
record ENVCACHE "Cache for environments. The cache consists of a tree of environments from which lookup can be performed."
CacheTree envTree;
end ENVCACHE;
end EnvCache;

Expand Down Expand Up @@ -1439,38 +1437,6 @@ algorithm
end match;
end printFrameElementStr;

protected function isVarItem "function: isVarItem
Succeeds if item is a VAR."
input tuple<Type_a, Item> inTplTypeAItem;
replaceable type Type_a subtypeof Any;
algorithm
_:=
matchcontinue (inTplTypeAItem)
case ((_,VAR(instantiated = _))) then ();
end matchcontinue;
end isVarItem;

protected function isClassItem "function: isClassItem
Succeeds if item is a CLASS."
input tuple<Type_a, Item> inTplTypeAItem;
replaceable type Type_a subtypeof Any;
algorithm
_ := matchcontinue (inTplTypeAItem)
case ((_,CLASS(cls = _))) then ();
end matchcontinue;
end isClassItem;

protected function isTypeItem "function: isTypeItem
Succeds if item is a TYPE."
input tuple<Type_a, Item> inTplTypeAItem;
replaceable type Type_a subtypeof Any;
algorithm
_:=
matchcontinue (inTplTypeAItem)
case ((_,TYPE(tys = _))) then ();
end matchcontinue;
end isTypeItem;

public function getCachedInitialEnv "get the initial environment from the cache"
input Cache cache;
output Env env;
Expand Down Expand Up @@ -2911,5 +2877,47 @@ algorithm
end match;
end avlTreeReplace2;

public function getClassesInFrame
input Frame fr;
output list<SCode.Element> elts;
protected
AvlTree ht;
list<AvlTreeValue> vals;
algorithm
FRAME(clsAndVars=ht) := fr;
vals := getAvlTreeItems(SOME(ht)::{},{});
elts := List.fold(vals,getClassesFromItem,{});
end getClassesInFrame;

protected function getClassesFromItem
input AvlTreeValue v;
input list<SCode.Element> acc;
output list<SCode.Element> res;
algorithm
res := match (v,acc)
local
SCode.Element c;
case (AVLTREEVALUE(value=CLASS(cls=c)),_) then c::acc;
else acc;
end match;
end getClassesFromItem;

protected function getAvlTreeItems
input list<Option<AvlTree>> tree;
input list<AvlTreeValue> acc;
output list<AvlTreeValue> res;
algorithm
res := match (tree,acc)
local
Option<AvlTreeValue> value;
Option<AvlTree> left,right;
list<Option<AvlTree>> rest;
case ({},_) then acc;
case (SOME(AVLTREENODE(value=value,left=left,right=right))::rest,_)
then getAvlTreeItems(left::right::rest,List.consOption(value,acc));
case (NONE()::rest,_) then getAvlTreeItems(rest,acc);
end match;
end getAvlTreeItems;

end Env;

0 comments on commit 021b098

Please sign in to comment.