@@ -77,10 +77,10 @@ class Semantic {
77
77
*
78
78
* We need to restrict nesting levels of `outer` to finitize the domain.
79
79
*/
80
- case class Warm (klass : ClassSymbol , outer : Value ) extends Addr
80
+ case class Warm (klass : ClassSymbol , outer : Value , ctor : Symbol , args : List [ Value ] ) extends Addr
81
81
82
82
/** A function value */
83
- case class Fun (expr : Tree , thisV : Addr , klass : ClassSymbol ) extends Value
83
+ case class Fun (expr : Tree , params : List [ Symbol ], thisV : Addr , klass : ClassSymbol , env : Env ) extends Value
84
84
85
85
/** A value which represents a set of addresses
86
86
*
@@ -138,6 +138,32 @@ class Semantic {
138
138
import Heap ._
139
139
val heap : Heap = Heap .empty
140
140
141
+ /** The environment for method parameters */
142
+ object Env {
143
+ opaque type Env = Map [Symbol , Value ]
144
+
145
+ val empty : Env = Map .empty
146
+
147
+ def apply (bindings : Map [Symbol , Value ]): Env = bindings
148
+
149
+ def apply (ddef : DefDef , args : List [Value ])(using Context ): Env =
150
+ val params = ddef.termParamss.flatten.map(_.symbol)
151
+ assert(args.size == params.size, " arguments = " + args.size + " , params = " + params.size)
152
+ params.zip(args).toMap
153
+
154
+ extension (env : Env )
155
+ def lookup (sym : Symbol )(using Context ): Value = env(sym)
156
+
157
+ def getOrElse (sym : Symbol , default : Value )(using Context ): Value = env.getOrElse(sym, default)
158
+
159
+ def union (other : Env ): Env = env ++ other
160
+ }
161
+
162
+ type Env = Env .Env
163
+ def env (using env : Env ) = env
164
+
165
+ import Env ._
166
+
141
167
object Promoted {
142
168
/** Values that have been safely promoted */
143
169
opaque type Promoted = mutable.Set [Value ]
@@ -251,11 +277,21 @@ class Semantic {
251
277
252
278
case (RefSet (refs1), RefSet (refs2)) => RefSet (refs1 ++ refs2)
253
279
280
+ def widen : Value =
281
+ a match
282
+ case RefSet (refs) => refs.map(_.widen).join
283
+ case _ : Addr => Cold
284
+ case Fun (e, params, thisV, klass, env) => Fun (e, params, thisV.widen, klass, env)
285
+ case _ => a
286
+
287
+
254
288
extension (values : Seq [Value ])
255
289
def join : Value =
256
290
if values.isEmpty then Hot
257
291
else values.reduce { (v1, v2) => v1.join(v2) }
258
292
293
+ def widen : List [Value ] = values.map(_.widen).toList
294
+
259
295
extension (value : Value )
260
296
def select (field : Symbol , source : Tree , needResolve : Boolean = true ): Contextual [Result ] =
261
297
value match {
0 commit comments