Implementing This

I am currently teaching the interpreter how to handle evaluation of this. While this is an intuitive concept, its correct implementation results in quite some work. The following code snippet,

val r = 
  object
    def outer = this
    def name = "r"
    def u =
      object
        def test = (inner, outer)
        def inner = this
        def name = "u"
      end
  end
val (i, o) = r.u.test
(i.name, o.name)

should evaluate to ("u", "r"). To achieve this, the interpreter converts the above program into something like:

val r = 
  object
    def outer this_a = this_a
    def name = "r"
    def u this_a =
      object
        def test this_b = (inner this_b, outer this_a)
        def inner this_b = this_b
        def name = "u"
      end
  end
val (i, o) = 
  begin
    val u = r.u r
    u.test u
  end
(i.name, o.name)

Off trying to implement this in a not too messy way …

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: