Skip to content

Commit

Permalink
- Added test case for events
Browse files Browse the repository at this point in the history
- Updated winruntime after changes in runtime
- Added missing return statement in printimpl.c

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1941 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Håkan Lundvall committed Nov 1, 2005
1 parent e5fa18c commit d93395e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 119 deletions.
1 change: 1 addition & 0 deletions Compiler/runtime/printimpl.c
Expand Up @@ -35,6 +35,7 @@ int print_error_buf_impl(char *str)

sprintf((char*)(errorBuf+strlen(errorBuf)),"%s",str);
errorNfilled=strlen(errorBuf);
return 0;
}

RML_BEGIN_LABEL(Print__print_5ferror_5fbuf)
Expand Down
119 changes: 40 additions & 79 deletions Compiler/winruntime/printimpl.c
@@ -1,53 +1,8 @@
/*
This file is part of OpenModelica.
Copyright (c) 1998-2005, Linköpings universitet, Department of
Computer and Information Science, PELAB
All rights reserved.
(The new BSD license, see also
http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Linköpings universitet nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "rml.h"
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "../absyn_builder/yacclib.h"

#define GROWTH_FACTOR 1.4 /* According to some roumours of buffer growth */
#define INITIAL_BUFSIZE 4000000 /* Seems reasonable */
#define INITIAL_BUFSIZE 4000 /* Seems reasonable */
char *buf = NULL;
char *errorBuf = NULL;

Expand All @@ -58,34 +13,40 @@ int errorNfilled=0;
int errorCursize=0;

int increase_buffer(void);
void error_increase_buffer(void);
int error_increase_buffer(void);
void Print_5finit(void)
{

}


void print_error_buf_impl(char *str)
int print_error_buf_impl(char *str)
{
/* printf("cursize: %d, nfilled %d, strlen: %d\n",cursize,nfilled,strlen(str));*/

assert(str != NULL);
if (str == NULL) {
return -1;
}
while (errorNfilled + strlen(str)+1 > errorCursize) {
error_increase_buffer();
if (error_increase_buffer() != 0) {
return -1;
}
/* printf("increased -- cursize: %d, nfilled %d\n",cursize,nfilled);*/
}

sprintf((char*)(errorBuf+strlen(errorBuf)),"%s",str);
errorNfilled=strlen(errorBuf);
return 0;
}

RML_BEGIN_LABEL(Print__print_5ferror_5fbuf)
{
char* str = RML_STRINGDATA(rmlA0);
print_error_buf_impl(str);

char* str = RML_STRINGDATA(rmlA0);
if (print_error_buf_impl(str) != 0) {
RML_TAILCALLK(rmlFC);
}

/* printf("%s",str);*/

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand All @@ -104,7 +65,9 @@ RML_END_LABEL
RML_BEGIN_LABEL(Print__get_5ferror_5fstring)
{
if (errorBuf == 0) {
error_increase_buffer();
if(error_increase_buffer() != 0) {
RML_TAILCALLK(rmlFC);
}
}

rmlA0=(void*)mk_scon(errorBuf);
Expand All @@ -115,22 +78,21 @@ RML_END_LABEL

RML_BEGIN_LABEL(Print__print_5fbuf)
{
long strl;
char* str = RML_STRINGDATA(rmlA0);

if (str == NULL) {
RML_TAILCALLK(rmlFC);
}
strl = strlen(str);
while (nfilled + strl+1 > cursize) {
if (!increase_buffer()) {
RML_TAILCALLK(rmlFC);
}
/* printf("cursize: %d, nfilled %d, strlen: %d\n",cursize,nfilled,strlen(str));*/

while (nfilled + strlen(str)+1 > cursize) {
if(increase_buffer()!= 0) {
RML_TAILCALLK(rmlFC);
}
/* printf("increased -- cursize: %d, nfilled %d\n",cursize,nfilled);*/
}

sprintf((char*)(buf+nfilled),"%s",str);
sprintf((char*)(buf+strlen(buf)),"%s",str);
nfilled=strlen(buf);

/* printf("%s",str);*/

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand All @@ -149,7 +111,9 @@ RML_END_LABEL
RML_BEGIN_LABEL(Print__get_5fstring)
{
if (buf == 0) {
increase_buffer();
if (increase_buffer() != 0) {
RML_TAILCALLK(rmlFC);
}
}

rmlA0=(void*)mk_scon(buf);
Expand Down Expand Up @@ -188,44 +152,41 @@ int increase_buffer(void)

if (cursize == 0) {
new_buf = (char*)malloc(INITIAL_BUFSIZE);
if (new_buf == NULL) {
return 0;
}
new_buf[0]='\0';
if (new_buf == NULL) { return -1; }
new_buf[0]='\0';
cursize = INITIAL_BUFSIZE;
} else {
new_buf = (char*)malloc(new_size =(int) (cursize * GROWTH_FACTOR));
if (new_buf == NULL) {
return 0;
}
if (new_buf == NULL) { return -1; }
memcpy(new_buf,buf,cursize);
cursize = new_size;
}
if (buf) {
free(buf);
}
buf = new_buf;
return 1;
return 0;
}

void error_increase_buffer(void)
int error_increase_buffer(void)
{
char * new_buf;
int new_size;

if (errorCursize == 0) {
new_buf = (char*)malloc(INITIAL_BUFSIZE);
assert(new_buf != NULL);
if (new_buf == NULL) { return -1; }
new_buf[0]='\0';
errorCursize = INITIAL_BUFSIZE;
} else {
new_buf = (char*)malloc(new_size =(int) (errorCursize * GROWTH_FACTOR));
assert(new_buf != NULL);
if (new_buf == NULL) { return -1; }
memcpy(new_buf,errorBuf,errorCursize);
errorCursize = new_size;
}
if (errorBuf) {
free(errorBuf);
}
errorBuf = new_buf;
return 0;
}
97 changes: 57 additions & 40 deletions Compiler/winruntime/systemimpl.c
Expand Up @@ -283,9 +283,8 @@ RML_BEGIN_LABEL(System__compile_5fc_5ffile)
exename[strlen(str)-2]='\0';

sprintf(command,"%s %s -o %s %s",cc,str,exename,cflags);
printf("compile using: %s\n",command);
//printf("compile using: %s\n",command);
_putenv("GCC_EXEC_PREFIX=");
// _putenv("MODELICAUSERCFLAGS=-Dfoo");
tmp = getenv("MODELICAUSERCFLAGS");
if (tmp == NULL || tmp[0] == '\0' ) {
_putenv("MODELICAUSERCFLAGS= ");
Expand Down Expand Up @@ -554,50 +553,66 @@ void* read_one_value_from_file(FILE* file, type_description* desc)
} else if (desc->type == 'r') {
fscanf(file,"%e",&rval);
res = (void*) Values__REAL(mk_rcon(rval));
}
}
else /* Array value */
{
int currdim,el,i;
if (desc->type == 'r') {
/* Create array to hold inserted values, max dimension as size */
size = 1;
for (currdim=0;currdim < desc->ndims; currdim++) {
size *= desc->dim_size[currdim];
}
rval_arr = (float*)malloc(sizeof(float)*size);
if(rval_arr == NULL) {
}
} else if (desc->ndims == 1 && desc->type == 's') { /* Scalar String */
int i;
char* tmp;
tmp = malloc(sizeof(char)*(desc->dim_size[0]+1));
if (!tmp) return NULL;
for(i=0;i<desc->dim_size[0];i++) {
tmp[i] = fgetc(file);
if (tmp[i] == EOF) {
return NULL;
}
/* Fill the array in reversed order */
for(i=size-1;i>=0;i--) {
fscanf(file,"%e",&rval_arr[i]);
}

next_realelt(NULL);
/* 1 is current dimension (start value) */
res =(void*) Values__ARRAY(generate_array('r',1,desc,(void*)rval_arr));
}

if (desc->type == 'i') {
tmp[i]='\0';
res = (void*) Values__STRING(mk_scon(tmp));
}
else /* Array value */
{
int currdim,el,i;
/* Create array to hold inserted values, mult of dimensions as size */
size = 1;
for (currdim=0;currdim < desc->ndims; currdim++) {
size *= desc->dim_size[currdim];
}
ival_arr = (int*)malloc(sizeof(int)*size);
if(rval_arr==NULL) {
return NULL;
if (desc->type == 'r') {
/* Create array to hold inserted values, max dimension as size */
size = 1;
for (currdim=0;currdim < desc->ndims; currdim++) {
size *= desc->dim_size[currdim];
}
rval_arr = (float*)malloc(sizeof(float)*size);
if(rval_arr == NULL) {
return NULL;
}
/* Fill the array in reversed order */
for(i=size-1;i>=0;i--) {
fscanf(file,"%e",&rval_arr[i]);
}

next_realelt(NULL);
/* 1 is current dimension (start value) */
res =(void*) Values__ARRAY(generate_array('r',1,desc,(void*)rval_arr));
}
/* Fill the array in reversed order */
for(i=size-1;i>=0;i--) {
fscanf(file,"%f",&ival_arr[i]);

if (desc->type == 'i') {
int currdim,el,i;
/* Create array to hold inserted values, mult of dimensions as size */
size = 1;
for (currdim=0;currdim < desc->ndims; currdim++) {
size *= desc->dim_size[currdim];
}
ival_arr = (int*)malloc(sizeof(int)*size);
if(rval_arr==NULL) {
return NULL;
}
/* Fill the array in reversed order */
for(i=size-1;i>=0;i--) {
fscanf(file,"%f",&ival_arr[i]);
}
next_intelt(NULL);
res = (void*) Values__ARRAY(generate_array('i',1,desc,(void*)ival_arr));
}
if (desc->type == 's') {
printf("Error, array of strings not impl. yet.\n");
}
next_intelt(NULL);
res = (void*) Values__ARRAY(generate_array('i',1,desc,(void*)ival_arr));
}
}
}
return res;
}

Expand All @@ -618,12 +633,14 @@ RML_BEGIN_LABEL(System__read_5fvalues_5ffrom_5ffile)
/* Read the first value */
stat = read_type_description(file,&desc);
if (stat != 0) {
printf("Error reading values from file\n");
RML_TAILCALLK(rmlFC);
}

while (stat == 0) { /* Loop for tuples. At the end of while, we try to read another description */
res = read_one_value_from_file(file, &desc);
if (res == NULL) {
printf("Error reading values from file2\n");
RML_TAILCALLK(rmlFC);
}
lst = (void*)mk_cons(res, lst);
Expand Down

0 comments on commit d93395e

Please sign in to comment.