ooc

Separate structure allocation and constructors

Registered by Amos Wenger

Currently constructors are translated to things like:

struct Object* Object__new() {
  struct Object* this = malloc(sizeof(struct Object));
  // do stuff with this
  return this;
}

And super/this constructor calls are handled by copying code from super/this cosntructors into the caller. This leads to code duplication and should be avoided by splitting memory allocation and constructor calling, e.g.

Thing t = new Thing();

Would generate code

struct Thing* t = malloc(sizeof(struct Thing));
Thing__new(t);

This approach has several advantages: avoid code duplications in constructors, ie.:

void Thing__new(struct Thing* this) {
  SuperClass__new(this);
}

It also allows calling constructors not only at the beginning but anywhere in a constructor.

Blueprint information

Status:
Not started
Approver:
Amos Wenger
Priority:
Undefined
Drafter:
Amos Wenger
Direction:
Needs approval
Assignee:
Amos Wenger
Definition:
Approved
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.