keriwarr / orangejoos

JOOS1W Compiler, written in Crystal
0 stars 1 forks source link

add object init and field handling #87

Closed lgo closed 6 years ago

lgo commented 6 years ago

To support these features, the following has been added:

In the constructor body, the first action that happens is the space for the instance layout is allocated with malloc. After that, a field initialization function is called which will execute all of the field initializers, in order. This is because fields can have arbitrary expressions within them. After all of this, the remainder of the constructor is run.

Hereon out, the register ESI is dedicated to storing this for the purposes of constructors and instance methods. Hence, any implicit or explicit reference to this is simply accessing the ESI register.

Constructor calling is done in the same manner as method invocation, where a safe call is made that does a backup and restore of the method context. This now includes the ESI register.

A class, ClassInstance, is created for building interfaces codegen will use involving an instance. In particular, it is tracking the layout of the object in memory.

Using the ClassInstance, addressing and value fetching for fields was added.