Changed the way CALL works: not it is copy into local variables arguments from stack

This commit is contained in:
Alex Vanin 2014-01-28 14:33:26 +04:00
parent 73c63fa7aa
commit 5eda4968c7
3 changed files with 18 additions and 4 deletions

View file

@ -1,5 +1,6 @@
#include <string.h>
#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));
}
}

View file

@ -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

View file

@ -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)