AZHenley / knox

A toy programming language written in Go that compiles to C.
MIT License
96 stars 7 forks source link

Emit fake constructor #149

Closed AZHenley closed 5 years ago

AZHenley commented 5 years ago

Currently, member initializations are being emitted which is not valid C.

struct foobar {
    bool hungry = false;
    int number = 3;
};
...
struct foobar * myobj = malloc(sizeof(struct foobar));

Should be:

struct foobar {
    bool hungry;
    int number;
};
void _foobar(struct foobar* self) {
    hungry = false;
    number = 3;
}
...
struct foobar * myobj = malloc(sizeof(struct foobar));
_foobar(myobj);