From 5eda4968c78c5edf2a98b61481e0fe1adedf375f Mon Sep 17 00:00:00 2001 From: AlexVanin Date: Tue, 28 Jan 2014 14:33:26 +0400 Subject: [PATCH] Changed the way CALL works: not it is copy into local variables arguments from stack --- VaninVM/LocalVars.c | 19 +++++++++++++++---- VaninVM/LocalVars.h | 2 ++ VaninVM/Main.c | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) 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)