Skip to content

Commit 2097c58

Browse files
committed
Array constructor added as syntactic sugar. {expr for iter in range} is created
as array(expr for iter in range) in Absyn. Implemented in walker. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1157 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent f8ba2de commit 2097c58

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

modeq/TODO

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ List of things to implement:
5858
implementing them. Some of them are added to the builtin.rml,
5959
some of them not. 15 days.
6060

61-
14. 3.4.3.1 Reduction expressions (Not implemented at all, except
62-
for in Absyn). (See also 3.4.4) 15 days.
61+
14. 3.4.3.1 Reduction expressions (Not implemented at all). (See also 3.4.4) 15 days.
6362

6463
15. Array access with end operator A[end]:=A[end-1];
6564
Array access on the form A[{1,2,3}] (in ceval)
@@ -118,9 +117,16 @@ List of things to implement:
118117

119118
25. Array construction (3.4.4.1). Using array(... for ...)
120119
syntax. Related to 14, should be done after or together with 14.
120+
Partially implemented. Left to do:
121+
* Constant evaluation and/or optimization. Could be implemented
122+
as function calls with index as argument. Or array can be unrolled and indexed, or if
123+
constant value can be calculated and indexed. Array should then be cached.
124+
* Automatic type conversion of element type, e.g. (Real[]) a[5] = {(Integer)3 for ...} fails.
125+
* Handle multiple iterators
121126

122127
26. Array constructors with iterators. Using {expr for i in ...}
123128
syntax. Related to 14 and 25.
129+
Implemented in walker which generates array() call (see 25.).
124130

125131
27. Deduction of ranges (3.3.3.1). It is allowed to leave out "in
126132
range" in loops. e.g.

modeq/absyn.rml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ module Absyn:
256256
| TUPLE of Exp list (*PR.*)
257257
| END
258258
| CODE of Code
259-
| FOR_ITER_EXP of Exp * Ident * Exp
260259

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

modeq/absyn_builder/walker.g

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,11 @@ primary returns [void* ast]
15251525
}
15261526
| #(LBRACE ( (ast = expression_list) { ast = Absyn__ARRAY(ast); }
15271527
| #(FOR_ITERATOR ast = for_iterator)
1528+
{
1529+
/* create an array constructor as a reduction expression */
1530+
/* for unified handling in compiler */
1531+
ast = Absyn__CALL(Absyn__CREF_5fIDENT(mk_scon("array"), mk_nil()),ast);
1532+
}
15281533
))
15291534
| END { ast = Absyn__END; }
15301535
)

0 commit comments

Comments
 (0)