Mixins can have static methods, non-virtual methods, virtual methods, or abstract methods. I don't have some of the sophisticated error checking we discussed (such that if there is ambiguity in what should be inherited you have to explicitly override the method).
They basically work right now, but there are a couple tasks I have left to do:
Finishing tying mixins into type checking
Mixins parameter defaults
Mixin reflection
Mixins with natives?
brianSat 25 Mar 2006
I added support for mixin type checking. A key design decision I made was that mixins act like they inherit from Obj. This means you can use a variable typed as a mixin where an Obj is expected. Likewise you can call Obj methods like type() or toStr() on a variable typed as mixin.
Of course the JVM doesn't like that all since it sees an interface type on the stack which doesn't actually implement Obj (since Obj is a class not an interface). So I fixed this at the compiler level by inserting an Obj cast where ever an mixin (interface) was being used as an Obj.
In Fan reflection it means mixins look like they extend Obj and implement all it's methods:
I wrapped up the mixin feature with support for default parameters. I also flushed out the test suite and fixed a couple other obscure bugs. I think mixins are basically done for now. I still need to add a bunch of error checking to the compiler - but I'm going to wait until for rewrite for that.
brianMon 5 Jun 2006
I really want to add field support to mixins - so far I've wanted that everytime I've used a mixin. But it's a pretty big feature so I want to wait and only do it once in the Fan version of the compiler.
In the meantime I added a feature which is almost just as good. A field may be used to "implement" an abstract method which matches its getter:
mixin Foo
{
abstract Str name()
}
class Bar mixin Foo
{
Str name := "unnamed"
}
The compiler will stay happy and not complain because although Bar.name is a field, it results in a getter method that will satisfy the contract of Foo.name. Same principle applies if Foo is an abstract class.
brianSat 24 Jun 2006
I added support for static fields to mixins. I created four new opcodes:
LoadMixinInstance 2 (field) // load field on mixin from storage
StoreMixinInstance 2 (field) // store field on mixin to storage
LoadMixinStatic 2 (field) // load static on mixin field from storage
StoreMixinStatic 2 (field) // store static on mixin field to storage
The instance field accessor opcodes aren't used yet.
brian Tue 21 Mar 2006
I checked in initial support for mixins.
The fcode format is enhanced slightly:
There are two new opcodes for invoking a mixin method:
The best way to understand my Java implementation is via a simple example. Consider this Fan code:
Compiles to the the following fcode:
Notice the use of CallMixinStatic and CallMixinVirtual. This basically emits to the following Java:
Mixins can have static methods, non-virtual methods, virtual methods, or abstract methods. I don't have some of the sophisticated error checking we discussed (such that if there is ambiguity in what should be inherited you have to explicitly override the method).
They basically work right now, but there are a couple tasks I have left to do:
brian Sat 25 Mar 2006
I added support for mixin type checking. A key design decision I made was that mixins act like they inherit from Obj. This means you can use a variable typed as a mixin where an Obj is expected. Likewise you can call Obj methods like type() or toStr() on a variable typed as mixin.
Of course the JVM doesn't like that all since it sees an interface type on the stack which doesn't actually implement Obj (since Obj is a class not an interface). So I fixed this at the compiler level by inserting an Obj cast where ever an mixin (interface) was being used as an Obj.
In Fan reflection it means mixins look like they extend Obj and implement all it's methods:
Outputs:
brian Sun 26 Mar 2006
I wrapped up the mixin feature with support for default parameters. I also flushed out the test suite and fixed a couple other obscure bugs. I think mixins are basically done for now. I still need to add a bunch of error checking to the compiler - but I'm going to wait until for rewrite for that.
brian Mon 5 Jun 2006
I really want to add field support to mixins - so far I've wanted that everytime I've used a mixin. But it's a pretty big feature so I want to wait and only do it once in the Fan version of the compiler.
In the meantime I added a feature which is almost just as good. A field may be used to "implement" an abstract method which matches its getter:
The compiler will stay happy and not complain because although Bar.name is a field, it results in a getter method that will satisfy the contract of Foo.name. Same principle applies if Foo is an abstract class.
brian Sat 24 Jun 2006
I added support for static fields to mixins. I created four new opcodes:
The instance field accessor opcodes aren't used yet.