Skip to content

Commit

Permalink
Merging
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Oct 20, 2010
2 parents 3933c27 + 1021c80 commit 1ecb588
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 133 deletions.
9 changes: 0 additions & 9 deletions Compiler/Ceval.mo
Expand Up @@ -1193,15 +1193,6 @@ algorithm
case "listStringCharString" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListStringCharString;
case "listLength" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListLength;
case "listAppend" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalListAppend;
// Box/Unbox
case "mmc_mk_bcon" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
case "mmc_mk_icon" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
case "mmc_mk_rcon" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
case "mmc_mk_scon" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
case "mmc_unbox_integer" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
case "mmc_unbox_real" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;
case "mmc_unbox_string" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalNoBoxUnbox;

//case "semiLinear" then cevalBuiltinSemiLinear;
//case "delay" then cevalBuiltinDelay;
case id
Expand Down
8 changes: 8 additions & 0 deletions Compiler/DAE.mo
Expand Up @@ -1168,6 +1168,14 @@ uniontype Exp "Expressions
Integer index; //Index in the uniontype
end METARECORDCALL;

record BOX
Exp exp;
end BOX;

record UNBOX
Exp exp;
end UNBOX;

/* --- */

end Exp;
Expand Down
5 changes: 3 additions & 2 deletions Compiler/Error.mo
Expand Up @@ -630,6 +630,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl

protected import ErrorExt;
protected import Print;
protected import RTOpts;
protected import System;

public function updateCurrentComponent "Function: updateCurrentComponent
Expand Down Expand Up @@ -996,8 +997,8 @@ algorithm
outFilename := matchcontinue filename
case filename
equation
filename = System.stringFindString(filename, "/testsuite/");
then filename;
true = RTOpts.getRunningTestsuite();
then System.basename(filename);
case filename then filename;
end matchcontinue;
end fixFilenameForTestsuite;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Inst.mo
Expand Up @@ -3713,6 +3713,7 @@ algorithm
false = Util.getStatefulBoolean(stopInst);
true = Mod.emptyModOrEquality(mods) and SCode.emptyModOrEquality(mod);
(cache,cenv,ih,tys,csets,oDA) = instClassDefHelper(cache,env,ih,tSpecs,pre,inst_dims,impl,{},csets);
tys = Util.listMap(tys, Types.boxIfUnboxedType);
bc = SOME((DAE.T_METATUPLE(tys),NONE));
oDA = Absyn.mergeElementAttributes(DA,oDA);
then (cache,env,ih,store,DAEUtil.emptyDae,csets,ClassInf.META_TUPLE(Absyn.IDENT("")),{},bc,oDA,NONE,graph);
Expand All @@ -3727,8 +3728,7 @@ algorithm
true = RTOpts.acceptMetaModelicaGrammar();
false = Util.getStatefulBoolean(stopInst);
true = Mod.emptyModOrEquality(mods) and SCode.emptyModOrEquality(mod);
(cache,cenv,ih,tys,csets,oDA) = instClassDefHelper(cache,env,ih,tSpecs,pre,inst_dims,impl,{},csets);
{ty} = tys;
(cache,cenv,ih,{ty},csets,oDA) = instClassDefHelper(cache,env,ih,tSpecs,pre,inst_dims,impl,{},csets);
bc = SOME((DAE.T_META_ARRAY(ty),NONE));
oDA = Absyn.mergeElementAttributes(DA,oDA);
then (cache,env,ih,store,DAEUtil.emptyDae,csets,ClassInf.META_ARRAY(Absyn.IDENT(className)),{},bc,oDA,NONE,graph);
Expand Down
90 changes: 0 additions & 90 deletions Compiler/MetaUtil.mo
Expand Up @@ -91,96 +91,6 @@ algorithm
end matchcontinue;
end simplifyListExp;

public function listToConsCell "function: listToConsCell
Author: KS
In the C-code, a list constructor will consist of
several cons constructor. For instance:
list(1,2,3,4) will be written as
mk_cons(1,mk_cons(2,mk_cons(3,mk_cons(4,mk_nil())))),
(the constants 1,2,3,4 each will be wrapped with a create-constant
function call)
"
input list<String> varList;
input list<DAE.Exp> expList;
output String outString;
algorithm
outString :=
matchcontinue (varList,expList)
case ({},_)
local
String s;
equation
s = "mmc_mk_nil()";
then s;
case (firstVar :: restVar,firstExp :: restExp)
local
String firstVar,s,s2;
list<String> restVar;
list<DAE.Exp> restExp;
DAE.Exp firstExp;
equation
firstVar = createConstantCExp(firstExp,firstVar);
s2 = listToConsCell(restVar,restExp);
s = System.stringAppendList({"mmc_mk_cons(",firstVar,",",s2,")"});
then s;
end matchcontinue;
end listToConsCell;

public function createConstantCExp "function: createConstantCExp2"
input DAE.Exp exp;
input String inExp;
output String s;
DAE.ExpType expType;
algorithm
expType := Exp.typeof(exp);
s := createConstantCExp2(expType, inExp);
end createConstantCExp;

protected function createConstantCExp2 "function: createConstantCExp2"
input DAE.ExpType exp;
input String inExp;
output String s;
algorithm
s :=
matchcontinue(exp,inExp)
local
String localInExp,outStr;
case (DAE.ET_INT(),localInExp)
equation
outStr = System.stringAppendList({"mmc_mk_icon(",localInExp,")"});
then outStr;
case (DAE.ET_REAL(),localInExp)
equation
outStr = System.stringAppendList({"mmc_mk_rcon(",localInExp,")"});
then outStr;
case (DAE.ET_BOOL(),localInExp)
equation
outStr = System.stringAppendList({"mmc_mk_icon(",localInExp,")"});
then outStr;
case (DAE.ET_STRING(),localInExp)
equation
outStr = System.stringAppendList({"mmc_mk_scon(",localInExp,")"});
then outStr;
case (DAE.ET_COMPLEX(name = path, varLst = varLst),localInExp)
local
list<DAE.ExpVar> varLst;
list<String> vars, vars1;
list<DAE.ExpType> types;
String str,name;
Absyn.Path path;
equation
vars = Util.listMap(varLst, Exp.varName);
str = stringAppend(localInExp,".");
vars1 = Util.listMap1r(vars, stringAppend, str);
types = Util.listMap(varLst, Exp.varType);
outStr = listToBoxes(vars1,types,-1,Absyn.pathString(path));
then outStr;

case (_,localInExp) then localInExp;

end matchcontinue;
end createConstantCExp2;

public function fixListConstructorsInArgs "function: fixListConstructorsInArgs
Author: KS
In a function call, an Absyn.ARRAY() will be transformed into an Absyn.LIST()
Expand Down
9 changes: 9 additions & 0 deletions Compiler/System.mo
Expand Up @@ -840,5 +840,14 @@ creates the Globally Unique IDentifier and return it as String
external "C";
end getUUIDStr;

public function basename
"Returns the name of the file without any leading directory path.
See man 3 basename."
input String filename;
output String base;
// We need to strdup the input, so we can't use basename() directly
external "C" base = System_basename(filename);
end basename;

end System;

38 changes: 11 additions & 27 deletions Compiler/Types.mo
Expand Up @@ -4097,28 +4097,28 @@ algorithm
(e,t1) = matchType(e,t1,unboxedType(t2),printFailtrace);
t2 = (DAE.T_BOXED(t1),NONE);
t = elabType(t2);
then (DAE.CALL(Absyn.IDENT("mmc_mk_icon"),{e},false,true,t,DAE.NO_INLINE),t2);
then (DAE.BOX(e),t2);

case (e, t1 as (DAE.T_BOOL(_),_), (DAE.T_BOXED(t2),_),printFailtrace)
equation
(e,t1) = matchType(e,t1,unboxedType(t2),printFailtrace);
t2 = (DAE.T_BOXED(t1),NONE);
t = elabType(t2);
then (DAE.CALL(Absyn.IDENT("mmc_mk_bcon"),{e},false,true,t,DAE.NO_INLINE),t2);
then (DAE.BOX(e),t2);

case (e, t1 as (DAE.T_REAL(_),_), (DAE.T_BOXED(t2),_),printFailtrace)
equation
(e,t1) = matchType(e,t1,unboxedType(t2),printFailtrace);
t2 = (DAE.T_BOXED(t1),NONE);
t = elabType(t2);
then (DAE.CALL(Absyn.IDENT("mmc_mk_rcon"),{e},false,true,t,DAE.NO_INLINE),t2);
then (DAE.BOX(e),t2);

case (e, t1 as (DAE.T_STRING(_),_), (DAE.T_BOXED(t2),_),printFailtrace)
equation
(e,t1) = matchType(e,t1,unboxedType(t2),printFailtrace);
t2 = (DAE.T_BOXED(t1),NONE);
t = elabType(t2);
then (DAE.CALL(Absyn.IDENT("mmc_mk_scon"),{e},false,true,t,DAE.NO_INLINE),t2);
then (DAE.BOX(e),t2);

case (e as DAE.CALL(path = path1, expLst = elist), t1 as (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(_), complexVarLst = v),SOME(path2)), (DAE.T_BOXED(t2),_),printFailtrace)
local Absyn.Path path1,path2;
Expand Down Expand Up @@ -4160,37 +4160,21 @@ algorithm
e_1 = DAE.METARECORDCALL(path, elist, l, -1);
then (e_1,t2);

case (e,(DAE.T_BOXED(t1),_),t2 as (DAE.T_INTEGER(_),_),printFailtrace)
case (DAE.BOXED(e),(DAE.T_BOXED(t1),_),t2,printFailtrace)
equation
true = subtype(t1,t2);
(e_1,_) = matchType(e,t1,t2,printFailtrace);
then
(DAE.CALL(Absyn.IDENT("mmc_unbox_integer"),{e_1},false,true,DAE.ET_INT,DAE.NO_INLINE),t2);
case (e,(DAE.T_BOXED(t1),_),t2 as (DAE.T_REAL(_),_),printFailtrace)
equation
true = subtype(t1,t2);
(e_1,_) = matchType(e,t1,t2,printFailtrace);
then
(DAE.CALL(Absyn.IDENT("mmc_unbox_real"),{e_1},false,true,DAE.ET_REAL,DAE.NO_INLINE),t2);
case (e,(DAE.T_BOXED(t1),_),t2 as (DAE.T_BOOL(_),_),printFailtrace)
equation
true = subtype(t1,t2);
(e_1,_) = matchType(e,t1,t2,printFailtrace);
then
(DAE.CALL(Absyn.IDENT("mmc_unbox_integer"),{e_1},false,true,DAE.ET_BOOL,DAE.NO_INLINE),t2);
case (e,(DAE.T_BOXED(t1),_),t2 as (DAE.T_STRING(_),_),printFailtrace)
equation
true = subtype(t1,t2);
(e_1,_) = matchType(e,t1,t2,printFailtrace);
then
(DAE.CALL(Absyn.IDENT("mmc_unbox_string"),{e_1},false,true,DAE.ET_STRING,DAE.NO_INLINE),t2);
t1 = unboxedType(t1);
(e,t1) = matchType(e,t1,t2,printFailtrace);
then (e,(DAE.T_BOXED(t1),NONE()));

/*
case (e,(DAE.T_BOXED(t1),_),t2 as (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(_), complexVarLst = v),_),printFailtrace)
equation
true = subtype(t1,t2);
(e_1,t2) = matchType(e,t1,t2,printFailtrace);
t = elabType(t2);
then
(DAE.CALL(Absyn.IDENT("mmc_unbox_record"),{e_1},false,true,t,DAE.NO_INLINE),t2);
*/

/* See printFailure()
case (exp,t1,t2,printFailtrace)
Expand Down
6 changes: 3 additions & 3 deletions Compiler/runtime/Error_rml.cpp
Expand Up @@ -209,14 +209,14 @@ RML_END_LABEL

RML_BEGIN_LABEL(ErrorExt__getMessagesStr)
{
std::string res("{");
std::string res("}");
while(!errorMessageQueue.empty()) {
res = errorMessageQueue.top()->getFullMessage() + res;
delete errorMessageQueue.top();
errorMessageQueue.pop();
if (!errorMessageQueue.empty()) { res = res + string(","); }
if (!errorMessageQueue.empty()) { res = string(",") + res; }
}
res = res + string("}");
res = string("{") + res;
rmlA0 = mk_scon((char*)res.c_str());
RML_TAILCALLK(rmlSC);
}
Expand Down
11 changes: 11 additions & 0 deletions Compiler/runtime/System_rml.c
Expand Up @@ -375,6 +375,17 @@ RML_BEGIN_LABEL(System__strcmp)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__basename)
{
const char *str = RML_STRINGDATA(rmlA0);
char *copy = strdup(str);
char *res = basename(copy); /* basename may modify the contents */
rmlA0 = (void*) mk_scon(res);
free(copy);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__stringFind)
{
char *str = RML_STRINGDATA(rmlA0);
Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -31,6 +31,7 @@
/*
* Common includes
*/
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down

0 comments on commit 1ecb588

Please sign in to comment.