Fixed major bug with compiling in release-mode: wrong allocated memory. initTOS now takes size of TOS as parameter. Improved work with contexts: now memory releases after popping context from stack
This commit is contained in:
parent
ff0ef7f0bb
commit
e2d0d56299
5 changed files with 15 additions and 11 deletions
|
@ -27,9 +27,12 @@ void push_context(context* cont)
|
||||||
}
|
}
|
||||||
context* pop_context()
|
context* pop_context()
|
||||||
{
|
{
|
||||||
|
context* poped = node_last->obj;
|
||||||
c_node* last = node_last;
|
c_node* last = node_last;
|
||||||
node_last = node_last->prev;
|
node_last = node_last->prev;
|
||||||
return last->obj;
|
|
||||||
|
free(last);
|
||||||
|
return poped;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Find Context in Context Stack.
|
//Find Context in Context Stack.
|
||||||
|
|
|
@ -58,7 +58,7 @@ int read_constant(FILE* stream, int* count, char*** index)
|
||||||
|
|
||||||
buffer = (char*)malloc(Const_Header.size_const+1);
|
buffer = (char*)malloc(Const_Header.size_const+1);
|
||||||
buffer[0]=0;
|
buffer[0]=0;
|
||||||
*(index) = (char**)malloc(sizeof(char**)*Const_Header.count_const);
|
*(index) = (char**)malloc(sizeof(char**)*Const_Header.count_const+1);
|
||||||
|
|
||||||
|
|
||||||
fread_s(buffer+1, Const_Header.size_const, sizeof(char), Const_Header.size_const, stream); //Reading constant values
|
fread_s(buffer+1, Const_Header.size_const, sizeof(char), Const_Header.size_const, stream); //Reading constant values
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
long long cmp_int(long long* a, long long* b);
|
long long cmp_int(long long* a, long long* b);
|
||||||
double cmp_double(double* a, double* b);
|
double cmp_double(double* a, double* b);
|
||||||
void run_intepreter(char* filename);
|
int run_interpreter(char* filename);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,9 @@ int main(int argc, char** argv)
|
||||||
printf("%s", "File is not specified");
|
printf("%s", "File is not specified");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return_code = run_interpreter(argv[1]);
|
|
||||||
|
|
||||||
|
return_code = run_interpreter(argv[1]);
|
||||||
|
return return_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_interpreter(char* filename)
|
int run_interpreter(char* filename)
|
||||||
|
@ -56,12 +57,13 @@ int run_interpreter(char* filename)
|
||||||
startfunc = read_bytecode(input, &phash_table);
|
startfunc = read_bytecode(input, &phash_table);
|
||||||
fclose(input);
|
fclose(input);
|
||||||
|
|
||||||
|
initTOS(3000);
|
||||||
|
|
||||||
initTOS();
|
|
||||||
initRStack(1000);
|
initRStack(1000);
|
||||||
ip = 0;
|
ip = 0;
|
||||||
|
|
||||||
current_context = create_context(startfunc, phash_table, &code);
|
current_context = create_context(startfunc, phash_table, &code);
|
||||||
|
|
||||||
node_last = NULL;
|
node_last = NULL;
|
||||||
|
|
||||||
while (exec_status)
|
while (exec_status)
|
||||||
|
@ -603,7 +605,6 @@ int run_interpreter(char* filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remove_context(current_context);
|
remove_context(current_context);
|
||||||
getchar();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ double pop_double()
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initTOS()
|
int initTOS(int count)
|
||||||
{
|
{
|
||||||
TOS = (double*)calloc(1, 12000);
|
TOS = (double*)calloc(count, sizeof(double*));
|
||||||
tp = 0;
|
tp = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ typedef union
|
||||||
|
|
||||||
double* TOS;
|
double* TOS;
|
||||||
int tp;
|
int tp;
|
||||||
int initTOS();
|
int initTOS(int);
|
||||||
void push_int(long long);
|
void push_int(long long);
|
||||||
void push_double(double);
|
void push_double(double);
|
||||||
long long pop_int();
|
long long pop_int();
|
||||||
|
|
Loading…
Reference in a new issue