Skip to content

Commit

Permalink
- Added list<Integer> dimLst to Values.ARRAY
Browse files Browse the repository at this point in the history
  * This means we can ceval {} and still know it has dimensions [0,3,2,5]
  * Updated C runtime
  * Updated elabBuiltinXXX to return correct type
  * Rewrote parts of vectorizeCall
  * Rewrote ValuesUtil and Ceval to set the correct dimensions of its calculated results
  * Didn't optimize all parts that use listLength on the valueLst. This could be improved also in in runtime


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4972 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 17, 2010
1 parent aea77c6 commit a0776c5
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 339 deletions.
281 changes: 148 additions & 133 deletions Compiler/Ceval.mo

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions Compiler/CevalScript.mo
Expand Up @@ -490,7 +490,7 @@ algorithm
equation
(cache,executable,method_str,st,initfilename) = buildModel(cache,env, exp, st_1, msg);
then
(cache,Values.ARRAY({Values.STRING(executable),Values.STRING(initfilename)}),st);
(cache,ValuesUtil.makeArray({Values.STRING(executable),Values.STRING(initfilename)}),st);

case (cache,env,(exp as
DAE.CALL(
Expand All @@ -512,7 +512,7 @@ algorithm
instClsLst = ic,
lstVarVal = iv,
compiledFunctions = cf)),msg) /* failing build_model */
then (cache,Values.ARRAY({Values.STRING(""),Values.STRING("")}),st_1);
then (cache,ValuesUtil.makeArray({Values.STRING(""),Values.STRING("")}),st_1);

case (cache,env,(exp as
DAE.CALL( path = Absyn.IDENT(name = "buildModelBeast"), expLst = {DAE.CODE(Absyn.C_TYPENAME(className),_), starttime,
Expand All @@ -521,7 +521,7 @@ algorithm
equation
(cache,executable,method_str,st,initfilename) = buildModelBeast(cache,env, exp, st_1, msg);
then
(cache,Values.ARRAY({Values.STRING(executable),Values.STRING(initfilename)}),st);
(cache,ValuesUtil.makeArray({Values.STRING(executable),Values.STRING(initfilename)}),st);

/* adrpo: see if the model exists before simulation! */
case (cache,env,(exp as
Expand Down Expand Up @@ -1456,7 +1456,7 @@ algorithm
equation
varName = Exp.CodeVarToCref(varName);
varNameStr = Exp.printExpStr(varName);
(cache,Values.ARRAY(vals),SOME(st)) = Ceval.ceval(cache,env, varTimeStamp, true, SOME(st), NONE, msg);
(cache,Values.ARRAY(valueLst = vals),SOME(st)) = Ceval.ceval(cache,env, varTimeStamp, true, SOME(st), NONE, msg);
timeStamps = Util.listMap(vals,ValuesUtil.valueReal);
(cache,val) = cevalValArray(cache,env,SOME(st),timeStamps,varNameStr);
then
Expand Down Expand Up @@ -2093,7 +2093,7 @@ algorithm
equation
(cache,st,xml_filename,xml_contents) = dumpXMLDAE(cache,env, exp, st_1, msg);
then
(cache,Values.ARRAY({Values.STRING(xml_filename),Values.STRING(xml_contents)}),st);
(cache,ValuesUtil.makeArray({Values.STRING(xml_filename),Values.STRING(xml_contents)}),st);

case (cache,env,(exp as
DAE.CALL(
Expand All @@ -2114,7 +2114,7 @@ algorithm
instClsLst = ic,
lstVarVal = iv,
compiledFunctions = cf)),msg) /* failing build_model */
then (cache,Values.ARRAY({Values.STRING("Xml dump error"),Values.STRING("")}),st_1);
then (cache,ValuesUtil.makeArray({Values.STRING("Xml dump error"),Values.STRING("")}),st_1);
end matchcontinue;
end cevalInteractiveFunctions;
Expand Down Expand Up @@ -2147,13 +2147,18 @@ protected function cevalValArray "Help function to cevalInteractiveFunctions. Ha
output Values.Value value;
algorithm
(outCache,value) := matchcontinue(cache,env,st,timeStamps,varName)
local list<Values.Value> vals;
Real v,timeStamp;
case(cache,env,st,{},varName) then (cache,Values.ARRAY({}));
case(cache,env,st,timeStamp::timeStamps,varName) equation
(cache,v) = cevalVal(cache,env,st,timeStamp,varName);
(cache,Values.ARRAY(vals)) = cevalValArray(cache,env,st,timeStamps,varName);
then (cache,Values.ARRAY(Values.REAL(v)::vals));
local
list<Values.Value> vals;
Real v,timeStamp;
Integer i;
list<Integer> dims;
case(cache,env,st,{},varName) then (cache,Values.ARRAY({},{0}));
case(cache,env,st,timeStamp::timeStamps,varName)
equation
(cache,v) = cevalVal(cache,env,st,timeStamp,varName);
(cache,Values.ARRAY(vals,i::dims)) = cevalValArray(cache,env,st,timeStamps,varName);
i = i+1;
then (cache,Values.ARRAY(Values.REAL(v)::vals,i::dims));
end matchcontinue;
end cevalValArray;
Expand All @@ -2174,13 +2179,13 @@ algorithm
(cache,Values.RECORD(orderd={Values.STRING(filename)}),_) = Ceval.ceval(cache,env,
DAE.CREF(DAE.CREF_IDENT("currentSimulationResult",DAE.ET_OTHER(),{}),DAE.ET_OTHER()), true, SOME(st), NONE, Ceval.NO_MSG());
Values.ARRAY({Values.ARRAY(varValues)}) = SimulationResults.readPtolemyplotDataset(filename, {varName}, 0);
Values.ARRAY({Values.ARRAY(timeValues)}) = SimulationResults.readPtolemyplotDataset(filename, {"time"}, 0);
Values.ARRAY(valueLst = {Values.ARRAY(valueLst = varValues)}) = SimulationResults.readPtolemyplotDataset(filename, {varName}, 0);
Values.ARRAY(valueLst = {Values.ARRAY(valueLst = timeValues)}) = SimulationResults.readPtolemyplotDataset(filename, {"time"}, 0);
tV = ValuesUtil.valueReals(timeValues);
vV = ValuesUtil.valueReals(varValues);
val = System.getVariableValue(timeStamp, tV, vV);
then (cache,val);
then (cache,val);
end matchcontinue;
end cevalVal;
Expand Down
28 changes: 15 additions & 13 deletions Compiler/Cevalfunc.mo
Expand Up @@ -621,7 +621,7 @@ algorithm
env2;
case(env, Absyn.ALG_FOR({(varName, SOME(ae1))},forBody = algitemlst),ht2)
equation
(Values.ARRAY(values)) = evaluateSingleExpression(ae1, env,NONE,ht2);
(Values.ARRAY(valueLst = values)) = evaluateSingleExpression(ae1, env,NONE,ht2);
start = listNth(values,0);
env1 = addForLoopScope(env,varName,start);
env2 = evaluateForLoopArray(env1, varName, values, algitemlst, ht2);
Expand Down Expand Up @@ -1243,7 +1243,7 @@ algorithm
true = (listLength(inDims)>0);
value = instFunctionArray2(dims, ty,optVal);
values = Util.listFill(value,dim);
value = Values.ARRAY(values);
value = Values.ARRAY(values, dim::dims);
then
value;
case({}, ty , SOME(value))
Expand Down Expand Up @@ -1426,26 +1426,27 @@ algorithm oval := matchcontinue(oldVal,newVal,insubs,env,ty)
DAE.Exp e1;
Integer x;
Absyn.Exp exp;
list<Integer> dims;
case(_,newVal,{},_,ty)
equation
(ty,_) = Types.flattenArrayType(ty);
value = checkValueTypes(newVal,ty);
then value;

case((oldVal as Values.ARRAY(valueLst = values1)),newVal,((sub as Absyn.SUBSCRIPT(exp))::subs),env,ty)
case((oldVal as Values.ARRAY(valueLst = values1, dimLst = dims)),newVal,((sub as Absyn.SUBSCRIPT(exp))::subs),env,ty)
equation
(_,e1,_,_,_) = Static.elabExp(Env.emptyCache(),env,exp,true,NONE,false);
(_,value as Values.INTEGER(x),_) = Ceval.ceval(Env.emptyCache(),env, e1, true, NONE, NONE, Ceval.MSG());
val1 = listNth(values1 ,(x-1)); // to be replaced
val2 = mergeValues(val1,newVal,subs,env,ty);
values2 = Util.listReplaceAt(val2,(x-1),values1);
val3 = Values.ARRAY(values2);
val3 = Values.ARRAY(values2,dims);
then
val3;
case((oldVal as Values.ARRAY(valueLst = values1)),(newVal as Values.ARRAY(valueLst = values2)),((sub as Absyn.NOSUB)::subs),env,ty)
case((oldVal as Values.ARRAY(valueLst = values1, dimLst = dims)),(newVal as Values.ARRAY(valueLst = values2)),((sub as Absyn.NOSUB)::subs),env,ty)
equation
values3 = mergeValues2(values1,values2,subs,env,ty);
val3 = Values.ARRAY(values3);
val3 = Values.ARRAY(values3,dims);
then
val3;
end matchcontinue;
Expand Down Expand Up @@ -1484,18 +1485,19 @@ algorithm outVal := matchcontinue(val,ty)
local
list<Values.Value> vals1,vals2;
Values.Value val1,val2;
list<Integer> dims;
Integer ix;
Real rx;
case(Values.ARRAY(vals1), ty as (DAE.T_REAL(_),_))
case(Values.ARRAY(vals1,dims), ty as (DAE.T_REAL(_),_))
equation
vals2 = Util.listMap1(vals1,checkValueTypes,ty) ;
val1 = Values.ARRAY(vals2);
val1 = Values.ARRAY(vals2,dims);
then
val1;
case(Values.ARRAY(vals1), ty as (DAE.T_INTEGER(_),_))
case(Values.ARRAY(vals1,dims), ty as (DAE.T_INTEGER(_),_))
equation
vals2 = Util.listMap1(vals1,checkValueTypes,ty);
val1 = Values.ARRAY(vals2);
val1 = Values.ARRAY(vals2,dims);
then
val1;
case(Values.INTEGER(ix), ty as (DAE.T_REAL(_),_))
Expand Down Expand Up @@ -1612,7 +1614,7 @@ algorithm res := matchcontinue(v,inRef)
Real r;
Boolean b;
String str;
case(Values.ARRAY(vals),inRef)
case(Values.ARRAY(valueLst = vals),inRef)
equation
res = createReplacementRulesRecordArray(vals,{},inRef,0);
then
Expand Down Expand Up @@ -1654,8 +1656,8 @@ algorithm res := matchcontinue(inVals,subs,inCref,offset)
list<tuple<DAE.ComponentRef, DAE.Exp>> res1,res2;
DAE.ComponentRef cref;
case({},_,_,_) then {};
case(Values.ARRAY({})::{},_,_,_) then {};
case((v as Values.ARRAY(vals2))::vals1,subs,inCref,offset)
case(Values.ARRAY(valueLst = {})::{},_,_,_) then {};
case((v as Values.ARRAY(valueLst = vals2))::vals1,subs,inCref,offset)
equation
offset=offset+1;
res2 = createReplacementRulesRecordArray(vals1,subs,inCref,offset);
Expand Down
32 changes: 18 additions & 14 deletions Compiler/Inst.mo
Expand Up @@ -11518,7 +11518,7 @@ algorithm
(cache,DAE.ATTR(false,false,SCode.RW(),SCode.VAR(),_,_),(DAE.T_INTEGER(_),_),DAE.UNBOUND(),_,_)
= Lookup.lookupVar(cache,env_1, DAE.CREF_IDENT(i,DAE.ET_OTHER(),{}));
vals = Ceval.cevalRange(1,1,len);
(cache,dae,csets_1,graph) = unroll(cache,env_1, mod, pre, csets, ci_state, i, Values.ARRAY(vals), el, initial_, impl,graph);
(cache,dae,csets_1,graph) = unroll(cache,env_1, mod, pre, csets, ci_state, i, Values.ARRAY(vals,{len}), el, initial_, impl,graph);
ci_state_1 = instEquationCommonCiTrans(ci_state, initial_);
then
(cache,env,ih,dae,csets_1,ci_state_1,graph);
Expand All @@ -11540,7 +11540,7 @@ algorithm
(cache,DAE.ATTR(false,false,SCode.RW(),SCode.VAR(),_,_),(DAE.T_INTEGER(_),_),DAE.UNBOUND(),_,_)
= Lookup.lookupVar(cache,env_1, DAE.CREF_IDENT(i,DAE.ET_OTHER(),{}));
vals = Ceval.cevalRange(1,1,len);
(cache,dae,csets_1,graph) = unroll(cache,env_1, mod, pre, csets, ci_state, i, Values.ARRAY(vals), el, initial_, impl,graph);
(cache,dae,csets_1,graph) = unroll(cache,env_1, mod, pre, csets, ci_state, i, Values.ARRAY(vals,{len}), el, initial_, impl,graph);
ci_state_1 = instEquationCommonCiTrans(ci_state, initial_);
then
(cache,env,ih,dae,csets_1,ci_state_1,graph);
Expand Down Expand Up @@ -12203,14 +12203,14 @@ algorithm
print(" implement assignComplexConstantConstruct for records of records\n");
then fail();

case(Values.RECORD(p, (v as Values.ARRAY(arrVals))::vals, n::names, index),cr,source)
case(Values.RECORD(p, (v as Values.ARRAY(valueLst = arrVals))::vals, n::names, index),cr,source)
equation
cr2 = Exp.crefAppend(cr,DAE.CREF_IDENT(n,DAE.ET_OTHER,{}));
eqns = assignComplexConstantConstruct(Values.RECORD(p,vals,names,index),cr,source);
eqnsArray = assignComplexConstantConstructToArray(arrVals,cr2,source,1);
eqns = listAppend(eqns,eqnsArray);
then
eqns;
then
eqns;
case(Values.RECORD(p, v::vals, n::names, index),cr,source)
equation
cr2 = Exp.crefAppend(cr,DAE.CREF_IDENT(n,DAE.ET_INT,{}));
Expand Down Expand Up @@ -12256,7 +12256,7 @@ algorithm eqns := matchcontinue(arr,assigned,source,subPos)
list<Values.Value> arrVals;
list<DAE.Element> eqns2;
case({},_,_,_) then {};
case((v as Values.ARRAY(arrVals))::arr,assigned,source,subPos)
case((v as Values.ARRAY(valueLst = arrVals))::arr,assigned,source,subPos)
equation
eqns = assignComplexConstantConstructToArray(arr,assigned,source,subPos+1);
assigned = Exp.addSubscriptsLast(assigned,subPos);
Expand Down Expand Up @@ -12446,38 +12446,42 @@ algorithm
Boolean impl;
Env.Cache cache;
ConnectionGraph.ConnectionGraph graph;
list<Integer> dims;
Integer dim;
case (cache,_,_,_,csets,_,_,Values.ARRAY(valueLst = {}),_,_,_,graph)
then (cache,DAEUtil.emptyDae,csets,graph); /* impl */

/* array equation, use instEEquation */
case (cache,env,mods,pre,csets,ci_state,i,Values.ARRAY(valueLst = (fst :: rest)),eqs,(initial_ as SCode.NON_INITIAL()),impl,graph)
equation
case (cache,env,mods,pre,csets,ci_state,i,Values.ARRAY(valueLst = (fst :: rest), dimLst = dim :: dims),eqs,(initial_ as SCode.NON_INITIAL()),impl,graph)
equation
dim = dim-1;
dims = dim::dims;
env_1 = Env.openScope(env, false, SOME(Env.forScopeName));
env_2 = Env.extendFrameForIterator(env_1, i, (DAE.T_INTEGER({}), NONE), DAE.VALBOUND(fst), SCode.CONST());
/* use instEEquation*/
(cache,env_3,_,dae1,csets_1,ci_state_1,graph) = instList(cache,env_2,InstanceHierarchy.emptyInstHierarchy, mods, pre, csets, ci_state, instEEquation, eqs, impl,graph);
(cache,dae2,csets_2,graph) = unroll(cache,env, mods, pre, csets_1, ci_state_1, i, Values.ARRAY(rest), eqs, initial_, impl,graph);
(cache,dae2,csets_2,graph) = unroll(cache,env, mods, pre, csets_1, ci_state_1, i, Values.ARRAY(rest,dims), eqs, initial_, impl,graph);
dae = DAEUtil.joinDaes(dae1, dae2);
then
(cache,dae,csets_2,graph);

/* initial array equation, use instEInitialequation */
case (cache,env,mods,pre,csets,ci_state,i,Values.ARRAY(valueLst = (fst :: rest)),eqs,(initial_ as SCode.INITIAL()),impl,graph)
case (cache,env,mods,pre,csets,ci_state,i,Values.ARRAY(valueLst = (fst :: rest), dimLst = dim :: dims),eqs,(initial_ as SCode.INITIAL()),impl,graph)
equation
dim = dim-1;
dims = dim::dims;
env_1 = Env.openScope(env, false, SOME(Env.forScopeName));
env_2 = Env.extendFrameForIterator(env_1, i, (DAE.T_INTEGER({}), NONE), DAE.VALBOUND(fst), SCode.CONST());
/* Use instEInitialequation*/
(cache,env_3,_,dae1,csets_1,ci_state_1,graph) = instList(cache,env_2,InstanceHierarchy.emptyInstHierarchy, mods, pre, csets, ci_state, instEInitialequation, eqs, impl,graph);
(cache,dae2,csets_2,graph) = unroll(cache,env, mods, pre, csets_1, ci_state_1, i, Values.ARRAY(rest), eqs, initial_, impl,graph);
(cache,dae2,csets_2,graph) = unroll(cache,env, mods, pre, csets_1, ci_state_1, i, Values.ARRAY(rest,dims), eqs, initial_, impl,graph);
dae = DAEUtil.joinDaes(dae1, dae2);
then
(cache,dae,csets_2,graph);
case (_,_,_,_,_,_,_,v,_,_,_,_)
equation
true = RTOpts.debugFlag("failtrace");
Debug.fprint("failtrace", "- Inst.unroll ");
Debug.fcall("failtrace", ValuesUtil.printVal, v);
Debug.fprint("failtrace", " failed\n");
Debug.fprintln("failtrace", "- Inst.unroll failed: " +& ValuesUtil.valString(v));
then
fail();
end matchcontinue;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Interactive.mo
Expand Up @@ -576,7 +576,7 @@ algorithm
local
input list<Values.Value> valList;
equation
(Values.ARRAY(valList),st_1) = evaluateExpr(exp, st);
(Values.ARRAY(valueLst = valList),st_1) = evaluateExpr(exp, st);
st_2 = evaluateForStmt(iter, valList, algItemList, st_1);
then
("",st_2);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Mod.mo
Expand Up @@ -1319,7 +1319,7 @@ algorithm
case (NONE,_) then NONE;
case (e,{}) then e;
/* Subscripting empty array gives no value. This is needed in e.g. fill(1.0,0,2) */
case (SOME(DAE.TYPED(_,SOME(Values.ARRAY({})),_)),xs) then NONE;
case (SOME(DAE.TYPED(_,SOME(Values.ARRAY(valueLst = {})),_)),xs) then NONE;

/* For modifiers with value, retrieve nth element*/
case (SOME(DAE.TYPED(e,SOME(e_val),DAE.PROP(t,c))),(x :: xs))
Expand Down

0 comments on commit a0776c5

Please sign in to comment.