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:
parent
159c5ed01f
commit
808f62b97e
7 changed files with 27 additions and 20 deletions
|
@ -6,7 +6,7 @@ context* create_context(int function, func** hash, char** code)
|
||||||
cont = (context*)malloc(sizeof(context));
|
cont = (context*)malloc(sizeof(context));
|
||||||
|
|
||||||
cont->id = function;
|
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;
|
*(code)=hash[function]->code;
|
||||||
return cont;
|
return cont;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,17 @@
|
||||||
#include "CodeHeader.h"
|
#include "CodeHeader.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
double d_data;
|
||||||
|
long long i_data;
|
||||||
|
char* s_data;
|
||||||
|
} l_var;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
void* locals;
|
l_var* locals;
|
||||||
} context;
|
} context;
|
||||||
|
|
||||||
typedef struct NODE
|
typedef struct NODE
|
||||||
|
|
|
@ -4,35 +4,36 @@
|
||||||
long long getlocal_int(context* cont, int id)
|
long long getlocal_int(context* cont, int id)
|
||||||
{
|
{
|
||||||
long long result;
|
long long result;
|
||||||
result = ((long long*)(cont->locals))[id];
|
result = (cont->locals)[id].i_data;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getlocal_double(context* cont, int id)
|
double getlocal_double(context* cont, int id)
|
||||||
{
|
{
|
||||||
double result;
|
double result;
|
||||||
result = ((double*)(cont->locals))[id];
|
result = (cont->locals)[id].d_data;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getlocal_string(context* cont, int id)
|
char* getlocal_string(context* cont, int id)
|
||||||
{
|
{
|
||||||
long long result;
|
char* result;
|
||||||
result = ((long long*)(cont->locals))[id];
|
result = (cont->locals)[id].s_data;
|
||||||
return (int)result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void putlocal_int(long long* num, 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(((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)
|
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*));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
long long getlocal_int(context*, int);
|
long long getlocal_int(context*, int);
|
||||||
double getlocal_double(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_int(long long*, context*, int);
|
||||||
void putlocal_double(double*, context*, int);
|
void putlocal_double(double*, context*, int);
|
||||||
void putlocal_string(int*, context*, int);
|
void putlocal_string(char*, context*, int);
|
||||||
#endif
|
#endif
|
|
@ -52,7 +52,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
|
|
||||||
initTOS();
|
initTOS();
|
||||||
initRStack();
|
initRStack(1000);
|
||||||
ip = 0;
|
ip = 0;
|
||||||
|
|
||||||
current_context = create_context(startfunc, phash_table, &code);
|
current_context = create_context(startfunc, phash_table, &code);
|
||||||
|
@ -596,7 +596,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remove_context(current_context);
|
remove_context(current_context);
|
||||||
|
getchar();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@ int pop_ret()
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initRStack()
|
int initRStack(int size)
|
||||||
{
|
{
|
||||||
RStack = (int*)calloc(1, 1000);
|
RStack = (int*)calloc(1, size);
|
||||||
rp = 0;
|
rp = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
int* RStack;
|
int* RStack;
|
||||||
int rp;
|
int rp;
|
||||||
int initRStack();
|
int initRStack(int);
|
||||||
void push_ret(int);
|
void push_ret(int);
|
||||||
int pop_ret();
|
int pop_ret();
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue