Skip to content

Commit

Permalink
Updated object and INVOKE function.
Browse files Browse the repository at this point in the history
Merge pull request #59 from ax-6/main
  • Loading branch information
ax-6 authored Oct 2, 2024
2 parents 6c5aa0c + 224229e commit 3bab2a6
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions prototype/prototype.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
typedef struct {
size_t size;
size_t* index;
} Object;
} InternalObject;

typedef void (*func_ptr)(Object, Object);
typedef void (*func_ptr)(InternalObject, size_t);

struct Pair {
char* first;
Expand Down Expand Up @@ -543,7 +543,7 @@ void* Get4Parament(void* ptr, size_t* first, size_t* second, size_t* third,
return ptr;
}

int INVOKE(size_t* func, Object return_value, Object args);
int INVOKE(size_t* func, size_t return_value, InternalObject args);

void* GetUnknownCountParamentAndINVOKE(void* ptr, size_t* return_value,
size_t* arg_count) {
Expand All @@ -570,8 +570,6 @@ void* GetUnknownCountParamentAndINVOKE(void* ptr, size_t* return_value,
++size;
}

Object return_obj = {1, return_value};

state = 0;
size = 0;
while (state == 0) {
Expand All @@ -583,7 +581,7 @@ void* GetUnknownCountParamentAndINVOKE(void* ptr, size_t* return_value,
++size;
}

Object args_obj = {*arg_count, NULL};
InternalObject args_obj = {*arg_count, NULL};

size_t* args = malloc(*arg_count * sizeof(size_t));

Expand All @@ -604,7 +602,7 @@ void* GetUnknownCountParamentAndINVOKE(void* ptr, size_t* return_value,

args_obj.index = args;

INVOKE(&func, return_obj, args_obj);
INVOKE(&func, *return_value, args_obj);

free(args);

Expand Down Expand Up @@ -1983,7 +1981,7 @@ int CMP(size_t result, size_t opcode, size_t operand1, size_t operand2) {
}
return 0;
}
int INVOKE(size_t* func, Object return_value, Object args) {
int INVOKE(size_t* func, size_t return_value, InternalObject args) {
func_ptr invoke_func = GetFunction((char*)GetPtrData(*func));
invoke_func(args, return_value);
return 0;
Expand All @@ -1995,8 +1993,8 @@ void* GOTO(void* ptr, size_t offset) {
int THROW() { return 0; }
int WIDE() { return 0; }

void print(Object args, Object return_value) {
SetIntData(*return_value.index, printf((char*)GetPtrData(*args.index)));
void print(InternalObject args, size_t return_value) {
SetIntData(return_value, printf((char*)GetPtrData(*args.index)));
}

unsigned int hash(const char* str) {
Expand Down Expand Up @@ -2256,4 +2254,4 @@ int main(int argc, char* argv[]) {
printf("Elapsed time: %f seconds\n", elapsedTime);*/

return 0;
}
}

0 comments on commit 3bab2a6

Please sign in to comment.