Skip to content

Commit

Permalink
- don't build the initial env all the time.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15859 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Apr 19, 2013
1 parent a98fd3a commit 42a0f2f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
76 changes: 60 additions & 16 deletions Compiler/FrontEnd/Builtin.mo
Expand Up @@ -574,26 +574,11 @@ algorithm
end isDer;

public function simpleInitialEnv "
val array2array= (DAE.T_FUNCTION({(\"x\",(DAE.T_ARRAY)},
(DAE.T_ARRAY),NONE())
val array_array2array=
val int2array= (DAE.T_FUNCTION(\"x\",(DAE.T_ARRAY(1,_)),NONE())
Specifierar en vector, array of dimension one
zeroes, ones, fill?

val real_real_int2array
val array2real
val array_array2int

- Initial environment
function: simpleInitialEnv

The initial environment where instantiation takes place is built
up using this function. It creates an empty environment and adds
all the built-in types to it.

This only creates a minimal environment, useful for debugging purposes.
"
This only creates a minimal environment, useful for debugging purposes."
output list<Env.Frame> env;
algorithm
env := Env.newEnvironment(NONE());
Expand Down Expand Up @@ -638,6 +623,12 @@ algorithm
env = Env.getCachedInitialEnv(cache);
then (cache,env);

case (cache)
equation
env = getSetInitialEnv(NONE());
then
(cache, env);

// if no cached version found create initial env.
case (cache) equation
env = Env.openScope(Env.emptyEnv, SCode.NOT_ENCAPSULATED(), NONE(), NONE());
Expand Down Expand Up @@ -718,6 +709,7 @@ algorithm
Absyn.PROGRAM(classes=initialClasses) = getInitialFunctions();
env = Env.extendFrameClasses(env, listReverse(List.fold(initialClasses, SCodeUtil.translate2, {}))) "Add classes in the initial env";
cache = Env.setCachedInitialEnv(cache,env);
_ = getSetInitialEnv(SOME(env));
then (cache,env);
end matchcontinue;
end initialEnv;
Expand Down Expand Up @@ -806,5 +798,57 @@ algorithm
end matchcontinue;
end getInitialFunctions;

protected function getSetInitialEnv
"gets/sets the initial environment depending on grammar flags"
input Option<Env.Env> inEnvOpt;
output Env.Env initialEnv;
algorithm
initialEnv := matchcontinue (inEnvOpt)
local
list<tuple<Integer,Env.Env>> assocLst;
Env.Env env;

// nothing there
case (_)
equation
failure(_ = getGlobalRoot(Global.builtinEnvIndex));
setGlobalRoot(Global.builtinEnvIndex,{});
then
fail();

// return the correct env depending on flags
case (NONE())
equation
assocLst = getGlobalRoot(Global.builtinEnvIndex);
then
Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst);

case (SOME(env))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA);
assocLst = getGlobalRoot(Global.builtinEnvIndex);
setGlobalRoot(Global.builtinEnvIndex, (Flags.METAMODELICA,env)::assocLst);
then
env;

case (SOME(env))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA);
assocLst = getGlobalRoot(Global.builtinEnvIndex);
setGlobalRoot(Global.builtinEnvIndex, (Flags.PARMODELICA,env)::assocLst);
then
env;

case (SOME(env))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.MODELICA) or intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA);
assocLst = getGlobalRoot(Global.builtinEnvIndex);
setGlobalRoot(Global.builtinEnvIndex, (Flags.MODELICA,env)::assocLst);
then
env;

end matchcontinue;
end getSetInitialEnv;

end Builtin;

1 change: 1 addition & 0 deletions Compiler/Global/Global.mo
Expand Up @@ -44,6 +44,7 @@ constant Integer instHashIndex = 0;
constant Integer typesIndex = 1;
constant Integer crefIndex = 2;
constant Integer builtinIndex = 3;
constant Integer builtinEnvIndex = 4;
constant Integer profilerTime1Index = 5;
constant Integer profilerTime2Index = 6;
constant Integer flagsIndex = 7;
Expand Down

0 comments on commit 42a0f2f

Please sign in to comment.