FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

February 18th -- Good bye colon syntax!

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sun Feb 18, 2007 10:50 pm    Post subject: February 18th -- Good bye colon syntax! Reply with quote

Added
  • The colon method syntax is GONE! I finally figured out a way to get rid of it that I liked. There are some other nice perks to this: one, it's now possible to reference other class/table members and functions from within class/table functions. Two, the instruction format has been changed, and code that deals with upvalues and globals is much more terse, meaning that there should be a slight speed improvement.

  • To go along with the previous item, 'this' is now a keyword, and every function has an implicit 'this' parameter. For methods, it's the object through which it was called; for most other functions, its the namespace from which the function was called.

  • Added an 'isNamespace' function to the baselib.


Changed
  • The 'method' keyword has been removed. Just replace it with 'function'.

  • Many functions in the array, char, string, and table libraries are now only available by using them as methods of their respective objects. Notable exceptions are array.new and string.join -- they are still accessed with these names, and cannot be accessed as methods through objects.

  • The 'delegate' function in the baselib will now accept just a closure as an argument list. In this case, the context is assumed to be the environment associated with the function. Note that this still doesn't mean you can do something like "delegate(a.foo)" and have it use 'a' as the context. You still have to write "delegate(a.foo, a)".

  • Some API functions have changed. easyCall now takes a third parameter, an MDValue which will be used as the context ('this') for the called function. This is how you call methods. Additionally, there is a new .getContext() method in MDState which returns the context (hidden first parameter) of the function.


Fixed
  • Fixed a bug in namespace lookup that made it possible to access symbols in outer namespaces through inner namespaces, usually causing "WTF" and sometimes causing infinite recursion.

  • Fixed some random bugs in the interpreter that I came across when rewriting some of it. I think there was a small bug with the 'vararg' expression.

  • Fixed a bug in the compiler where class literals crashed the compiler (!!).


The big thing this update is the elimination of the colon syntax for calling methods. Rather than:

obj:method(x);

you now just write:

obj.method(x);

like in most other languages. This seems like a tiny change, but it took a lot of work to implement. Well, maybe not that much work; after I got this working, I wanted to be able to call other member functions from member functions without specifying "this", and came up with an idea to redesign the instruction format, so all that ended up taking quite some time. But now I think it's complete, and it's probably buggy (though it seems to work fine!).

OK, so here are some other things that are now possible:

Code:
global class A
{
   mX;
   mY;

   function constructor(x, y)
   {
      // No more explicit qualification of mX and mY!
      mX = x;
      mY = y;
   }

   function toString()
   {
      return format("A: ", mX, ", ", mY);
   }
}

local a = A(3, 4);
writefln(a);


Note that when you write an unqualified name, like mX, it will first look in the 'this' parameter to the function (this applies to all functions, not just class methods), and then it'll look for it as if it were a global. This means that, just like in D, you might run into a toString situation:

Code:
global class A
{
   function toString()
   {
      return "A!!";
   }
   
   function func()
   {
      return toString(6);
   }
}

local a = A();
writefln(a.func());


This will print 'A!!' instead of the expected '6', because MiniD finds a toString in 'this' before it looks for the global. To solve this, use the hidden _G global:

Code:
   return _G.toString(6);


Of course, if your class defines something called _G, then you're up a creek. I'm thinking of making it possible to write ".toString(6)" as in D, which means "look this up without considering 'this'" -- i.e. start at the global namespace.

I've also considered adding a syntax for calling a function with a specific context, rather than having MiniD figure it out. Notice that the properties demo in simple.md is now using a bit of a hack (the 'me' parameters of all the setters and getters) in order to work. Would be nice if the 'this' parameter could be filled in with the value of 'me'.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group