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

September 4th update - new directions

 
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: Mon Sep 04, 2006 10:08 pm    Post subject: September 4th update - new directions Reply with quote

Contrary to how it may seem, I have not dropped off the edge of the earth!

I was working on writing the standard library functions when I realized that I was dissatisfied with how MiniD was. It was (1) too much like Lua and (2) not object-oriented enough for my tastes.

So I've decided to work in some Squirrel-like classes. This means there are two new datatypes: class, which is the class definition itself, and instance, an instance of a class. I'm borrowing some things from Squirrel in this regard but I'm also trying to keep it D-like.

So here's an example of what you'll be able to do:

Code:
class Foo
{
   x = 0;
   y = 0;
   name = "";

   // 'method' is a function with an implicit "this" parameter.
   // 'constructor' is not a keyword, but is special to the language for class methods.
   method constructor(name, x, y)
   {
      this.name = name;
      this.x = x;
      this.y = y;
   }

   method show()
   {
      writefln("Foo: name = \"", this.name, "\", x = ", this.x, ", y = ", this.y);
   }

   method setX(val)
   {
      this.x = val;
   }

   method setY(val)
   {
      this.y = val;
   }
   
   method setName(val)
   {
      this.name = val;
   }
}

local f = new Foo("foobar", 3, 5);
f:setX(8);
f:show();


And this:

Code:
class Base
{
   method constructor()
   {
      writefln("Base ctor!");
      this:foo();
   }
   
   method foo()
   {
      writefln("Base.foo()!");
   }
}

class Derived : Base
{
   method constructor()
   {
      writefln("Derived ctor!");
      
      // Hmm.
      super(this).constructor(this);
   }
   
   method foo()
   {
      writefln("Derived.foo()!");
   }
}

/*
writes:

Base ctor!
Base.foo()!
*/
local b = new Base();

/*
writes:

Derived ctor!
Base ctor!
Derived.foo()!
*/
local d = new Derived();

// A downcast - prints null, since b is not a Derived
writefln(typeof(b as Derived));


And then I thought of a new datatype which might be useful:

Code:
class Foo
{
   x = 5;

   method bar()
   {
      writefln("x = ", this.x);
   }
}

local f = new Foo();
local d = delegate f:bar;

// writes "x = 5"
d();


The "delegate f:bar" expression is similar to "&f.bar" in D; that is, it creates a bound delegate with f as the context.

Because of this shift towards a more object-oriented nature, some other features will be changed or dropped. Namely, tables will lose some functionality, especially relating to metatables (metatables will now mostly be per-type, instead of per-table and per-type).

In addition, it's not very influential from the user's point of view, but I've changed the VM instruction format. Instead of a 32-bit, 6-8-9-9 format, it's now a 64-bit, 8-8-16-16-16 format. That is, 8-bit opcode, 8 bits of reserved (don't know what I'll do with it but it could be interesting), 16-bit dest and two 16-bit sources. And of course, the 16-bit sources can be made into a 32-bit signed or unsigned immediate. I mostly did this because I wanted more opcodes, since I might be needing several for the class and delegate stuff, especially depending on how complex I make it. And maybe for the op= ops too; or maybe that's what the reserved field could be for!

So yes, things are happening Smile
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