Skip to content

Commit

Permalink
- Added more external functions for System_omc.cpp
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7113 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 19, 2010
1 parent dbdf0f4 commit 01eaaaf
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 124 deletions.
28 changes: 14 additions & 14 deletions Compiler/System.mo
Expand Up @@ -139,7 +139,7 @@ end strtok;
public function setCCompiler
input String inString;

external "C" System_setCCompiler(inString) annotation(Library = "omcruntime");
external "C" SystemImpl__setCCompiler(inString) annotation(Library = "omcruntime");
end setCCompiler;

public function getCCompiler
Expand All @@ -151,7 +151,7 @@ end getCCompiler;
public function setCFlags
input String inString;

external "C" System_setCFlags(inString) annotation(Library = "omcruntime");
external "C" SystemImpl__setCFlags(inString) annotation(Library = "omcruntime");
end setCFlags;

public function getCFlags
Expand All @@ -163,7 +163,7 @@ end getCFlags;
public function setCXXCompiler
input String inString;

external "C" System_setCXXCompiler(inString) annotation(Library = "omcruntime");
external "C" SystemImpl__setCXXCompiler(inString) annotation(Library = "omcruntime");
end setCXXCompiler;

public function getCXXCompiler
Expand All @@ -175,7 +175,7 @@ end getCXXCompiler;
public function setLinker
input String inString;

external "C" System_setLinker(inString) annotation(Library = "omcruntime");
external "C" SystemImpl__setLinker(inString) annotation(Library = "omcruntime");
end setLinker;

public function getLinker
Expand All @@ -187,7 +187,7 @@ end getLinker;
public function setLDFlags
input String inString;

external "C" System_setLDFlags(inString) annotation(Library = "omcruntime");
external "C" SystemImpl__setLDFlags(inString) annotation(Library = "omcruntime");
end setLDFlags;

public function getLDFlags
Expand Down Expand Up @@ -236,8 +236,8 @@ public function freeLibrary
end freeLibrary;

public function sendData
input String inString1;
input String inString2; //interpolation
input String data;
input String interpolation;
input String title;
input Boolean legend;
input Boolean grid;
Expand All @@ -247,7 +247,7 @@ public function sendData
input String yLabel;
input Boolean points;
input String range;
external "C" System_sendData(inString1,inString2,title,legend,grid,logX,logY,xLabel,yLabel,points,range) annotation(Library = "omcruntime");
external "C" emulateStreamData(data, title, xLabel, yLabel , interpolation, legend, grid, logX, logY, points, range) annotation(Library = "omcruntime");
end sendData;

public function enableSendData
Expand All @@ -267,9 +267,9 @@ public function setVariableFilter
end setVariableFilter;

public function sendData2
input String inString1;
input String inString2;
external "C" System_sendData2(inString1,inString2) annotation(Library = "omcruntime");
input String info;
input String data;
external "C" emulateStreamData2(info, data, 7778) annotation(Library = "omcruntime");
end sendData2;

public function writeFile
Expand Down Expand Up @@ -307,12 +307,12 @@ end systemCall;
public function cd
input String inString;
output Integer outInteger;
external "C" outInteger=System_cd(inString) annotation(Library = "omcruntime");
external "C" outInteger=chdir(inString) annotation(Library = "omcruntime");
end cd;

public function pwd
output String outString;
external "C" outString=System_pwd() annotation(Library = "omcruntime");
external "C" outString=SystemImpl__pwd() annotation(Library = "omcruntime");
end pwd;

public function readEnv "Reads the environment variable given as string, fails if variable not found"
Expand Down Expand Up @@ -378,7 +378,7 @@ end getPackageFileNames;
public function directoryExists
input String inString;
output Boolean outBool;
external "C" outBool=System_directoryExists(inString) annotation(Library = "omcruntime");
external "C" outBool=SystemImpl__directoryExists(inString) annotation(Library = "omcruntime");
end directoryExists;

public function platform
Expand Down
58 changes: 58 additions & 0 deletions Compiler/runtime/System_omc.cpp
Expand Up @@ -167,4 +167,62 @@ extern const char* System_groupDelimiter()
return CONFIG_GROUP_DELIMITER;
}

extern int System_strncmp(const char *str1, const char *str2, int len)
{
int res= strncmp(str1,str2,len);
/* adrpo: 2010-10-07, return -1, 0, +1 so we can pattern match on it directly! */
if (res>0) res = 1;
else if (res<0) res = -1;
return res;
}

extern int System_strcmp(const char *str1, const char *str2)
{
int res = strcmp(str1,str2);
/* adrpo: 2010-10-07, return -1, 0, +1 so we can pattern match on it directly! */
if (res>0) res = 1;
else if (res<0) res = -1;
return res;
}

extern int System_getHasExpandableConnectors()
{
return hasExpandableConnector;
}

extern void System_setHasExpandableConnectors(int b)
{
hasExpandableConnector = b;
}

extern int System_hasInnerOuterDefinitions()
{
return hasInnerOuterDefinitions;
}

extern void System_setHasInnerOuterDefinitions(int b)
{
hasInnerOuterDefinitions = b;
}

extern void* System_strtok(const char *str0, const char *delimit)
{
char *s;
void *res = mmc_mk_nil();
char *str = strdup(str0);
s=strtok(str,delimit);
if (s == NULL)
{
free(str);
throw 1;
}
res = mmc_mk_cons(mmc_mk_scon(s),res);
while (s=strtok(NULL,delimit))
{
res = mmc_mk_cons(mmc_mk_scon(s),res);
}
free(str);
return listReverse(res);
}

}
134 changes: 30 additions & 104 deletions Compiler/runtime/System_rml.c
Expand Up @@ -266,6 +266,9 @@ RML_BEGIN_LABEL(System__strncmp)
char *str2 = RML_STRINGDATA(rmlA1);
rml_sint_t len = RML_UNTAGFIXNUM(rmlA2);
int res= strncmp(str,str2,len);
/* adrpo: 2010-10-07, return -1, 0, +1 so we can pattern match on it directly! */
if (res>0) res = 1;
else if (res<0) res = -1;

rmlA0 = (void*) mk_icon(res);

Expand Down Expand Up @@ -332,8 +335,8 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__setCCompiler)
{
char* str = RML_STRINGDATA(rmlA0);
if (set_cc(str)) {
const char* str = RML_STRINGDATA(rmlA0);
if (SystemImpl__setCCompiler(str)) {
RML_TAILCALLK(rmlFC);
}
RML_TAILCALLK(rmlSC);
Expand All @@ -351,8 +354,8 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__setCXXCompiler)
{
char* str = RML_STRINGDATA(rmlA0);
if (set_cxx(str)) {
const char* str = RML_STRINGDATA(rmlA0);
if (SystemImpl__setCXXCompiler(str)) {
RML_TAILCALLK(rmlFC);
}
RML_TAILCALLK(rmlSC);
Expand All @@ -370,8 +373,8 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__setLinker)
{
char* str = RML_STRINGDATA(rmlA0);
if (set_linker(str)) {
const char* str = RML_STRINGDATA(rmlA0);
if (SystemImpl__setLinker(str)) {
RML_TAILCALLK(rmlFC);
}
RML_TAILCALLK(rmlSC);
Expand All @@ -389,8 +392,8 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__setCFlags)
{
char* str = RML_STRINGDATA(rmlA0);
if (set_cflags(str)) {
const char* str = RML_STRINGDATA(rmlA0);
if (SystemImpl__setCFlags(str)) {
RML_TAILCALLK(rmlFC);
}
RML_TAILCALLK(rmlSC);
Expand All @@ -408,8 +411,8 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__setLDFlags)
{
char* str = RML_STRINGDATA(rmlA0);
if (set_ldflags(str)) {
const char* str = RML_STRINGDATA(rmlA0);
if (SystemImpl__setLDFlags(str)) {
RML_TAILCALLK(rmlFC);
}
RML_TAILCALLK(rmlSC);
Expand Down Expand Up @@ -919,11 +922,6 @@ void free_function(modelica_ptr_t func)
/* fprintf(stderr, "FUNCTION FREE LIB index[%d]/count[%d]/handle[%ul].\n", (lib-ptr_vector),((modelica_ptr_t)(lib-ptr_vector))->cnt, lib->data.lib); fflush(stderr); */
}

/*
* @author: adrpo
* side effect to detect if we have expandable conenctors in a program
*/
int hasExpandableConnector = 0;
/*
* @author: adrpo
* side effect to set if we have expandable conenctors in a program
Expand All @@ -945,11 +943,6 @@ RML_BEGIN_LABEL(System__setHasExpandableConnectors)
}
RML_END_LABEL

/*
* @author: adrpo
* side effect to detect if we have expandable conenctors in a program
*/
int hasInnerOuterDefinitions = 0;
/*
* @author: adrpo
* side effect to set if we have expandable conenctors in a program
Expand Down Expand Up @@ -1174,23 +1167,6 @@ RML_BEGIN_LABEL(System__compileCFile)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__pwd)
{
char buf[MAXPATHLEN];
char* buf2;
LPTSTR bufPtr=buf;
DWORD bufLen = MAXPATHLEN;
GetCurrentDirectory(bufLen,bufPtr);

/* Make sure windows paths use fronslash and not backslash */
buf2=_replace(buf,"\\","/");

rmlA0 = (void*) mk_scon(buf2);
free(buf2);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

/* RML_BEGIN_LABEL(System__modelicapath) */
/* { */
/* char *path = getenv("OPENMODELICALIBRARY"); */
Expand Down Expand Up @@ -1364,33 +1340,6 @@ RML_BEGIN_LABEL(System__getPackageFileNames)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__directoryExists)
{
char* str = RML_STRINGDATA(rmlA0);
int ret_val;
void *res;
WIN32_FIND_DATA FileData;
HANDLE sh;
if (str == NULL)
RML_TAILCALLK(rmlFC);
sh = FindFirstFile(str, &FileData);
if (sh == INVALID_HANDLE_VALUE) {
ret_val = 1;
}
else {
if ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
ret_val = 1;
}
else {
ret_val = 0;
}
FindClose(sh);
}
rmlA0 = (void*) mk_icon(!ret_val);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

//void* generate_array(char type, int curdim, type_description *desc, void *data)
//
//{
Expand Down Expand Up @@ -1938,20 +1887,6 @@ RML_BEGIN_LABEL(System__compileCFile)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__pwd)
{
char buf[MAXPATHLEN];
if (NULL == getcwd(buf,MAXPATHLEN)) {
fprintf(stderr, "System.pwd failed\n");
rmlA0 = (void*) mk_scon("$invalid_path$");
} else {
rmlA0 = (void*) mk_scon(buf);
}

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

/* RML_BEGIN_LABEL(System__modelicapath) */
/* { */
/* char *path = getenv("OPENMODELICALIBRARY"); */
Expand Down Expand Up @@ -2120,32 +2055,6 @@ RML_BEGIN_LABEL(System__getPackageFileNames)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__directoryExists)
{
char* str = RML_STRINGDATA(rmlA0);
int ret_val;
struct stat buf;

if (str == NULL)
RML_TAILCALLK(rmlFC);

ret_val = stat(str, &buf);
if (ret_val != 0 ) {
ret_val = 1;
}
else {
if (buf.st_mode & S_IFDIR) {
ret_val = 0;
}
else {
ret_val = 1;
}
}
rmlA0 = (void*) mk_icon(!ret_val);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__setVariableFilter)
{
char * variables = RML_STRINGDATA(rmlA0);
Expand Down Expand Up @@ -2412,3 +2321,20 @@ RML_BEGIN_LABEL(System__groupDelimiter)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__pwd)
{
char *buf = SystemImpl__pwd();
if (buf == NULL) RML_TAILCALLK(rmlFC);
rmlA0 = mk_scon(buf);
free(buf);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__directoryExists)
{
const char* str = RML_STRINGDATA(rmlA0);
rmlA0 = (void*) mk_icon(SystemImpl__directoryExists(str));
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

0 comments on commit 01eaaaf

Please sign in to comment.