Changed the way local variables are works, now it is a bunch of unions. ReturnStack now have changable size. Strins are now char* instead int

This commit is contained in:
Alex Vanin 2014-01-28 13:56:45 +04:00
parent 159c5ed01f
commit 808f62b97e
7 changed files with 27 additions and 20 deletions

View file

@ -6,7 +6,7 @@ context* create_context(int function, func** hash, char** code)
cont = (context*)malloc(sizeof(context));
cont->id = function;
cont->locals=malloc(8*hash[function]->count_locals);
cont->locals=(l_var*)malloc(sizeof(l_var)*hash[function]->count_locals);
*(code)=hash[function]->code;
return cont;
}

View file

@ -4,11 +4,17 @@
#include "CodeHeader.h"
#include <stdio.h>
typedef union
{
double d_data;
long long i_data;
char* s_data;
} l_var;
typedef struct
{
int id;
void* locals;
l_var* locals;
} context;
typedef struct NODE

View file

@ -4,35 +4,36 @@
long long getlocal_int(context* cont, int id)
{
long long result;
result = ((long long*)(cont->locals))[id];
result = (cont->locals)[id].i_data;
return result;
}
double getlocal_double(context* cont, int id)
{
double result;
result = ((double*)(cont->locals))[id];
result = (cont->locals)[id].d_data;
return result;
}
int getlocal_string(context* cont, int id)
char* getlocal_string(context* cont, int id)
{
long long result;
result = ((long long*)(cont->locals))[id];
return (int)result;
char* result;
result = (cont->locals)[id].s_data;
return result;
}
void putlocal_int(long long* num, context* cont, int id)
{
memcpy(((long long*)cont->locals)+id, num, sizeof(long long));
//memcpy(((long long*)cont->locals)+id, num, sizeof(long long));
memcpy((cont->locals)+id, num, sizeof (long long));
}
void putlocal_double(double* num, context* cont, int id)
{
memcpy(((double*)cont->locals)+id, num, sizeof(double));
memcpy((cont->locals)+id, num, sizeof(double));
}
void putlocal_string(int* str, context* cont, int id)
void putlocal_string(char* str, context* cont, int id)
{
memcpy(((long long*)cont->locals)+id, (long long*)str, sizeof(long long));
memcpy((cont->locals)+id, str, sizeof(int*));
}

View file

@ -4,9 +4,9 @@
long long getlocal_int(context*, int);
double getlocal_double(context*, int);
int getlocal_string(context*, int);
char* getlocal_string(context*, int);
void putlocal_int(long long*, context*, int);
void putlocal_double(double*, context*, int);
void putlocal_string(int*, context*, int);
void putlocal_string(char*, context*, int);
#endif

View file

@ -52,7 +52,7 @@ int main(int argc, char** argv)
initTOS();
initRStack();
initRStack(1000);
ip = 0;
current_context = create_context(startfunc, phash_table, &code);
@ -596,7 +596,7 @@ int main(int argc, char** argv)
}
}
remove_context(current_context);
getchar();
return 0;
}

View file

@ -12,9 +12,9 @@ int pop_ret()
return num;
}
int initRStack()
int initRStack(int size)
{
RStack = (int*)calloc(1, 1000);
RStack = (int*)calloc(1, size);
rp = 0;
return 0;
}

View file

@ -3,7 +3,7 @@
int* RStack;
int rp;
int initRStack();
int initRStack(int);
void push_ret(int);
int pop_ret();
#endif