KAYLukas / FoxyC

Adds class-oriented syntaxis to C, by using macro's only.
0 stars 0 forks source link

Implement instance calls #2

Open KAYLukas opened 10 years ago

KAYLukas commented 10 years ago

We need to implement methods on specific objects. These methods should overloadable, therefore a pretty simple VTable can be used at the end of the class struct. The macro mapping should be something along the way of:

Tree *t = ...
Node *n = foxy(t $ getLowestElement());

Maps in:

Tree *t = ...
Node *n = ({
                  _FoxyC_SyntaxLogic_Runtime_Push_ObjectScope(t);
                  result = t->class->getLowestElement();
                  _FoxyC_SyntaxLogic_Runtime_Pop_ObjectScope(t);
                  return result;
                  });

It would be better to chain them with tertiary operators instead of this more readable version, as tertiary operators are standard C.

So basically next to the macro we also need to implement a Runtime scope handler. Each file should have its own scope variable 'this', the runtime should set the scope when needed, and the runtime should pop the scope back to its original state. When recursive functions are used, the runtime should just remember the amount of recursions instead of saving the same variable over and over.

KAYLukas commented 10 years ago

Type checking of the class vtable will always ensure type correctness

KAYLukas commented 10 years ago

In case statement expressions do not exist, we should require the given instance to be a lvalue:

    n = n;

ensures the compiler requires this.

KAYLukas commented 10 years ago

8