diff --git a/lang/main.c b/lang/main.c index 2ad9fea..00bcf26 100644 --- a/lang/main.c +++ b/lang/main.c @@ -40,7 +40,14 @@ } struct object; -typedef struct object *(object_call)(struct object*, struct object*); + +#define ARGS_MAX 8 + +typedef struct { + struct object *args[ARGS_MAX]; +} argstack; + +typedef struct object *(object_call)(struct object*, int, argstack*); typedef struct { int symbol; @@ -58,7 +65,12 @@ object *create_object(int value); -object *add_objects(object *objA, object *objB) { +object *add_objects(object *objA, int args, argstack *stack) { + if(args != 1) { + printf("ERROR: wrong arg countnull\n"); + abort(); + } + object *objB = stack->args[0]; if(objB == NULL) { printf("ERROR: objA is null\n"); abort(); @@ -94,12 +106,12 @@ *objptr = NULL; } -object *dispatch_call(object *obj, int sym, object *arg1) { +object *dispatch_call(object *obj, int sym, int args, argstack *stack) { for(int i = 0; i < obj->calls_count; ++i) { call_mapping *curr_call = &obj->calls[i]; int symbol = curr_call->symbol; if(symbol == sym) { - return curr_call->call(obj, arg1); + return curr_call->call(obj, args, stack); } } printf("ERROR: no call found to dispatch\n"); @@ -113,7 +125,9 @@ printf("symb %i\n", find_symbol("b")); object *numA = create_object(5); object *numB = create_object(3); - object *numC = dispatch_call(numA, find_symbol("Add"), numB); + argstack stack; + stack.args[0] = numB; + object *numC = dispatch_call(numA, find_symbol("Add"), 1, &stack); printf("numC value is %i\n", numC->value); printf("numA is %p\n", (void*)numA); printf("numB is %p\n", (void*)numB);