Skip to content

Commit

Permalink
local (protected) variables in functions implemented. Started to impl…
Browse files Browse the repository at this point in the history
…ement strings in external function interface

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@970 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
levsa committed Jun 2, 2003
1 parent 5aa5eae commit 8ef9955
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 3,716 deletions.
2 changes: 1 addition & 1 deletion c_runtime/Makefile
Expand Up @@ -5,7 +5,7 @@ CFLAGS = -g -Wall -ansi -pedantic


OBJS = boolean_array.o index_spec.o integer_array.o memory_pool.o \
real_array.o string_array.o read_write.o utility.o
real_array.o string_array.o read_write.o utility.o modelica_string.o

all : libc_runtime.a

Expand Down
30 changes: 29 additions & 1 deletion c_runtime/memory_pool.c
Expand Up @@ -30,7 +30,8 @@ state current_state = {
0,/*string buffer*/
0,/*boolean buffer*/
0,/* size buffer */
0 /* index buffer */
0,/* index buffer */
0 /* char buffer */
};

real real_buffer[NR_REAL_ELEMENTS];
Expand All @@ -39,6 +40,7 @@ string string_buffer[NR_STRING_ELEMENTS];
boolean boolean_buffer[NR_BOOLEAN_ELEMENTS];
integer size_buffer[NR_SIZE_ELEMENTS];
int* index_buffer[NR_INDEX_ELEMENTS];
char char_buffer[NR_CHAR_ELEMENTS];


state get_memory_state()
Expand All @@ -53,6 +55,7 @@ void print_current_state()
printf("integer index: %d\n",current_state.integer_buffer_ptr);
printf("string index: %d\n",current_state.string_buffer_ptr);
printf("boolean: %d\n",current_state.boolean_buffer_ptr);
printf("char: %d\n",current_state.char_buffer_ptr);
}

void print_state(state s)
Expand All @@ -62,6 +65,7 @@ void print_state(state s)
printf("integer index: %d\n",s.integer_buffer_ptr);
printf("string index: %d\n",s.string_buffer_ptr);
printf("boolean: %d\n",s.boolean_buffer_ptr);
printf("char: %d\n",s.char_buffer_ptr);
}

void restore_memory_state(state restore_state)
Expand All @@ -75,6 +79,7 @@ void clear_current_state()
current_state.integer_buffer_ptr = 0;
current_state.string_buffer_ptr = 0;
current_state.boolean_buffer_ptr = 0;
current_state.char_buffer_ptr = 0;
}

/* allocates n reals in the real_buffer */
Expand Down Expand Up @@ -168,6 +173,20 @@ int** index_alloc(int n)
/* return start;*/
}

char* char_alloc(int n)
{
_index_t start;

assert(n>=0);
assert(n + current_state.char_buffer_ptr < NR_CHAR_ELEMENTS);

start = current_state.char_buffer_ptr;
current_state.char_buffer_ptr += n;
return char_buffer+start;

/* return start;*/
}

_index_t real_free(int n)
{
assert(n>=0);
Expand Down Expand Up @@ -221,3 +240,12 @@ _index_t index_free(int n)
current_state.index_buffer_ptr -= n;
return current_state.index_buffer_ptr;
}

_index_t char_free(int n)
{
assert(n>=0);
assert(current_state.char_buffer_ptr-n>=0);

current_state.char_buffer_ptr -= n;
return current_state.char_buffer_ptr;
}
5 changes: 5 additions & 0 deletions c_runtime/memory_pool.h
Expand Up @@ -29,6 +29,7 @@
#define NR_BOOLEAN_ELEMENTS 10000
#define NR_SIZE_ELEMENTS 10000
#define NR_INDEX_ELEMENTS 10000
#define NR_CHAR_ELEMENTS 10000

typedef double real;
typedef int integer;
Expand All @@ -42,6 +43,7 @@ extern string string_buffer[NR_STRING_ELEMENTS];
extern boolean boolean_buffer[NR_BOOLEAN_ELEMENTS];
extern integer size_buffer[NR_SIZE_ELEMENTS];
extern int* index_buffer[NR_INDEX_ELEMENTS];
extern char char_buffer[NR_CHAR_ELEMENTS];

struct state_s {
_index_t real_buffer_ptr;
Expand All @@ -50,6 +52,7 @@ struct state_s {
_index_t boolean_buffer_ptr;
_index_t size_buffer_ptr;
_index_t index_buffer_ptr;
_index_t char_buffer_ptr;
};

typedef struct state_s state;
Expand All @@ -72,11 +75,13 @@ string* string_alloc(int n);
boolean* boolean_alloc(int n);
int* size_alloc(int n);
int** index_alloc(int n);
char* char_alloc(int n);

_index_t real_free(int n);
_index_t integer_free(int n);
_index_t string_free(int n);
_index_t boolean_free(int n);
_index_t size_free(int n);
_index_t index_free(int n);
_index_t char_free(int n);
#endif
2 changes: 2 additions & 0 deletions c_runtime/modelica.h
Expand Up @@ -30,10 +30,12 @@
#include "string_array.h"
#include "boolean_array.h"
#include "utility.h"
#include "modelica_string.h"
#include "read_write.h"

typedef real_array_t real_array;
typedef integer_array_t integer_array;
typedef modelica_string_t modelica_string;

typedef modelica_integer size_real_array_rettype;
typedef modelica_integer size_integer_array_rettype;
Expand Down
35 changes: 35 additions & 0 deletions c_runtime/read_write.c
Expand Up @@ -25,6 +25,7 @@ void read_to_eol(FILE* file)
int c;
while (((c = fgetc(file)) != '\n') && (c != EOF));
}

int read_type_description(FILE* file, type_description* desc)
{
int c;
Expand Down Expand Up @@ -195,3 +196,37 @@ void write_integer_array(FILE* file, integer_array_t* arr)
return 0;
}
*/

int read_modelica_string(FILE* file, modelica_string_t* str)
{
int length;
int i;
char c;
type_description desc;
modelica_string_t tmp;

if (read_type_description(file,&desc)) { in_report("ms type_desc"); return 1; }
if (desc.type != 's') { cleanup_description(&desc); in_report("ms type"); return 1; }
if (desc.ndims != 1) { cleanup_description(&desc); in_report("ms ndims"); return 1; }

tmp.length = desc.dim_size[0];
clone_modelica_string_spec(&tmp, str);
alloc_modelica_string_data(str);
cleanup_description(&desc);

length = modelica_string_length(str);
for (i = 0; i< length; ++i) {
if (fscanf(file,"%c",&c) != 1) { in_report("ms parse"); return 1; }
str->data[i] = c;
}
read_to_eol(file);
return 0;
}

int write_modelica_string(FILE* file, modelica_string_t* str)
{
fprintf(file,"# s[ %d %d", 1, str->length);
fprintf(file,"\n");
fprintf(file,"%s\n",str->data);
return 0;
}
3 changes: 3 additions & 0 deletions c_runtime/read_write.h
Expand Up @@ -53,4 +53,7 @@ int read_integer_array(FILE*,integer_array_t*);
int write_modelica_integer(FILE*,modelica_integer*);
int write_integer_array(FILE*,integer_array_t*);

int read_modelica_string(FILE*,modelica_string_t*);
int write_modelica_string(FILE*,modelica_string_t*);

#endif
4 changes: 2 additions & 2 deletions c_runtime/string_array.h
Expand Up @@ -23,13 +23,13 @@
#ifndef STRING_ARRAY_H_
#define STRING_ARRAY_H_

typedef char* modelica_string;
#include "modelica_string.h"

struct string_array_s
{
int ndims;
int* dim_size;
modelica_string* data;
modelica_string_t* data;
};

typedef struct string_array_s string_array_t;
Expand Down
1 change: 1 addition & 0 deletions modeq/DEBUG.TXT
Expand Up @@ -33,6 +33,7 @@ General--------------------------------------------------------------------
info General information
olddebug print messages sent to the old Debug.print
Dump-----------------------------------------------------------------------
parsedump dump the parse tree
dump dump the absyn tree
dumpgraphviz dump the absyn tree in graphviz format
daedump dump the dae in printed form
Expand Down
16 changes: 12 additions & 4 deletions modeq/absyn.rml
Expand Up @@ -326,6 +326,7 @@ module Absyn:
relation cref_to_path : ComponentRef => Path
relation path_to_cref : Path => ComponentRef
relation path_string : Path => string
relation path_string2 : (Path, string) => string
relation path_last_ident : Path => Ident
relation get_cref_from_exp : ( Exp ) => ComponentRef list
relation join_paths: (Path, Path) => Path
Expand Down Expand Up @@ -365,13 +366,20 @@ end

relation path_string: Path => string =

axiom path_string(IDENT(s)) => s
rule path_string2 (path, ".") => s
-----------------------------
path_string path => s
end

relation path_string2: (Path, string) => string =

axiom path_string2(IDENT(s),_) => s

rule path_string(n) => ns &
string_append(s,".") => s1 &
rule path_string2(n,str) => ns &
string_append(s,str) => s1 &
string_append(s1,ns) => ss
-------------------------------------
path_string(QUALIFIED(s,n)) => ss
path_string2(QUALIFIED(s,n), str) => ss

end

Expand Down
4 changes: 4 additions & 0 deletions modeq/cache.rml
Expand Up @@ -81,7 +81,11 @@ relation get_variable: (Cache, Absyn.Path option, Absyn.Path) => Types.Var
relation get_type: (Cache, Absyn.Path option, Absyn.Path) => Types.Type

relation print_cache: (Cache) => ()

val empty_cache : Cache

end

with "dump.rml"
val empty_cache = CACHE([],[])

Expand Down

0 comments on commit 8ef9955

Please sign in to comment.