Skip to content

Commit

Permalink
Fixes for #1318
Browse files Browse the repository at this point in the history
- Added some more runtime functions for bootstrapping
- Added testcase SusanTest.mos; still incomplete but part of it is working


git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6424 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 19, 2010
1 parent fd3e0bb commit 23e78c4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 41 deletions.
1 change: 1 addition & 0 deletions Compiler/Static.mo
Expand Up @@ -8788,6 +8788,7 @@ algorithm
tuple_ = isTuple(restype);
(cache,builtin,fn_1) = isBuiltinFunc(cache,fn_1,pre);
const = Util.listFold(constlist, Types.constAnd, DAE.C_CONST());
const = Util.if_(RTOpts.debugFlag("rml"), 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
8 changes: 4 additions & 4 deletions Compiler/System.mo
Expand Up @@ -83,7 +83,7 @@ public function stringFind "locates substring searchStr in str. If succeeds retu
input String searchStr;
output Integer outInteger;

external "C" ;
external "C" outInteger=System__stringFind(str,searchStr);
end stringFind;

public function stringFindString "locates substring searchStr in str. If succeeds return the string, otherwise fail"
Expand All @@ -110,7 +110,7 @@ public function stringReplace
input String target;
output String res;

external "C" ;
external "C" res=System__stringReplace(str,source,target);
end stringReplace;

public function toupper
Expand Down Expand Up @@ -293,7 +293,7 @@ public function readFile
input String inString;
output String outString;

external "C" outString = SystemImpl__readFile(inString);
external "C" outString = System__readFile(inString);
end readFile;

public function getVariableNames
Expand Down Expand Up @@ -384,7 +384,7 @@ public function regularFileExists
input String inString;
output Boolean outBool;

external "C" outBool = SystemImpl__regularFileExists(inString);
external "C" outBool = System__regularFileExists(inString);
end regularFileExists;

public function removeFile "Removes a file, returns 0 if suceeds, implemented using remove() in stdio.h"
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/Makefile.in
Expand Up @@ -36,7 +36,7 @@ SRC = rtopts.c socketimpl.c Print_rml.c System_rml.c settingsimpl.c dynload.c Si

CPPSRC = unitparser.cpp unitparserext.cpp ptolemyio.cpp daeext.cpp ErrorMessage.cpp Error_rml.cpp optmanager.cpp systemimplmisc.cpp dynload_try.o $(CORBASRC)
OBJ = $(SRC:.c=.o) $(CPPSRC:.cpp=.o) $(CPPSRC:.cc=.o)
OMC_OBJ = Error_omc.o Print_omc.o RTOpts_omc.o System_omc.o ErrorMessage.o
OMC_OBJ = Error_omc.o Print_omc.o RTOpts_omc.o System_omc.o ErrorMessage.o systemimplmisc.o

all: runtime.a install
.PHONY: all install
Expand Down
21 changes: 16 additions & 5 deletions Compiler/runtime/System_omc.cpp
Expand Up @@ -35,22 +35,33 @@ extern "C" {
extern int System__regularFileExists(const char* str)
{
fprintf(stderr, "NYI: %s\n", __FUNCTION__);
//return SystemImpl__regularFileExists(str);
throw 1;
return SystemImpl__regularFileExists(str);
}

extern void writeFile(const char* filename, const char* data)
{
fprintf(stderr, "NYI: %s\n", __FUNCTION__);
//if (SystemImpl__writeFile(filename, data))
if (SystemImpl__writeFile(filename, data))
throw 1;
}

extern char* System__readFile(const char* filename)
{
fprintf(stderr, "NYI: %s\n", __FUNCTION__);
//return SystemImpl__readFile(filename);
throw 1;
return SystemImpl__readFile(filename);
}

extern const char* System__stringReplace(const char* str, const char* source, const char* target)
{
char* res = _replace(str,source,target);
if (res == NULL)
throw 1;
return res;
}

extern int System__stringFind(const char* str, const char* searchStr)
{
return SystemImpl__stringFind(str, searchStr);
}

}
30 changes: 3 additions & 27 deletions Compiler/runtime/System_rml.c
Expand Up @@ -40,11 +40,6 @@
#include <shlwapi.h>
#endif

#include "rtclock.h"
#include "systemimpl.h"
#include "config.h"
#include "rtopts.h"

#include "systemimpl.c"

#include "rml.h"
Expand Down Expand Up @@ -481,29 +476,10 @@ RML_BEGIN_LABEL(System__stringReplace)
char *str = /* strdup( */RML_STRINGDATA(rmlA0)/* ) */;
char *source = /* strdup( */RML_STRINGDATA(rmlA1)/* ) */;
char *target =/* strdup( */RML_STRINGDATA(rmlA2)/* ) */;
char * res=0;
/* printf("in '%s' replace '%s' with '%s'\n",str,source,target); */

/* adrpo 2006-05-15
* if source and target are the same this function
* cycles, get rid of that here
* x08joekl 2008-02-5
* fixed so that _replace handles target having source as a substring.
*/
/*
if (!strcmp(source, target))
RML_TAILCALLK(rmlSC);
*/
/* end adrpo */

res = _replace(str,source,target);
char *res = _replace(str,source,target);
if (res == NULL)
{
/* printf("res == NULL\n"); */
RML_TAILCALLK(rmlFC);
}
rmlA0 = (void*) mk_scon(res);
/* printf("Replace result: '%s'\n",res); */
free(res);
RML_TAILCALLK(rmlSC);
}
Expand Down Expand Up @@ -2599,7 +2575,7 @@ RML_END_LABEL

char *select_from_dir;

int file_select_directories(struct dirent *entry)
int file_select_directories(const struct dirent *entry)
{
char fileName[MAXPATHLEN];
int res;
Expand Down Expand Up @@ -2642,7 +2618,7 @@ RML_BEGIN_LABEL(System__subDirectories)
}
RML_END_LABEL

int file_select_mo(struct dirent *entry)
int file_select_mo(const struct dirent *entry)
{
char fileName[MAXPATHLEN];
int res; char* ptr;
Expand Down
26 changes: 22 additions & 4 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -82,10 +82,13 @@ extern "C" {
#endif
#endif

/* errorext.h is a C++ header... */
void c_add_message(int errorID, const char* type, const char* severity, const char* message, const char** ctokens, int nTokens);
#include "rtclock.h"
#include "systemimpl.h"
#include "config.h"
#include "rtopts.h"
#include "errorext.h"

static int SystemImpl__regularFileExists(const char* str)
static modelica_integer SystemImpl__regularFileExists(const char* str)
{
#if defined(__MINGW32__) || defined(_MSC_VER)
int ret_val;
Expand Down Expand Up @@ -145,7 +148,7 @@ static char* SystemImpl__readFile(const char* filename)
}

/* returns 0 on success */
static int SystemImpl__writeFile(const char* filename, const char* data)
static modelica_integer SystemImpl__writeFile(const char* filename, const char* data)
{
#if defined(__MINGW32__) || defined(_MSC_VER)
const char *fileOpenMode = "wt"; /* on Windows do translation so that \n becomes \r\n */
Expand Down Expand Up @@ -191,6 +194,21 @@ static int SystemImpl__writeFile(const char* filename, const char* data)
return 0;
}

static modelica_integer SystemImpl__stringFind(const char* str, const char* searchStr)
{
int strLen = strlen(str);
int strSearchLen = strlen(searchStr);
modelica_integer i,retVal=-1;

for (i=0; i< strLen - strSearchLen+1; i++) {
if (strncmp(&str[i],searchStr,strSearchLen) == 0) {
retVal = i;
break;
}
}
return retVal;
}

#ifdef __cplusplus
}
#endif

0 comments on commit 23e78c4

Please sign in to comment.