Reorder the method types.

Seems to slightly improve perf.
This commit is contained in:
Bob Nystrom 2013-12-12 07:39:27 -08:00
parent 4ba5c38bbf
commit 8e71660ce6
2 changed files with 13 additions and 13 deletions

View File

@ -156,9 +156,6 @@ typedef struct
typedef enum typedef enum
{ {
// No method for the given symbol.
METHOD_NONE,
// A primitive method implemented in C that immediately returns a value. // A primitive method implemented in C that immediately returns a value.
METHOD_PRIMITIVE, METHOD_PRIMITIVE,
@ -171,7 +168,10 @@ typedef enum
// A constructor. This will be defined on the metaclass. If [fn] is non-NULL, // A constructor. This will be defined on the metaclass. If [fn] is non-NULL,
// then it's a user-defined constructor and [fn] is the initialization code. // then it's a user-defined constructor and [fn] is the initialization code.
// Otherwise, it's a default constructor. // Otherwise, it's a default constructor.
METHOD_CTOR METHOD_CTOR,
// No method for the given symbol.
METHOD_NONE
} MethodType; } MethodType;
typedef struct typedef struct

View File

@ -673,15 +673,6 @@ Value interpret(WrenVM* vm, Value function)
Method* method = &classObj->methods[symbol]; Method* method = &classObj->methods[symbol];
switch (method->type) switch (method->type)
{ {
case METHOD_NONE:
printf("Receiver ");
wrenPrintValue(receiver);
printf(" does not implement method \"%s\".\n",
vm->methods.names[symbol]);
// TODO(bob): Throw an exception or halt the fiber or something.
exit(1);
break;
case METHOD_PRIMITIVE: case METHOD_PRIMITIVE:
{ {
Value* args = &fiber->stack[fiber->stackSize - numArgs]; Value* args = &fiber->stack[fiber->stackSize - numArgs];
@ -724,6 +715,15 @@ Value interpret(WrenVM* vm, Value function)
LOAD_FRAME(); LOAD_FRAME();
break; break;
} }
case METHOD_NONE:
printf("Receiver ");
wrenPrintValue(receiver);
printf(" does not implement method \"%s\".\n",
vm->methods.names[symbol]);
// TODO(bob): Throw an exception or halt the fiber or something.
exit(1);
break;
} }
DISPATCH(); DISPATCH();
} }