Skip to content

Commit 3ec13e1

Browse files
author
x97davka
committed
Rewrote to not use lform, but put modifications in the environment.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@139 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent da53f7d commit 3ec13e1

File tree

1 file changed

+101
-54
lines changed

1 file changed

+101
-54
lines changed

modeq/inst.rml

Lines changed: 101 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
module Inst:
44

55
with "exp.rml"
6-
with "lform.rml"
6+
with "absyn.rml"
7+
(* with "lform.rml" *)
78
with "dae.rml"
89

9-
relation instantiate: Lform.Program => DAE.DAEform
10+
relation instantiate: Absyn.Program => DAE.DAEform
1011

1112
end
1213

@@ -16,8 +17,10 @@ with "mod.rml"
1617
with "builtin.rml"
1718
with "dump.rml"
1819

20+
(* These make the code a little more readable *)
1921
type Prefix = Prefix.Prefix
20-
22+
type Mod = Mod.Mod
23+
type Ident = Exp.Ident
2124

2225

2326
(**********************************************************************)
@@ -43,7 +46,7 @@ relation inst_connect: (Exp.Exp,Exp.Exp) => DAE.DAEcomp list =
4346

4447
end
4548

46-
relation inst_equation: (Env.Env,Mod.Mod,Prefix,Lform.Equation)
49+
relation inst_equation: (Env.Env,Mod.Mod,Prefix,Absyn.Equation)
4750
=> (DAE.DAEcomp list, Env.Env) =
4851

4952
(* connect
@@ -54,7 +57,7 @@ relation inst_equation: (Env.Env,Mod.Mod,Prefix,Lform.Equation)
5457
rule inst_connect(o1,o2) => l
5558
------------------------
5659
inst_equation(env,mods,pre,
57-
Lform.EQ_EXPR(Exp.CALL(Exp.IDENT("connect"),[o1,o2])))
60+
Absyn.EQ_EXPR(Exp.CALL(Exp.IDENT("connect"),[o1,o2])))
5861
=> (l,env)
5962

6063
(* assert
@@ -67,24 +70,43 @@ relation inst_equation: (Env.Env,Mod.Mod,Prefix,Lform.Equation)
6770
print d & print "\n"
6871
------------------------
6972
inst_equation(env,mods,pre,
70-
Lform.EQ_EXPR(Exp.CALL(Exp.IDENT("assert"),
73+
Absyn.EQ_EXPR(Exp.CALL(Exp.IDENT("assert"),
7174
[e,Exp.STRING(d)])))
7275
=> ([],env)
7376

7477
rule print "No expression equations yet\n" & fail
7578
--------------------------------------------
76-
inst_equation(env,mods,pre,Lform.EQ_EXPR(_)) => ([],env)
79+
inst_equation(env,mods,pre,Absyn.EQ_EXPR(_)) => ([],env)
7780

7881
rule print " equation\n" &
7982
Prefix.prefix_exp(e1,pre) => e1' &
8083
Prefix.prefix_exp(e2,pre) => e2'
8184
------------------------
82-
inst_equation(env,mods,pre,Lform.EQ_EQUALS(e1,e2)) =>
85+
inst_equation(env,mods,pre,Absyn.EQ_EQUALS(e1,e2)) =>
8386
([DAE.EQUATION(Exp.RELATION(e1',Exp.EQUAL,e2'))],env)
8487

8588
end
8689

87-
relation inst_element: (Env.Env,Mod.Mod,Prefix,Lform.Element)
90+
relation inst_mod_assignment : (Prefix, Ident, Mod) => DAE.DAEcomp list =
91+
92+
rule Prefix.prefix_path(Exp.IDENT(v), pre) => v' &
93+
94+
Exp.path_string(v') => vn &
95+
print " assignment modification: " & Mod.dump(mod, vn) &
96+
print "\n" &
97+
98+
Prefix.prefix_exp(e, pre) => e'
99+
-------------------------------
100+
inst_mod_assignment(pre,v,mod as Mod.MOD(_,_,SOME(e)))
101+
=> [DAE.EQUATION(Exp.RELATION(Exp.PATH(v'), Exp.EQUAL, e'))]
102+
103+
rule print "FOO\n"
104+
-----------------
105+
inst_mod_assignment(_,_,_) => []
106+
107+
end
108+
109+
relation inst_element: (Env.Env, Mod.Mod, Prefix, Absyn.Element)
88110
=> (DAE.DAEcomp list, Env.Env) =
89111

90112
(* extends
@@ -93,15 +115,24 @@ relation inst_element: (Env.Env,Mod.Mod,Prefix,Lform.Element)
93115
* of the extended class.
94116
*)
95117

96-
rule Env.lookup_class(env,cn) => c &
97-
Mod.merge(SOME(mods),SOME(Lform.CLASSMOD(m))) => mods' &
98-
Mod.simple_maybe_modify_class(env,mods',pre,c)
99-
=> (Lform.CLASS(n,_,r,d), dae1) &
118+
rule Env.lookup_class(env,cn) => (Absyn.CLASS(_,partial,restr,d),classmod) &
119+
120+
(* Can't extend partial classes *)
121+
partial = false &
122+
123+
(* Build the combind set of modifications *)
124+
(* FIXME: verify order *)
125+
Mod.build(SOME(Absyn.CLASSMOD(m)), false) => mod2 &
126+
Mod.merge(mods,mod2) => mods' &
127+
Mod.merge(mods',classmod) => mods'' &
128+
129+
(*Mod.simple_maybe_modify_class(env,mods',pre,c) *)
130+
(* => (Absyn.CLASS(n,_,r,d), dae1) & *)
131+
100132
(* Can't use inst_class, as that creates a new frame *)
101-
inst_classdef(env,mods,pre,d) => (dae2,env') &
102-
list_append(dae1,dae2) => dae
133+
inst_classdef(env,mods'',pre,d) => (dae,env')
103134
----------------------------------
104-
inst_element(env,mods,pre,Lform.ELEMENT(_,_,Lform.EXTENDS(cn,m)))
135+
inst_element(env,mods,pre,Absyn.ELEMENT(_,_,Absyn.EXTENDS(cn,m)))
105136
=> (dae,env')
106137

107138
(* components
@@ -114,7 +145,7 @@ relation inst_element: (Env.Env,Mod.Mod,Prefix,Lform.Element)
114145
print " ignoring shadowed variable " & print n & print "\n"
115146
--------------------------
116147
inst_element(env,mods,pre,
117-
Lform.ELEMENT(_,n,Lform.COMPONENT(_,_,_,_,_,_,_,_,_)))
148+
Absyn.ELEMENT(_,n,Absyn.COMPONENTS(_,_,_,_,_,_,_)))
118149
=> ([],env)
119150

120151
(* Illegal redeclarations *)
@@ -123,31 +154,31 @@ relation inst_element: (Env.Env,Mod.Mod,Prefix,Lform.Element)
123154
print " as a variable\n" &
124155
fail
125156
------------------------
126-
inst_element(env,mods,pre,Lform.ELEMENT(_,n,Lform.CLASSDEF(_,_)))
157+
inst_element(env,mods,pre, Absyn.ELEMENT(_,n,Absyn.CLASSDEF(_,_)))
127158
=> ([],env)
128159

129-
rule Env.lookup_class(env,Exp.IDENT(n)) => v &
160+
rule Env.lookup_class(env,Exp.IDENT(n)) => (v,_) &
130161
print "Trying to redeclare the variable " & print n &
131162
print " as a class\n" &
132163
fail
133164
------------------------
134165
inst_element(env,mods,pre,
135-
Lform.ELEMENT(_,n,Lform.COMPONENT(_,_,_,_,_,_,_,_,_)))
166+
Absyn.ELEMENT(_,n,Absyn.COMPONENTS(_,_,_,_,_,_,_)))
136167
=> ([],env)
137168

138169
(* A new class definition
139170
*
140171
* Put it in the current frame in the environment
141172
*)
142173

143-
rule Lform.convert(c) => c' &
144-
Mod.lookup_modification(mods,n) => mm &
145-
Mod.simple_maybe_modify_class(env,mm,pre,c') => (c'',dae) &
146-
Env.extend_frame_c(env,c'') => env'
174+
rule (* Absyn.convert(c) => c' & *)
175+
Mod.lookup_modification(mods,n) => classmod &
176+
(* Mod.simple_maybe_modify_class(env,mm,pre,c') => (c'',dae) & *)
177+
Env.extend_frame_c(env,c,classmod) => env'
147178
----------------------------------------
148179
inst_element(env,mods,pre,
149-
Lform.ELEMENT(_,n,Lform.CLASSDEF(_,c)))
150-
=> (dae,env')
180+
Absyn.ELEMENT(_,n,Absyn.CLASSDEF(_,c)))
181+
=> ([],env')
151182

152183
(* A variable
153184
*
@@ -161,97 +192,113 @@ relation inst_element: (Env.Env,Mod.Mod,Prefix,Lform.Element)
161192
Exp.path_string(vn) => ns &
162193
print " variable " & print ns & print "\n" &
163194

164-
Env.lookup_class(env,t) => cl &
195+
(* FIXME: merge order *)
196+
Env.lookup_class(env,t) => (cl,classmod) &
197+
Mod.merge(mods,classmod) => mods' &
165198

166199
(* Exp.path_string(t) => ts & *)
167200
(* print " class " & print ts & print " found\n" & *)
168201

169202
(* Find the set of modifications *)
170-
Mod.lookup_modification(mods,n) => mm &
171-
Mod.merge(mm,m) => m' &
203+
Mod.lookup_modification(mods(*'*),n) => mm &
204+
Mod.build(m,final) => m' &
205+
Mod.merge(mm,m') => mm'' &
206+
print " modification: " & Mod.dump(mm'',ns) & print "\n" &
172207

173208
Prefix.prefix_add(n,pre) => pre' &
174209

175-
Mod.maybe_modify_class(env,vn,m',pre',cl) => (cl',dae1) &
210+
(* Mod.maybe_modify_class(env,vn,m'',pre',cl) => (cl',dae1) & *)
176211

177212
(* print " modified\n" & *)
178213

179-
Env.extend_frame_v(env,Env.FRAMEVAR(n,ad,cl',f,p,c,i,o)) => env' &
214+
Env.extend_frame_v(env,Env.FRAMEVAR(n,ad,cl,f,p,c,i,o)) => env' &
215+
216+
print " added\n" &
180217

181-
(* print " added\n" & *)
218+
inst_class(env,mm'',pre',cl) => dae1 &
182219

183-
inst_class(env,Mod.empty_mod,pre',cl') => dae2 &
184-
list_append(dae1,dae2) => dae
220+
print " BAR\n" &
221+
222+
(* If the modification assigns a value to this variable, add an
223+
equation *)
224+
inst_mod_assignment(pre,n,mm'') => dae2 &
225+
226+
list_append(dae1, dae2) => dae
185227
--------------------------
186228
inst_element(env,mods,pre,
187-
Lform.ELEMENT(_,_,Lform.COMPONENT(f,p,c,i,o,t,n,ad,m)))
229+
Absyn.ELEMENT(final,_,Absyn.COMPONENTS(f,p,c,i,o,t,
230+
[Absyn.COMPONENT(n,ad,m)])))
188231
=> (dae,env')
189232

190233
(*
191234
* If the class lookup in the previous rule fails, this rule catches
192235
* the error and prints an error message about the unknown class.
193236
*)
194237

195-
rule not Env.lookup_class(env,t) => cl &
238+
rule not Env.lookup_class(env,t) => (cl,_) &
196239
Exp.path_string(t) => s &
197240
print "# unknown class '" & print s & print "' while instantiating " &
198241
Prefix.prefix_path(Exp.IDENT(n),pre) => n' &
199242
Exp.path_string(n') => ns &
200243
print ns & print "\n"
201244
--------------------------
202245
inst_element(env,_,pre,
203-
Lform.ELEMENT(_,_,Lform.COMPONENT(_,_,_,_,_,t,n,_,_)))
246+
Absyn.ELEMENT(_,n,Absyn.COMPONENTS(_,_,_,_,_,t,_)))
204247
=> ([],env)
205248

206249
end
207250

208-
and inst_classpart: (Env.Env,Mod.Mod,Prefix,Lform.ClassPart)
251+
and inst_classpart: (Env.Env,Mod.Mod,Prefix,Absyn.ClassPart)
209252
=> (DAE.DAEcomp list,Env.Env) =
210253

211254
rule inst_list(env,mods,pre,inst_element,l) => (dae,env')
212255
-------------------------------------------
213-
inst_classpart(env,mods,pre,Lform.PUBLIC(l)) => (dae,env')
256+
inst_classpart(env,mods,pre,Absyn.PUBLIC(l)) => (dae,env')
214257

215258
rule inst_list(env,mods,pre,inst_element,l) => (dae,env')
216259
-------------------------------------------
217-
inst_classpart(env,mods,pre,Lform.PROTECTED(l)) => (dae,env')
260+
inst_classpart(env,mods,pre,Absyn.PROTECTED(l)) => (dae,env')
218261

219262
rule print "No algorithms yet\n" & fail
220263
----------------------------------
221-
inst_classpart(env,mods,pre,Lform.ALGORITHMS(l)) => ([],env)
264+
inst_classpart(env,mods,pre,Absyn.ALGORITHMS(l)) => ([],env)
222265

223266
rule inst_list(env,mods,pre,inst_equation,el) => (dae,el')
224267
------------------------------------
225-
inst_classpart(env,mods,pre,Lform.EQUATIONS(el)) => (dae,el')
268+
inst_classpart(env,mods,pre,Absyn.EQUATIONS(el)) => (dae,el')
226269

227270
end
228271

229-
and inst_classdef: (Env.Env,Mod.Mod,Prefix,Lform.ClassDef)
272+
and inst_classdef: (Env.Env, Mod.Mod, Prefix, Absyn.ClassDef)
230273
=> (DAE.DAEcomp list, Env.Env) =
231274

232275
rule inst_list(env,mods,pre,inst_classpart,pl) => (dae,env')
276+
& print "XYZZY\n"
233277
------------------------------------------------
234-
inst_classdef(env,mods,pre,Lform.PARTS(pl)) => (dae,env')
278+
inst_classdef(env,mods,pre, Absyn.PARTS(pl)) => (dae,env')
235279

236280
rule print "DERIVED not handled\n" & fail
237281
------------------------------------
238-
inst_classdef(env,_,_,Lform.DERIVED(_,_,_)) => ([],env)
282+
inst_classdef(env,_,_, Absyn.DERIVED(_,_,_)) => ([],env)
239283
end
240284

241-
and inst_class: (Env.Env,Mod.Mod,Prefix,Lform.Class) => DAE.DAEcomp list =
285+
and inst_class: (Env.Env, Mod, Prefix, Absyn.Class) => DAE.DAEcomp list =
242286

243-
rule (* print " instantiating " & print n & print "\n" & *)
287+
rule print " instantiating " & print n & print "\n" &
244288
Env.new_frame(env) => env' &
245289
inst_classdef(env',mods,pre,d) => (l,_)
246290
------------------------------------------------------
247-
inst_class(env,mods,pre,c as Lform.CLASS(n,false,r,d)) => l
291+
inst_class(env,mods,pre,c as Absyn.CLASS(n,false,r,d)) => l
248292

249293
rule print "Can't instantiate partial class " & print n & print "\n" &
250294
fail
251295
------------------------------------------------------
252-
inst_class(env,mod,pre,Lform.CLASS(n,true,_,_)) => []
296+
inst_class(env,mod,pre, Absyn.CLASS(n,true,_,_)) => []
253297

254-
(* FIXME *)
298+
(* FIXME *)
299+
rule print "# Fallthru in inst_class\n"
300+
----------------------------------
301+
inst_class(_,_,_,_) => []
255302

256303
end
257304

@@ -261,19 +308,19 @@ relation inst_program : (Env.Env, Absyn.Program) => DAE.DAEcomp list =
261308
------------------------------
262309
inst_program(env,[]) => []
263310

264-
rule Env.extend_frame_c(env,c) => env' &
265-
inst_class(env',Mod.empty_mod,[],c') => l
311+
rule Env.extend_frame_c(env,c,Mod.NOMOD) => env' &
312+
inst_class(env',Mod.NOMOD,[],c) => l
266313
-----------------------------
267314
inst_program(env,[c]) => l
268315

269-
rule Env.extend_frame_c(env,c) => env' &
316+
rule Env.extend_frame_c(env,c,Mod.NOMOD) => env' &
270317
inst_program(env',cs) => l
271318
----------------------
272319
inst_program(env,c::cs) => l
273320

274321
end
275322

276-
relation instantiate: Lform.Program => DAE.DAEform =
323+
relation instantiate: Absyn.Program => DAE.DAEform =
277324

278325
rule Builtin.initial_env => env &
279326
inst_program(env,p) => l

0 commit comments

Comments
 (0)