Skip to content

Commit

Permalink
Added support for quoting using the Code keyword. Implemented a faste…
Browse files Browse the repository at this point in the history
…r Env: is now a hashtable using RMLs vector datatype. This will prevent a linear search in each frame.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1005 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Sep 25, 2003
1 parent c3ba5ab commit 78eb02b
Show file tree
Hide file tree
Showing 16 changed files with 674 additions and 251 deletions.
10 changes: 10 additions & 0 deletions modeq/absyn.rml
Expand Up @@ -243,9 +243,19 @@ module Absyn:
| RANGE of Exp * Exp option * Exp
| TUPLE of Exp list (*PR.*)
| END
| CODE of Code

(** The `Exp' datatype is the container of a Modelica expression. *)

datatype Code = C_TYPENAME of Path
| C_VARIABLENAME of ComponentRef
| C_EQUATIONSECTION of bool * EquationItem list
| C_ALGORITHMSECTION of bool * AlgorithmItem list
| C_ELEMENT of Element
| C_EXPRESSION of Exp
| C_MODIFICATION of Modification
(** The 'Code' datatype is used for Meta-programming. It orgiginates from the Code quotation. *)

datatype FunctionArgs = FUNCTIONARGS of Exp list * NamedArg list
(** The `FunctionArgs' datatype consists of a list of positional arguments *)
(** followed by a list of named arguments (Modelica v2.0) *)
Expand Down
41 changes: 41 additions & 0 deletions modeq/absyn_builder/walker.g
Expand Up @@ -1216,9 +1216,50 @@ expression returns [void* ast]
:
( ast = simple_expression
| ast = if_expression
| ast = code_expression
)
;

code_expression returns [void* ast]
:
#(CODE_MODIFICATION (ast = modification) )
{
ast = Absyn__CODE(Absyn__C_5fMODIFICATION(ast));
}

| #(CODE_EXPRESSION (ast = expression) )
{
ast = Absyn__CODE(Absyn__C_5fEXPRESSION(ast));
}

| #(CODE_ELEMENT (ast = element) )
{
ast = Absyn__CODE(Absyn__C_5fELEMENT(ast));
}

| #(CODE_EQUATION (ast = equation_clause) )
{
ast = Absyn__CODE(Absyn__C_5fEQUATIONSECTION(RML_FALSE,
RML_FETCH(RML_OFFSET(RML_UNTAGPTR(ast), 1))));
}

| #(CODE_INITIALEQUATION (ast = equation_clause) )
{
ast = Absyn__CODE(Absyn__C_5fEQUATIONSECTION(RML_TRUE,
RML_FETCH(RML_OFFSET(RML_UNTAGPTR(ast), 1))));
}
| #(CODE_ALGORITHM (ast = algorithm_clause) )
{
ast = Absyn__CODE(Absyn__C_5fALGORITHMSECTION(RML_FALSE,
RML_FETCH(RML_OFFSET(RML_UNTAGPTR(ast), 1))));
}
| #(CODE_INITIALALGORITHM (ast = algorithm_clause) )
{
ast = Absyn__CODE(Absyn__C_5fALGORITHMSECTION(RML_TRUE,
RML_FETCH(RML_OFFSET(RML_UNTAGPTR(ast), 1))));
}
;

if_expression returns [void* ast]
{
void* cond;
Expand Down
4 changes: 2 additions & 2 deletions modeq/builtin.rml
Expand Up @@ -636,8 +636,8 @@ relation initial_env =
Env.extend_frame_c(env, int_type) => env &
Env.extend_frame_c(env, str_type) => env &
Env.extend_frame_c(env, bool_type) => env &
Env.extend_frame_c(env, enum_type) => env' &
Env.extend_frame_c(env', real_type) => env &
Env.extend_frame_c(env, enum_type) => env &
Env.extend_frame_c(env, real_type) => env &
Env.extend_frame_c(env, integer_type) => env &
Env.extend_frame_c(env, string_type) => env &
Env.extend_frame_c(env, boolean_type) => env &
Expand Down
14 changes: 11 additions & 3 deletions modeq/dae.rml
Expand Up @@ -346,8 +346,7 @@ end


relation dump_elements : Element list => () =

rule dump_vars l &
rule dump_vars l &
Print.print_buf "initial equation\n" &
dump_list (l, dump_initialequation) &
Print.print_buf "equation\n" &
Expand All @@ -367,7 +366,16 @@ relation dump_elements_str : Element list => string =
dump_equations_str(l) => s3 &
dump_initialalgorithms_str(l) => s4 &
dump_algorithms_str(l) => s5 &
Util.string_append_list([s1,"initial equation\n",s2,"initial algorithm\n",s4,"equation\n",s3,"algorithm\n",s5]) => str
Util.string_equal(s2,"") => noiniteq &
Util.string_equal(s4,"") => noinitalg &
Util.string_equal(s3,"") => noeq &
Util.string_equal(s5,"") => noalg &
Dump.select_string(noiniteq,"","initial equation\n") => initeqstr &
Dump.select_string(noinitalg,"","initial algorithm\n") => initalgstr &
Dump.select_string(noeq,"","equation\n") => eqstr &
Dump.select_string(noalg,"","algorithm\n") => algstr &

Util.string_append_list([s1,initeqstr,s2,initalgstr,s4,eqstr,s3,algstr,s5]) => str
---------------------------
dump_elements_str l => str

Expand Down
12 changes: 6 additions & 6 deletions modeq/doc/manual.tex
Expand Up @@ -328,7 +328,7 @@ \chapter{Functions for Modelica reflection}
end getDisplayUnit;
\end{verbatim}

\func{getMin\emph{variableName, className})}
\func{getMin(\emph{variableName, className})}
Retrieve the min value of the variable named \emph{variableName} in the
class named \emph{className}.

Expand All @@ -342,7 +342,7 @@ \chapter{Functions for Modelica reflection}
end getMin;
\end{verbatim}

\func{getMax\emph{variableName, className})}
\func{getMax(\emph{variableName, className})}
Retrieve the max value of the variable named \emph{variableName} in the
class named \emph{className}.

Expand All @@ -356,7 +356,7 @@ \chapter{Functions for Modelica reflection}
end getMax;
\end{verbatim}

\func{getStart\emph{variableName, className})}
\func{getStart(\emph{variableName, className})}
Retrieve the start value of the variable named \emph{variableName} in the
class named \emph{className}. \emph{\bf{Note:} If the start value is given
as an initial equation, it is currently not retrievable.}
Expand All @@ -371,7 +371,7 @@ \chapter{Functions for Modelica reflection}
end getStart;
\end{verbatim}

\func{getFixed\emph{variableName, className})}
\func{getFixed(\emph{variableName, className})}
Retrieve the fixed value of the variable named \emph{variableName} in the
class named \emph{className}.

Expand All @@ -385,7 +385,7 @@ \chapter{Functions for Modelica reflection}
end getFixed;
\end{verbatim}

\func{getNominal\emph{variableName, className})}
\func{getNominal(\emph{variableName, className})}
Retrieve the nominal value of the variable named \emph{variableName} in the
class named \emph{className}.

Expand All @@ -399,7 +399,7 @@ \chapter{Functions for Modelica reflection}
end getNominal;
\end{verbatim}

\func{getStateSelect\emph{variableName, className})}
\func{getStateSelect(\emph{variableName, className})}
Retrieve the StateSelect value of the variable named
\emph{variableName} in the class named \emph{className}. StateSelect
is defined as (According to the Modelica Language Specification)
Expand Down
41 changes: 41 additions & 0 deletions modeq/dump.rml
Expand Up @@ -51,6 +51,7 @@ module Dump:
relation direction_symbol: Absyn.Direction => string
relation print_exp: Absyn.Exp => ()
relation print_exp_str: Absyn.Exp => string
relation print_code_str: Absyn.Code => string
relation print_component_ref: Absyn.ComponentRef => ()
relation print_component_ref_str : Absyn.ComponentRef => string
relation print_path : Absyn.Path => ()
Expand Down Expand Up @@ -1921,9 +1922,49 @@ relation print_exp_str : Absyn.Exp => string =
------------------------------------
print_exp_str (e as Absyn.RANGE(start,SOME(step),stop)) => s

rule print_code_str(c) => res
--------------------------
print_exp_str ( Absyn.CODE(c)) => res

axiom print_exp_str (_) => "#UNKNOWN EXPRESSION#"

end

relation print_code_str: Absyn.Code => string =

rule print_path_str p => s
---------------------
print_code_str( Absyn.C_TYPENAME(p)) => s

rule print_component_ref_str cr => s
---------------------
print_code_str( Absyn.C_VARIABLENAME(cr)) => s

rule select_string(b,"initial ", "") => s1 &
unparse_equationitem_str_lst (1,eqitems,";\n") => s2 &
Util.string_append_list([s1, "equation ",s2]) => res
------------------------------------------------
print_code_str( Absyn.C_EQUATIONSECTION(b, eqitems)) => res

rule select_string(b,"initial ", "") => s1 &
unparse_algorithm_str_lst (1,algitems,";\n") => s2 &
Util.string_append_list([s1,"algorithm ", s2]) => res
------------------------------------------------
print_code_str( Absyn.C_ALGORITHMSECTION(b, algitems)) => res

rule unparse_element_str(1,elt) => res
------------------------------------------------
print_code_str( Absyn.C_ELEMENT(elt)) => res

rule print_exp_str(exp) => res
------------------------------------------------
print_code_str( Absyn.C_EXPRESSION(exp)) => res

rule unparse_modification_str(m) => res
------------------------------------------------
print_code_str( Absyn.C_MODIFICATION(m)) => res

end

relation print_elseif_str: (Absyn.Exp * Absyn.Exp) list => string =
axiom print_elseif_str ([]) => ""
Expand Down

0 comments on commit 78eb02b

Please sign in to comment.