Skip to content

Commit

Permalink
- Don't disable ceval of builtin functions when +d=rml is activated
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7701 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 15, 2011
1 parent 1229bcb commit e5c0caa
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Ceval.mo
Expand Up @@ -1105,8 +1105,8 @@ algorithm
case "listLength" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListLength;
case "listAppend" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListAppend;
case "listReverse" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListReverse;
case "listHead" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListFirst;
case "listRest" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListRest;
case "listFirst" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListFirst;

//case "semiLinear" then cevalBuiltinSemiLinear;
//case "delay" then cevalBuiltinDelay;
Expand Down Expand Up @@ -2930,7 +2930,7 @@ algorithm
equation
(cache,Values.LIST(v::_),st) = ceval(cache,env, exp1, impl, st,NONE(), msg);
then
(cache,v,st);
(cache,Values.META_BOX(v),st);
end match;
end cevalListFirst;

Expand Down
40 changes: 39 additions & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -328,10 +328,13 @@ algorithm
outExp := matchcontinue exp
local
DAE.Exp e,e1,e2,e1_1,e2_1;
Boolean b1,b2;
Boolean b,b1,b2;
DAE.ExpType tp;
Absyn.Path path;
list<DAE.Exp> el;
Integer i;
Real r;
String s;
case DAE.MATCHEXPRESSION(inputs={e}, localDecls={}, cases={
DAE.CASE(patterns={DAE.PAT_CONSTANT(exp=DAE.BCONST(b1))},localDecls={},body={},result=SOME(e1)),
DAE.CASE(patterns={DAE.PAT_CONSTANT(exp=DAE.BCONST(b2))},localDecls={},body={},result=SOME(e2))
Expand Down Expand Up @@ -366,6 +369,24 @@ algorithm
DAE.LIST(valList={}) = simplify(e2);
then simplify(e1);

case DAE.CALL(path=path as Absyn.IDENT("intString"),expLst={e1},ty=tp)
equation
DAE.ICONST(i) = simplify(e1);
s = intString(i);
then DAE.SCONST(s);

case DAE.CALL(path=path as Absyn.IDENT("realString"),expLst={e1},ty=tp)
equation
DAE.RCONST(r) = simplify(e1);
s = realString(r);
then DAE.SCONST(s);

case DAE.CALL(path=path as Absyn.IDENT("boolString"),expLst={e1},ty=tp)
equation
DAE.BCONST(b) = simplify(e1);
s = boolString(b);
then DAE.SCONST(s);

case DAE.CALL(path=path as Absyn.IDENT("listReverse"),expLst={e1},ty=tp)
equation
DAE.LIST(el) = simplify(e1);
Expand All @@ -374,6 +395,12 @@ algorithm
e1_1 = DAE.LIST(el);
then e1_1;

case DAE.CALL(path=path as Absyn.IDENT("listLength"),expLst={e1},ty=tp)
equation
DAE.LIST(el) = simplify(e1);
i = listLength(el);
then DAE.ICONST(i);

case DAE.LIST(el)
equation
el = Util.listMap(el,simplify);
Expand All @@ -384,6 +411,17 @@ algorithm
DAE.LIST(el) = simplify(e2);
e1_1 = simplify(e1);
then DAE.LIST(e1_1::el);

case DAE.CONS(e1,e2)
equation
e1_1 = simplify(e1);
e2_1 = simplify(e2);
then DAE.CONS(e1_1,e2_1);

case DAE.UNBOX(exp=e1)
equation
DAE.BOX(e1_1) = simplify(e1);
then e1_1;
end matchcontinue;
end simplifyMetaModelica;

Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/MetaModelicaBuiltin.mo
Expand Up @@ -648,6 +648,7 @@ function debug_print
input String str;
input TypeA a;
replaceable type TypeA subtypeof Any;
annotation(__OpenModelica_Impure = true);
external "builtin";
end debug_print;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Static.mo
Expand Up @@ -8330,7 +8330,7 @@ algorithm
(isBuiltin,fn_1) = isBuiltinFunc(fn_1,functype);
builtin = valueEq(DAE.FUNCTION_BUILTIN(),isBuiltin);
const = Util.listFold(constlist, Types.constAnd, DAE.C_CONST());
const = Util.if_(RTOpts.debugFlag("rml") or (not isPure), DAE.C_VAR(), const) "in RML no function needs to be ceval'ed; this speeds up compilation significantly when bootstrapping";
const = Util.if_((RTOpts.debugFlag("rml") and not builtin) or (not isPure), DAE.C_VAR(), const) "in RML no function needs to be ceval'ed; this speeds up compilation significantly when bootstrapping";
(cache,const) = determineConstSpecialFunc(cache,env,const,fn);
tyconst = elabConsts(restype, const);
prop = getProperties(restype, tyconst);
Expand Down
4 changes: 4 additions & 0 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1300,6 +1300,10 @@ algorithm
ts = Util.listMap(ts, boxIfUnboxedType);
then
((DAE.T_METATUPLE(ts),NONE()));
case Values.META_BOX(v)
equation
tp = typeOfValue(v);
then boxIfUnboxedType(tp);
case (v)
equation
str = "- Types.typeOfValue failed: " +& ValuesUtil.valString(v);
Expand Down
4 changes: 4 additions & 0 deletions Compiler/FrontEnd/Values.mo
Expand Up @@ -108,6 +108,10 @@ uniontype Value
record NORETCALL
end NORETCALL;

record META_BOX
Value value;
end META_BOX;

record META_FAIL
"If the result of constant evaluation of a MetaModelica function call is fail(),
we need to propagate this value in order to avoid running the code over and over again.
Expand Down
15 changes: 14 additions & 1 deletion Compiler/FrontEnd/ValuesUtil.mo
Expand Up @@ -1013,7 +1013,12 @@ algorithm
then DAE.METARECORDCALL(path,explist,namelst,ix);

case (Values.META_FAIL())
then DAE.CALL(Absyn.IDENT("fail"),{},false,false,DAE.ET_OTHER(),DAE.NO_INLINE());
then DAE.CALL(Absyn.IDENT("fail"),{},false,true,DAE.ET_OTHER(),DAE.NO_INLINE());

case (Values.META_BOX(v))
equation
e = valueExp(v);
then DAE.BOX(e);

case (v)
equation
Expand Down Expand Up @@ -1996,6 +2001,14 @@ algorithm
then
();

case ((Values.META_BOX(r)))
equation
Print.printBuf("#(");
valString2(r);
Print.printBuf(")");
then
();

case (Values.CODE(A = c))
equation
Print.printBuf("Code(");
Expand Down
19 changes: 17 additions & 2 deletions Compiler/OpenModelicaBootstrappingHeader.h
Expand Up @@ -214,6 +214,21 @@ extern struct record_description Values_Value_NORETCALL__desc;
static const MMC_DEFSTRUCTLIT(Values__NORETCALL__struct,1,16) {&Values_Value_NORETCALL__desc}};
static void *Values__NORETCALL = MMC_REFSTRUCTLIT(Values__NORETCALL__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef Values_Value_META__BOX__desc_added
#define Values_Value_META__BOX__desc_added
const char* Values_Value_META__BOX__desc__fields[1] = {"value"};
struct record_description Values_Value_META__BOX__desc = {
"Values_Value_META__BOX",
"Values.Value.META_BOX",
Values_Value_META__BOX__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description Values_Value_META__BOX__desc;
#endif
#define Values__META_5fBOX_3dBOX1 17
#define Values__META_5fBOX(value) (mmc_mk_box2(17,&Values_Value_META__BOX__desc,value))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef Values_Value_META__FAIL__desc_added
#define Values_Value_META__FAIL__desc_added
const char* Values_Value_META__FAIL__desc__fields[0] = {};
Expand All @@ -226,8 +241,8 @@ struct record_description Values_Value_META__FAIL__desc = {
#else /* Only use the file as a header */
extern struct record_description Values_Value_META__FAIL__desc;
#endif
#define Values__META_5fFAIL_3dBOX0 17
static const MMC_DEFSTRUCTLIT(Values__META_5fFAIL__struct,1,17) {&Values_Value_META__FAIL__desc}};
#define Values__META_5fFAIL_3dBOX0 18
static const MMC_DEFSTRUCTLIT(Values__META_5fFAIL__struct,1,18) {&Values_Value_META__FAIL__desc}};
static void *Values__META_5fFAIL = MMC_REFSTRUCTLIT(Values__META_5fFAIL__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef Values_IntRealOp_MULOP__desc_added
Expand Down

0 comments on commit e5c0caa

Please sign in to comment.