0

For a class declaration like (using a dynamically typed language I am develop):

class Foo
{
    var bar
    {
       get { return bar; }
       set(value) { bar = value; }
    }
}

User can the write something like:

var f = New Foo();
f.bar = 20;
var n = f.bar;

The compiler then will convert f.bar = 20 to a setter call and n = f.bar in a getter call. What could be an efficient runtime representation of the setter/getter functions inside the Foo class?

Should the compiler decide to use to setter ONLY based on the fact that f.bar is used in an assignment expression?

Seki
  • 11,135
  • 7
  • 46
  • 70
Marco
  • 783
  • 5
  • 21
  • 1
    Are you interpreting your own language in C, as it seems so from your other questions and the tags in your question. Please update the question accordingly. – dmg Jan 19 '15 at 15:34
  • this might be C#, it doesn't quite look like C++. – YoungJohn Jan 19 '15 at 15:35
  • I modified the question, it is a dynamically typed language I am developing. – Marco Jan 19 '15 at 15:37
  • I am developing a dynamically typed language and a virtual machine, my question about how the compiler should decide about when to use the setter method and what could be an efficient runtime representation of the setter/getter methods is a generic question not related to the language used in the examples. – Marco Jan 19 '15 at 15:56
  • Did you really mean to write dynamically *scoped* in the question? Note that this is **not the same thing** as a dynamically *typed* language! – Martin Törnwall Jan 19 '15 at 16:38
  • 1
    Sorry my fault, I meant dynamically typed (original post fixed). – Marco Jan 19 '15 at 16:45
  • 1
    If this is dynamically typed then how can you tell the type of `f` at compile time (which is required to determine the correct getter/setter)? – arshajii Jan 19 '15 at 16:50
  • 1
    But the question is about how to accomplish this efficiently at *runtime*. It is clearly not possible at compile time. – Martin Törnwall Jan 19 '15 at 17:39

0 Answers0