diff --git a/VaninVM/LocalVars.c b/VaninVM/LocalVars.c index 21e5a83..9c8eeec 100644 --- a/VaninVM/LocalVars.c +++ b/VaninVM/LocalVars.c @@ -1,5 +1,6 @@ #include #include "LocalVars.h" +#include "TOS.h" long long getlocal_int(context* cont, int id) { @@ -24,16 +25,26 @@ char* getlocal_string(context* cont, int id) void putlocal_int(long long* num, context* cont, int id) { - //memcpy(((long long*)cont->locals)+id, num, sizeof(long long)); - memcpy((cont->locals)+id, num, sizeof (long long)); + memmove((cont->locals)+id, num, sizeof (long long)); } void putlocal_double(double* num, context* cont, int id) { - memcpy((cont->locals)+id, num, sizeof(double)); + memmove((cont->locals)+id, num, sizeof(double)); } void putlocal_string(char* str, context* cont, int id) { - memcpy((cont->locals)+id, str, sizeof(int*)); + memmove((cont->locals)+id, str, sizeof(int*)); +} + +void args_to_local(context* cont, func** hash) +{ + int i; + long long tmp; + for (i=(hash[cont->id]->count_args)-1; i>=0; i--) + { + tmp = pop_int(); + memmove(&((cont->locals)[i]), &tmp, sizeof(long long)); + } } diff --git a/VaninVM/LocalVars.h b/VaninVM/LocalVars.h index 581a0db..7853c3c 100644 --- a/VaninVM/LocalVars.h +++ b/VaninVM/LocalVars.h @@ -9,4 +9,6 @@ char* getlocal_string(context*, int); void putlocal_int(long long*, context*, int); void putlocal_double(double*, context*, int); void putlocal_string(char*, context*, int); + +void args_to_local(context*, func**); #endif \ No newline at end of file diff --git a/VaninVM/Main.c b/VaninVM/Main.c index 6523a96..71cb5ef 100644 --- a/VaninVM/Main.c +++ b/VaninVM/Main.c @@ -582,6 +582,7 @@ int main(int argc, char** argv) ip+=2; push_ret(ip); push_context(current_context); current_context = create_context(s1, phash_table, &code); + args_to_local(current_context, phash_table); ip = 0; break; case RETURN: //DO(RETURN, "Return to call location", 1)