New fbc branch ('inheritance') on sourceforge (fbc SVN)
New fbc branch ('inheritance') on sourceforge (fbc SVN)
There is a new fb branch at sourceforge. It's a branch aiming to implement inheritance. It's code written by v1ctor. He's committing sizeable chucks of source code to SVN.
This is more like a 'news' item but I think it's news that must not go unnoticed. I for one am very interested in the way inheritance is going to get implemented.
This is more like a 'news' item but I think it's news that must not go unnoticed. I for one am very interested in the way inheritance is going to get implemented.
And v1ctor is moving fast. There is an example in SVN (in the trunk) of how to use inheritance:
As it says in the fbc svn: it's WIP. Perhaps inheritance will be done by the time the next fbc version gets released.
Code: Select all
type Foo
declare function DoSomething() as integer
declare function DoIt() as integer
declare function DoItFromBase() as integer
private:
dim unused as byte
end type
function Foo.DoSomething() as integer
return 1
end function
function Foo.DoIt() as integer
return DoSomething()
end function
function Foo.DoItFromBase() as integer
return DoSomething()
end function
type SuperFoo extends Foo
declare function DoSomething() as integer
declare function DoIt() as integer
end type
function SuperFoo.DoSomething() as integer
return 2
end function
function SuperFoo.DoIt() as integer
return DoSomething()
end function
sub main
dim as SuperFoo inst
assert( inst.DoIt() = 2 )
assert( cast( Foo, inst ).DoIt() = 1 )
assert( inst.DoItFromBase() = 1 )
print "all tests ok"
end sub
main
I think inheritance is almost done.
I've yet to write tests to add to the compiler's test suite, plus try to rebuild the compiler using the new version.
There are some warnings with -gen gcc that i've to fix.
Support for abstract methods should come next. Then we could make a new release.
Polymorphism will probably be left to be added in a future release.
I've yet to write tests to add to the compiler's test suite, plus try to rebuild the compiler using the new version.
There are some warnings with -gen gcc that i've to fix.
Support for abstract methods should come next. Then we could make a new release.
Polymorphism will probably be left to be added in a future release.
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California
-
- Posts: 1009
- Joined: Jul 14, 2005 23:41
In my limited testing inheritance is very nearly there, I made a simple example for testing:
running that with last nights build results in the Animal class proc getting called, but it does compile and run, but polymorphism is definitely kind of borked atm. Great start though, really good to see work being done. I'll take a look at what the changes entail to see if I can help as well.
That code produces this warning from the linker as well:
Code: Select all
type Animal
declare sub preferredAction()
declare constructor( byval numlegs as integer = 0 )
as integer legs
as integer onlyAnimal
end type
type Dog extends Animal
declare sub preferredAction()
declare constructor()
end type
type Cat extends Animal
declare sub preferredAction()
declare constructor()
end type
constructor Animal( byval numlegs as integer = 0 )
legs = numlegs
onlyAnimal = 1
end constructor
sub Animal.preferredAction()
print "Florble."
end sub
constructor Dog ()
legs = 4
onlyAnimal = 0
end constructor
sub Dog.preferredAction()
print "Rub Belly!"
end sub
constructor Cat ()
legs = 4
end constructor
sub Cat.preferredAction()
print "Feed me and leave me alone."
end sub
sub animalAction( byref x as Animal )
x.preferredAction()
end sub
scope 'main
var d = Dog()
var c = Cat()
animalaction(d) : print d.onlyAnimal; : print d.legs;
animalaction(c) : print c.onlyAnimal; : print c.legs;
cast(Animal, d).preferredAction()
end scope
That code produces this warning from the linker as well:
May be an issue with latest mingw. Binutils is ver 2.21, GCC is 4.5.2Warning: .drectve `-aligncomm:"___CTOR_LIST__",2 ' unrecognized
Warning: .drectve `-aligncomm:"___DTOR_LIST__",2' unrecognized
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California
In my GUI system I attempted I used function pointers to simulate polymorphism and it worked fine. It is not as seamless as virtual functions, but workable. I also used function pointers for the event system which worked quite well.v1ctor wrote:There's no polymorphism, you would have to declare the methods as virtual to that work as expected.
The real problem was that with the containment model we have now, you have to manually expose each level of containment, which gets unmanageable very quickly.