@@ -3085,7 +3085,7 @@ algorithm
30853085end elabBuiltinProduct2;
30863086
30873087protected function elabBuiltinPre "function: elabBuiltinPre
3088-
3088+
30893089 This function elaborates the builtin operator pre.
30903090 Input is the arguments to the pre operator and the environment, Env.Env.
30913091"
@@ -3097,7 +3097,7 @@ protected function elabBuiltinPre "function: elabBuiltinPre
30973097 output Env.Cache outCache;
30983098 output Exp.Exp outExp;
30993099 output Types.Properties outProperties;
3100- algorithm
3100+ algorithm
31013101 (outCache,outExp,outProperties):=
31023102 matchcontinue (inCache,inEnv,inAbsynExpLst,inNamedArg,inBoolean)
31033103 local
@@ -3111,47 +3111,69 @@ algorithm
31113111 Ident s,el_str;
31123112 list< Absyn.Exp> expl;
31133113 Env.Cache cache;
3114- case (cache,env,{exp },_,impl) /* impl */
3115- local Exp.Type t; String str;
3116- equation
3117- (cache,exp_1,Types.PROP(tp,c),_) = elabExp(cache,env, exp , impl, NONE,true );
3118- true = Types.basicType(tp);
3119- t = Types.elabType(tp);
3120- exp_2 = Exp.CALL(Absyn.IDENT("pre" ),{exp_1},false ,true ,t);
3114+
3115+ /* an matrix? */
3116+ case (cache,env,{exp },_,impl) /* impl */
3117+ local
3118+ Types.Type t,t2;
3119+ Exp.Type etp,etp_org;
3120+ list< Exp.Exp> expl_1;
3121+ Boolean sc;
3122+ equation
3123+ (cache,exp_1 as Exp.MATRIX(_, _, _),Types.PROP(t as (Types.T_ARRAY(dim,tp),_),c),_) = elabExp(cache, env, exp , impl, NONE, true );
3124+
3125+ true = Types.isArray(t);
3126+
3127+ t2 = Types.unliftArray(t);
3128+ etp = Types.elabType(t2);
3129+
3130+ exp_2 = elabBuiltinPreMatrix(Exp.CALL(Absyn.IDENT("pre" ),{exp_1},false ,true ,etp),t2);
31213131 then
3122- (cache,exp_2,Types.PROP(tp,c));
3123- case (cache,env,{exp },_,impl) /* impl */
3124- local
3125- Types.Type t,t2;
3126- Exp.Type etp,etp_org;
3132+ (cache,exp_2,Types.PROP(t,c));
3133+
3134+ /* an array? */
3135+ case (cache,env,{exp },_,impl) /* impl */
3136+ local
3137+ Types.Type t,t2;
3138+ Exp.Type etp,etp_org;
31273139 list< Exp.Exp> expl_1;
31283140 Boolean sc;
3129- equation
3141+ equation
31303142 (cache,exp_1,Types.PROP(t as (Types.T_ARRAY(dim,tp),_),c),_) = elabExp(cache, env, exp , impl, NONE,true );
31313143
31323144 true = Types.isArray(t);
3133-
3145+
31343146 t2 = Types.unliftArray(t);
31353147 etp = Types.elabType(t2);
3136-
3148+
31373149 (expl_1,sc) = elabBuiltinPre2(Exp.CALL(Absyn.IDENT("pre" ),{exp_1},false ,true ,etp),t2);
3138-
3150+
31393151 etp_org = Types.elabType(t);
31403152 exp_2 = Exp.ARRAY(etp_org, sc, expl_1);
3141-
31423153 then
31433154 (cache,exp_2,Types.PROP(t,c));
3155+
3156+ /* a scalar? */
3157+ case (cache,env,{exp },_,impl) /* impl */
3158+ local Exp.Type t; String str;
3159+ equation
3160+ (cache,exp_1,Types.PROP(tp,c),_) = elabExp(cache,env, exp , impl, NONE,true );
3161+ true = Types.basicType(tp);
3162+ t = Types.elabType(tp);
3163+ exp_2 = Exp.CALL(Absyn.IDENT("pre" ),{exp_1},false ,true ,t);
3164+ then
3165+ (cache,exp_2,Types.PROP(tp,c));
31443166 case (cache,env,{exp },_,impl)
31453167 local Exp.Exp exp ;
3146- equation
3168+ equation
31473169 (cache,exp ,Types.PROP(tp,c),_) = elabExp(cache,env, exp , impl, NONE,true );
31483170 false = Types.basicType(tp);
31493171 s = Exp.printExpStr(exp );
31503172 Error.addMessage(Error.OPERAND_BUILTIN_TYPE, {"pre" ,s});
31513173 then
31523174 fail();
31533175 case (cache,env,expl,_,_)
3154- equation
3176+ equation
31553177 el_str = Exp.printListStr(expl, Dump.printExpStr, ", " );
31563178 s = Util.stringAppendList({"pre(" ,el_str,")" });
31573179 Error.addMessage(Error.WRONG_TYPE_OR_NO_OF_ARGS, {s});
@@ -3169,57 +3191,133 @@ output list<Exp.Exp> outExp;
31693191output Boolean sc;
31703192algorithm
31713193 (outExp) := matchcontinue(inExp,t)
3172- local
3194+ local
31733195 Exp.Type ty;
31743196 Boolean sc;
3197+ Integer i;
31753198 list< Exp.Exp> expl,e;
31763199 Exp.Exp exp_1;
3177- case(Exp.CALL(_,{Exp.ARRAY(ty,sc,expl)},_,_,_),t)
3200+ list< list< tuple< Exp.Exp, Boolean >>> matrixExpl, matrixExplPre;
3201+ list< Boolean > boolList;
3202+
3203+ case(Exp.CALL(_,{Exp.ARRAY(ty,sc,expl)},_,_,_),t)
31783204 equation
3179- (e) = makePreLst(expl, t);
3180- then (e,sc);
3181- case (exp_1,t)
3205+ (e) = makePreLst(expl, t);
3206+ then (e,sc);
3207+ case(Exp.CALL(_,{Exp.MATRIX(ty,i,matrixExpl)},_,_,_),t)
3208+ equation
3209+ matrixExplPre = makePreMatrix(matrixExpl, t);
3210+ then ({Exp.MATRIX(ty,i,matrixExplPre)},false );
3211+ case (exp_1,t)
31823212 equation
3183- then
3213+ then
31843214 (exp_1 :: {},false );
3185-
3215+
31863216 end matchcontinue;
31873217end elabBuiltinPre2;
31883218
3189- protected function makePreLst "function: makePreLst
3190-
3191- Takes a list of expressions and makes a list of pre - expressions
3192- "
3219+ protected function makePreLst
3220+ "function: makePreLst
3221+ Takes a list of expressions and makes a list of pre - expressions"
31933222 input list< Exp.Exp> inExpLst;
31943223 input Types.Type t;
31953224 output list< Exp.Exp> outExp;
3196- algorithm
3225+ algorithm
31973226 (outExp):=
31983227 matchcontinue (inExpLst,t)
31993228 local
32003229 Exp.Exp exp_1;
32013230 list< Exp.Exp> expl_1;
3202- case((exp_1 :: expl_1),t)
3203- local
3231+
3232+ case((exp_1 :: expl_1),t)
3233+ local
32043234 Exp.Exp exp_2;
32053235 list< Exp.Exp> expl_2;
32063236 Exp.Type ttt;
32073237 Types.Type ttY;
32083238 equation
32093239 ttt = Types.elabType(t);
3210- exp_2 = Exp.CALL(Absyn.IDENT("pre" ),{exp_1},false ,true ,ttt);
3240+ exp_2 = Exp.CALL(Absyn.IDENT("pre" ),{exp_1},false ,true ,ttt);
32113241 (expl_2) = makePreLst(expl_1,t);
32123242 then
3213- ((exp_2 :: expl_2));
3243+ ((exp_2 :: expl_2));
32143244
32153245 case ({},t)
32163246 equation
3217- then
3218- ( {});
3247+ then
3248+ ({});
3249+ end matchcontinue;
3250+ end makePreLst;
3251+
3252+ protected function elabBuiltinPreMatrix
3253+ "function: elabBuiltinPreMatrix
3254+ Help function for elabBuiltinPreMatrix, when type is matrix, send it here."
3255+ input Exp.Exp inExp;
3256+ input Types.Type t;
3257+ output Exp.Exp outExp;
3258+ algorithm
3259+ (outExp) := matchcontinue(inExp,t)
3260+ local
3261+ Exp.Type ty;
3262+ Boolean sc;
3263+ Integer i;
3264+ list< Exp.Exp> expl,e;
3265+ Exp.Exp exp_1;
3266+ list< list< tuple< Exp.Exp, Boolean >>> matrixExpl, matrixExplPre;
3267+ list< Boolean > boolList;
3268+
3269+ case(Exp.CALL(_,{Exp.MATRIX(ty,i,matrixExpl)},_,_,_),t)
3270+ equation
3271+ matrixExplPre = makePreMatrix(matrixExpl, t);
3272+ then Exp.MATRIX(ty,i,matrixExplPre);
32193273
3274+ case (exp_1,t) then exp_1;
3275+ end matchcontinue;
3276+ end elabBuiltinPreMatrix;
3277+
3278+ protected function makePreMatrix
3279+ "function: makePreMatrix
3280+ Takes a list of matrix expressions and makes a list of pre - matrix expressions"
3281+ input list< list< tuple< Exp.Exp, Boolean >>> inMatrixExp;
3282+ input Types.Type t;
3283+ output list< list< tuple< Exp.Exp, Boolean >>> outMatrixExp;
3284+ algorithm
3285+ (outMatrixExp) := matchcontinue (inMatrixExp,t)
3286+ local
3287+ list< list< tuple< Exp.Exp, Boolean >>> lstLstExp, lstLstExpRest;
3288+ list< tuple< Exp.Exp, Boolean >> lstExpBool, lstExpBoolPre;
32203289
3290+ case ({},t) then {};
3291+ case(lstExpBool::lstLstExpRest,t)
3292+ equation
3293+ lstExpBoolPre = mkLstPre(lstExpBool, t);
3294+ lstLstExp = makePreMatrix(lstLstExpRest, t);
3295+ then
3296+ lstExpBoolPre ::lstLstExp;
32213297 end matchcontinue;
3222- end makePreLst;
3298+ end makePreMatrix;
3299+
3300+ function mkLstPre
3301+ input list< tuple< Exp.Exp, Boolean >> inLst;
3302+ input Types.Type t;
3303+ output list< tuple< Exp.Exp, Boolean >> outLst;
3304+ algorithm
3305+ outLst := matchcontinue(inLst, t)
3306+ local
3307+ Exp.Exp exp ; Boolean b;
3308+ Exp.Exp expPre;
3309+ Exp.Type ttt;
3310+ list< tuple< Exp.Exp, Boolean >> rest;
3311+ case ({}, t) then {};
3312+ case ((exp ,b)::rest, t)
3313+ equation
3314+ ttt = Types.elabType(t);
3315+ exp = Exp.CALL(Absyn.IDENT("pre" ),{exp },false ,true ,ttt);
3316+ rest = mkLstPre(rest,t);
3317+ then
3318+ (exp , b)::rest;
3319+ end matchcontinue;
3320+ end mkLstPre;
32233321
32243322protected function elabBuiltinInitial "function: elabBuiltinInitial
32253323
@@ -4350,10 +4448,9 @@ algorithm
43504448 end matchcontinue;
43514449end elabBuiltinSign;
43524450
4353- protected function elabBuiltinDer "function: elabBuiltinDer
4354-
4355- This function handles the built in der operator.
4356- "
4451+ protected function
4452+ "function: elabBuiltinDer
4453+ This function handles the built in der operator."
43574454 input Env.Cache inCache;
43584455 input Env.Env inEnv;
43594456 input list< Absyn.Exp> inAbsynExpLst;
0 commit comments