Basically I want to have dynamic method binding in my language.
I want to have a dynamic type and call the corresponding method. I'm not sure how to use pointers to those methods in assembly since simple labels don't work anymore in the compiler because we can't figure out the dynamic type of an object. A solution would be to have a reference to a vtable where the method pointers are, but I don't how to do that. Thanks in advance.
Here an example: Pseudocode
class Main{
void main() {
A a;
a = new B(); //Dynamic type of is B
a.method(); //should call B's method()
}
}
class A{
method(){}
}
class B extends A{
method(){} //OVERRIDING
}
Pseudoassembly:
Main.main:
...
call POINTERTORIGHTMETHOD #### my proble, how can I ensure now (via vtables that I'm calling the right Method????
....
A.method:
....
....
B.method:
...