Tangent: Mix-ins Part 1

Published August 07, 2008
Advertisement
Fixed the bug in the op-constraints. I must've written them while sleepy, because I made the op-constraint object a mutable class. Things that get bound with types need to be immutable (and you get a new type back). This led to problems when I ran two in a row (in this case, assignment). I would bind the two types to the op constraint, and it'd check them as passed. I would bind the next two types, but there was no type-parameters left to bind to, they were already filled! So when it went to check, it saw the old 2 params, and passed that along too.

Oops. They're now nicely immutable little things that return new things when bound with types.


I decided in the past few days that the name collision and inheritance cleanup needs three parts. Part one will be converting the mix-in operator from working on well-defined types to the half-defined types during compilation. Part two will be converting type comparison to the half-defined types available at compilation. Part three will be auto-generating new types for inherited member-methods.

That will allow (respectively):

- name collisions to be resolvable for cases where the types are identical. Abstract and virtual and initializer resolution should work.

- name collisions to be resolvable (or less punt-able at least) where the types are not identical. There's likely to be some cases where it's indeterminable. This is going to be the hardest part.

- methods -> method groups, virtual dispatch, snazzy stuff.


I got part one done tonight, which also included a mechanism for block comparison and some cleanup on the built-in types. Example!:

public class bar{	public int x = 4;}public class foo:bar{	public virtual int x = 0;	public int x = 4;	public abstract int x;	}public class a{	public virtual string moo = "a";}public class b:a{	public virtual string moo = "b";}public static void main(){	print (new foo).x " \r\n";	print (new b).moo;}


(the multiple declarations per class is odd, but allowed for now. It simulates inheritance, which mechanically adds members from the inheritees to the bottom of the declaration [and are then consolidated to 1 per name])

This code works fine now, printing:
4b


bar::x is consolidated into foo::x since they have the same initializer. foo::x = 4 beats out its brethren because it's not virtual (or abstract). virtual on fields implies that the initializer may be overriden. The second half of the program shows the picking if both parts of the name collision are virtual; the type doing the inheriting (or to the left of the mix operation) wins.
Previous Entry Working Weekend
Next Entry I am going to hell.
0 likes 3 comments

Comments

Mike.Popoloski
Have you made any decisions as to the final output of your language? If you have it compile down to C# or CIL, you get an immediate platform that would allow someone to do useful work. It would be cool to see SlimDX running in Tangent.
August 07, 2008 07:42 AM
Daerax
must the types of virtual fields be aligned?

what if moo for b was an int? Who would get called?
August 07, 2008 07:48 AM
Telastyn
Quote:
Have you made any decisions as to the final output of your language? If you have it compile down to C# or CIL, you get an immediate platform that would allow someone to do useful work. It would be cool to see SlimDX running in Tangent.


No final decisions. At the moment it compiles into an intermediary stage which is run. Easy to debug. Compiling down to C# or CIL is an option that might be invoked due to speed or interop concerns.

I will be implementing .NET importing at the very least so that SlimDX and the such can be usable in Tangent (but not necessarily vice versa). The main problem at the moment is that I don't have all of .NET stuff working yet (properties, delegates, events, generics, exceptions) so while doing reflection on a class to import it, what do I do if I encounter something like that?

I probably will just not expose it for the time being. But yeah, .NET imports are quickly becoming more and more important.

Quote:
what if moo for b was an int? Who would get called?


You would get a compile time error. Type mismatch. If moo for b was a subtype of string, it would depend on the initializer. You'd either get the subtype or a compile time error (eventually. currently, the code gives you an error if the types are in any way not equivalent regardless of the initializer).
August 07, 2008 08:07 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement