Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
all synchronous features except state machines should work (ticket:5127)
Browse files Browse the repository at this point in the history
- do not constant evaluate impure functions
- better fix for sample that requires no patching of NFModelicaBuiltin.mo

Belonging to [master]:
  - #2667
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Sep 19, 2018
1 parent 0f7d6b9 commit 3048851
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 60 deletions.
53 changes: 10 additions & 43 deletions Compiler/FFrontEnd/FBuiltin.mo
Expand Up @@ -362,7 +362,7 @@ algorithm

(initialProgram,initialSCodeProgram) := matchcontinue ()
local
list<tuple<tuple<Integer,Config.LanguageStandard>,tuple<Absyn.Program,SCode.Program>>> assocLst;
list<tuple<Integer,tuple<Absyn.Program,SCode.Program>>> assocLst;
list<Absyn.Class> classes,classes1,classes2;
Absyn.Program p;
SCode.Program sp;
Expand All @@ -374,60 +374,56 @@ algorithm
case ()
equation
assocLst = getGlobalRoot(Global.builtinIndex);
((p,sp)) = Util.assoc((Flags.getConfigEnum(Flags.GRAMMAR), Config.getLanguageStandard()), assocLst);
((p,sp)) = Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileMetaModelica),Error.FILE_NOT_FOUND_ERROR,{fileMetaModelica},Absyn.dummyInfo);
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) =
patchSample(Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA));
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes2,within_=Absyn.TOP()) = Parser.parsebuiltin(fileMetaModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
classes = listAppend(classes1,classes2);
p = Absyn.PROGRAM(classes,Absyn.TOP());
(p as Absyn.PROGRAM(classes=classes)) = MetaUtil.createMetaClassesInProgram(p);
sp = List.map(classes, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.METAMODELICA, Config.getLanguageStandard()), (p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, (Flags.METAMODELICA,(p,sp))::assocLst);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileParModelica),Error.FILE_NOT_FOUND_ERROR,{fileParModelica},Absyn.dummyInfo);
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) =
patchSample(Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA));
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes2,within_=Absyn.TOP()) = Parser.parsebuiltin(fileParModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
classes = listAppend(classes1,classes2);
p = Absyn.PROGRAM(classes,Absyn.TOP());
sp = List.map(classes, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.PARMODELICA,Config.getLanguageStandard()), (p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, (Flags.PARMODELICA,(p,sp))::assocLst);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.MODELICA) or intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
(p as Absyn.PROGRAM(classes=classes)) =
patchSample(Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA));
(p as Absyn.PROGRAM(classes=classes)) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
sp = List.map(classes, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.MODELICA, Config.getLanguageStandard()), (p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, (Flags.MODELICA,(p,sp))::assocLst);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(filePDEModelica),Error.FILE_NOT_FOUND_ERROR,{filePDEModelica},Absyn.dummyInfo);
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) =
patchSample(Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA));
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes2,within_=Absyn.TOP()) = Parser.parsebuiltin(filePDEModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
classes = listAppend(classes1,classes2);
p = Absyn.PROGRAM(classes,Absyn.TOP());
sp = List.map(classes, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, ((Flags.PDEMODELICA, Config.getLanguageStandard()), (p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, (Flags.PDEMODELICA,(p,sp))::assocLst);
then (p,sp);

else
Expand All @@ -437,35 +433,6 @@ algorithm
end matchcontinue;
end getInitialFunctions;

protected function patchSample
"patch sample definition if --std < 3.3"
input output Absyn.Program p;
protected
list<Absyn.Class> classes;
Absyn.Within w;
algorithm
if not Config.synchronousFeaturesAllowed() then
Absyn.PROGRAM(classes, w) := p;
classes := List.map(classes, samplePatch);
p := Absyn.PROGRAM(classes, w);
end if;
end patchSample;

protected function samplePatch
input Absyn.Class inCls;
output Absyn.Class outCls;
protected
Absyn.Class c;
Option<Absyn.Comment> cmt;
list<Absyn.Path> functionNames;
algorithm
outCls := match(inCls)
case c as Absyn.CLASS(name="sample", body = Absyn.OVERLOAD(functionNames, cmt))
then Absyn.setClassBody(c, Absyn.OVERLOAD({listHead(functionNames),listHead(functionNames)}, cmt));
else inCls;
end match;
end samplePatch;

public function initialGraph
"The initial environment where instantiation takes place is built
up using this function. It creates an empty environment and adds
Expand Down
9 changes: 7 additions & 2 deletions Compiler/FrontEnd/NFSCodeDependency.mo
Expand Up @@ -45,6 +45,7 @@ public import NFSCodeEnv;

public type Env = NFSCodeEnv.Env;

protected import Config;
protected import Debug;
protected import Error;
protected import Flags;
Expand Down Expand Up @@ -579,8 +580,12 @@ algorithm
// Other cases which doesn't need to be analysed.
case (SCode.ENUMERATION(), _, _, _, _) then ();
case (SCode.OVERLOAD(pathLst = paths), _, _, _, _)
equation
List.map2_0(paths,analyseClass,inEnv,inInfo);
algorithm
if not Config.synchronousFeaturesAllowed() and Absyn.pathFirstIdent(listHead(paths)) == "OMC_NO_CLOCK" then
List.map2_0({listHead(paths)},analyseClass,inEnv,inInfo);
else
List.map2_0(paths,analyseClass,inEnv,inInfo);
end if;
then ();
case (SCode.PDER(), _, _, _, _) then ();

Expand Down
20 changes: 20 additions & 0 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -477,6 +477,16 @@ uniontype Call
end match;
end isExternal;

function isImpure
input Call call;
output Boolean isImpure;
algorithm
isImpure := match call
case TYPED_CALL() then Function.isImpure(call.fn);
else false;
end match;
end isImpure;

function isRecordConstructor
input Call call;
output Boolean isConstructor;
Expand Down Expand Up @@ -1203,6 +1213,16 @@ protected
then Type.arrayElementType(Expression.typeOf(Expression.unbox(listHead(args))));
case Absyn.IDENT("previous")
then Expression.typeOf(Expression.unbox(listHead(args)));
case Absyn.IDENT("shiftSample")
then Expression.typeOf(Expression.unbox(listHead(args)));
case Absyn.IDENT("backSample")
then Expression.typeOf(Expression.unbox(listHead(args)));
case Absyn.IDENT("hold")
then Expression.typeOf(Expression.unbox(listHead(args)));
case Absyn.IDENT("superSample")
then Expression.typeOf(Expression.unbox(listHead(args)));
case Absyn.IDENT("subSample")
then Expression.typeOf(Expression.unbox(listHead(args)));
else
algorithm
Error.assertion(false, getInstanceName() + ": unhandled case for " +
Expand Down
5 changes: 4 additions & 1 deletion Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -173,7 +173,10 @@ algorithm
exp;

case Expression.CALL()
then evalCall(exp.call, target);
then
if Call.isImpure(exp.call) // do NOT evaluate impure calls!
then exp
else evalCall(exp.call, target);

case Expression.SIZE(dimIndex = SOME(exp1))
algorithm
Expand Down

0 comments on commit 3048851

Please sign in to comment.