diff --git a/lang/main.c b/lang/main.c index 059db8b..030511b 100644 --- a/lang/main.c +++ b/lang/main.c @@ -9,7 +9,8 @@ struct object *numA = number_create(5); struct object *numB = number_create(3); struct object *args[] = {numB}; - struct object *numC = dispatch_call(numA, "Add", 1, &args[0]); + dispatch_call(numA, "Add", 1, &args[0]); + struct object *numC = args[0]; printf("numC value is %i\n", number_value(numC)); printf("numA is %p\n", (void *)numA); printf("numB is %p\n", (void *)numB); diff --git a/lang/number.c b/lang/number.c index 3f2dc8f..e5f5f31 100644 --- a/lang/number.c +++ b/lang/number.c @@ -36,8 +36,7 @@ return num->value; } -struct object *number_add( - struct object *obj, int arg_count, struct object **args) { +void number_add(struct object *obj, int arg_count, struct object **args) { abort_if(arg_count != 1, "number_add called with more than 1 argument"); abort_if(!args[0], "number_add arg is NULL"); abort_if(obj->class_data != &num_class, @@ -47,7 +46,7 @@ struct number *numA = (struct number *)obj; struct number *numB = (struct number *)args[0]; int added = numA->value + numB->value; - return number_create(added); + args[0] = number_create(added); } struct object_call calls[] = { diff --git a/lang/number.h b/lang/number.h index 4f3a5d7..376b605 100644 --- a/lang/number.h +++ b/lang/number.h @@ -13,6 +13,6 @@ int number_value(struct object *); // Adds two numbers together -struct object *number_add(struct object *, struct object *); +void number_add(struct object *, struct object *); #endif diff --git a/lang/object.c b/lang/object.c index 62907ad..0995679 100644 --- a/lang/object.c +++ b/lang/object.c @@ -20,12 +20,13 @@ *objptr = NULL; } -struct object *dispatch_call(struct object *obj, const char *name, - int arg_count, struct object **args) { +void dispatch_call(struct object *obj, const char *name, int arg_count, + struct object **args) { struct object_call *call = obj->class_data->calls; while (call->name != NULL) { if (strcmp(call->name, name) == 0) { - return call->handler(obj, arg_count, args); + call->handler(obj, arg_count, args); + return; } ++call; } diff --git a/lang/object.h b/lang/object.h index 2cf37c9..dc4be25 100644 --- a/lang/object.h +++ b/lang/object.h @@ -20,7 +20,7 @@ // Dispatchable object call struct object_call { const char *name; - struct object *(*handler)( + void (*handler)( struct object *obj, int arg_count, struct object **args); }; @@ -36,7 +36,7 @@ void object_drop(struct object **objptr); // Calls a method on an object -struct object *dispatch_call(struct object *obj, const char *name, - int arg_count, struct object **args); +void dispatch_call(struct object *obj, const char *name, int arg_count, + struct object **args); #endif