Skip to content

Commit

Permalink
Function call fixes. Tuples support added. Testsuite extension for c …
Browse files Browse the repository at this point in the history
…compiler flag support. External function tests ExternalFunction1.mo ExternalFunction2.mo ExternalFunction3.mo

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1644 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
levsa committed Mar 30, 2005
1 parent d507d2d commit 2c91bba
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 168 deletions.
1 change: 1 addition & 0 deletions modeq/TODO
Expand Up @@ -190,6 +190,7 @@ List of things to implement:
34. inst.rml:inst_var2. If impl=true and we cannot flatten the array variable, we
should leave it unflattened, but with correct type and dimensions, e.g. similar to
functions.
35. values_to_mods doesn't handle all value types, e.g. arrays.


Specific adaptions:
Expand Down
12 changes: 6 additions & 6 deletions modeq/algorithm.rml
Expand Up @@ -193,15 +193,15 @@ with "debug.rml"
** assignment is semantically valid, which means that the component
** being assigned is not constant, and that the types match.
**
** LS: Added call to get_prop_type and is_prop_const instead of
** LS: Added call to get_prop_type and is_prop_any_const instead of
** having PROP in the rules. Otherwise rules must be repeated because of
** combinations with PROP_TUPLE
**)
relation make_assignment : (Exp.Exp, Types.Properties,
Exp.Exp, Types.Properties,
SCode.Accessibility) => Statement =

rule Types.is_prop_const (lprop) => true &
rule Types.is_prop_any_const (lprop) => true &
Print.print_error_buf "# Trying to assign to constant component\n" &
Print.print_error_buf " " & Exp.print_exp lhs &
Print.print_error_buf " := " & Exp.print_exp rhs & Print.print_buf "\n"
Expand All @@ -213,15 +213,15 @@ relation make_assignment : (Exp.Exp, Types.Properties,
make_assignment(e,_,_,_, SCode.RO) => fail

(* LS: Replaced "as Types.PROP(_,false)" from lhprop", by the first predicate *)
rule Types.is_prop_const (lhprop) => false &
rule Types.is_prop_any_const (lhprop) => false &
Types.match_prop(rhs, rhprop, lhprop) => rhs' &
Types.is_prop_array lhprop => false &
get_prop_exp_type lhprop => t
----------------------------------------------
make_assignment(Exp.CREF(c,crt), lhprop,
rhs, rhprop, _) => ASSIGN(t,c,rhs')

rule Types.is_prop_const (lhprop) => false &
rule Types.is_prop_any_const (lhprop) => false &
Types.match_prop(rhs, rhprop, lhprop) => rhs' &
Types.is_prop_array lhprop => true &
get_prop_exp_type lhprop => t
Expand Down Expand Up @@ -257,7 +257,7 @@ end
relation make_tuple_assignment : (Exp.Exp list, Types.Properties list,
Exp.Exp, Types.Properties) => Statement =

rule Util.list_map(lprop, Types.is_prop_const) => bvals &
rule Util.list_map(lprop, Types.is_prop_any_const) => bvals &
Util.bool_or_list(bvals) => true &
Print.print_error_buf "# Trying to assign to constant component in tuple assignment\n" &
Print.print_error_buf " " &
Expand All @@ -267,7 +267,7 @@ relation make_tuple_assignment : (Exp.Exp list, Types.Properties list,
-------------------------------------------
make_tuple_assignment (lhs,lprop,rhs,rprop) => fail

rule Util.list_map(lhprops, Types.is_prop_const) => bvals &
rule Util.list_map(lhprops, Types.is_prop_any_const) => bvals &
Util.bool_or_list(bvals) => false &
Util.list_map(lhprops,Types.get_prop_type) => lhrtypes &
Types.match_type_list(rhs,tpl,lhrtypes) => (rhs',_)
Expand Down
6 changes: 4 additions & 2 deletions modeq/codegen.rml
Expand Up @@ -3557,8 +3557,10 @@ end

relation generate_vardecl_func : (string, string, string option) => CFunction =

rule Util.string_append_list ([tystr, " ", name, " = (", tystr, ")", expr, ";"]) => str &
c_add_variables(c_empty_function, [str]) => res
rule Util.string_append_list ([tystr, " ", name, ";"]) => str &
c_add_variables(c_empty_function, [str]) => f1 &
Util.string_append_list ([name, " = (", tystr, ")", expr, ";"]) => str3 &
c_add_statements(f1, [str3]) => res
-----------------------------------------------
generate_vardecl_func (tystr, name, SOME(expr)) => res

Expand Down
2 changes: 1 addition & 1 deletion modeq/debug.rml
Expand Up @@ -160,7 +160,7 @@ relation print: string => () =

*)

rule (*fprint ("olddebug", s)*)
rule fprint ("olddebug", s)
----------------------
print s => ()

Expand Down
21 changes: 16 additions & 5 deletions modeq/inst.rml
Expand Up @@ -1983,9 +1983,8 @@ relation inst_var2 : (Env.Env,
inst_start_binding_exp(mod,ty,idxs') => start &

inst_dae_variable_attributes(mod,ty,idxs') => dae_var_attr &
DAE.dump_variable_attributes_str(dae_var_attr) => str_tmp &
Debug.fprint("failtrace", str_tmp) &
Debug.fprint("failtrace", " <------------\n") &
DAE.dump_variable_attributes_str(dae_var_attr) => str_tmp &
Debug.fprintln("failtrace", str_tmp) &
dae_declare(cr,ty,SCode.ATTR([], flow, acc, vt, dir), NONE,
inst_dims, start, dae_var_attr) => dae3 &

Expand Down Expand Up @@ -4012,10 +4011,22 @@ relation inst_eq_equation : (Exp.Exp, Types.Properties,
----------
inst_eq_equation(e1,Types.PROP(t1,_), e2,Types.PROP(t2,_), initial,impl) => fail


(* No match. *)
rule Debug.fprintln("failtrace", "\n No match in inst_eq_equation. ")
rule Print.print_error_buf "# No match in inst_eq_equation\n" &
Print.print_error_buf " lhs: " & Exp.print_exp_str e1 => str &
Print.print_error_buf str &
Print.print_error_buf " :: " &
Types.print_prop_str p1 => str & Print.print_error_buf str &
Print.print_error_buf "\n" &
Print.print_error_buf " rhs: " &
Exp.print_exp_str e2 => str & Print.print_error_buf str &
Print.print_error_buf " :: " &
Types.print_prop_str p2 => str & Print.print_error_buf str &
Print.print_error_buf "\n"
---------------------------------
inst_eq_equation(_,_,_,_,_,_) => fail
inst_eq_equation(e1,p1,e2,p2,initial,impl) => fail


end

Expand Down
150 changes: 91 additions & 59 deletions modeq/runtime/systemimpl.c
Expand Up @@ -436,79 +436,111 @@ RML_BEGIN_LABEL(System__mo_5ffiles)
RML_END_LABEL


RML_BEGIN_LABEL(System__read_5fvalues_5ffrom_5ffile)
void* read_one_value_from_file(FILE* file, type_description* desc)
{
type_description desc;
void * res, *res2;
void *res=NULL;
int ival;
float rval;
float *rval_arr;
int *ival_arr;
int size;
if (desc->ndims == 0) /* Scalar value */
{
if (desc->type == 'i') {
fscanf(file,"%d",&ival);
res =(void*) Values__INTEGER(mk_icon(ival));
} 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) {
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') {
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));
}
}
return res;
}

RML_BEGIN_LABEL(System__read_5fvalues_5ffrom_5ffile)
{
int stat=0;
int varcount=0;
type_description desc;
void *lst = (void*)mk_nil();
void *res = NULL;
char* filename = RML_STRINGDATA(rmlA0);
FILE * file=NULL;
file = fopen(filename,"r");
if (file == NULL) {
RML_TAILCALLK(rmlFC);
}

read_type_description(file,&desc);

if (desc.ndims == 0) /* Scalar value */
{
if (desc.type == 'i') {
fscanf(file,"%d",&ival);
res =(void*) Values__INTEGER(mk_icon(ival));
} 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) {
RML_TAILCALLK(rmlFC);
}
/* 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') {
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) {
RML_TAILCALLK(rmlFC);
}
/* 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));

}
/* Read the first value */
stat = read_type_description(file,&desc);
if (stat != 0) {
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) {
RML_TAILCALLK(rmlFC);
}
rmlA0 = (void*)res;
lst = (void*)mk_cons(res, lst);
varcount++;
read_to_eol(file);
stat = read_type_description(file,&desc);
/*
printf("varcount is : %d\n", varcount);
printf("stat is : %d\n", stat);
*/
}
if (varcount > 1) { /* if tuple */
rmlA0 = lst;
rml_prim_once(RML__list_5freverse);
rmlA0 = (void*) Values__TUPLE(rmlA0);
}
else {
rmlA0 = (void*)res;
}
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand Down Expand Up @@ -662,7 +694,7 @@ int next_intelt(int *arr)
else return arr[curpos++];
}

void * generate_array(char type, int curdim, type_description *desc,void *data)
void * generate_array(char type, int curdim, type_description *desc, void *data)

{
void *lst;
Expand Down

0 comments on commit 2c91bba

Please sign in to comment.