Use more conventional syntax for constructors.

They are now invoked like "new Foo".
Also, superclass constructors are now much less semantically
and syntactically weird. Since the instance is created before
any constructor is called, there's no point in time where the
instance isn't there.
This commit is contained in:
Bob Nystrom
2013-12-19 07:02:27 -08:00
parent b880b17db9
commit 4d67f2270a
30 changed files with 171 additions and 190 deletions
+3 -7
View File
@@ -996,13 +996,9 @@ Value interpret(WrenVM* vm, Value function)
CASE_CODE(NEW):
{
// The current receiver is the class itself.
Value receiver = fiber->stack[frame->stackStart];
Value instance = wrenNewInstance(vm, AS_CLASS(receiver));
// Store the new instance back in the receiver slot so that now it can be
// "this" in the body of the constructor and returned by it.
fiber->stack[frame->stackStart] = instance;
// TODO: Handle object not being a class.
ObjClass* classObj = AS_CLASS(POP());
PUSH(wrenNewInstance(vm, classObj));
DISPATCH();
}