Update.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include "../../types.h"
|
||||
#include "../../tokenizer.h"
|
||||
#include "../../interpreter.h"
|
||||
@@ -19,6 +20,7 @@ extern long ax;
|
||||
extern int return_flag;
|
||||
extern char str_pool[];
|
||||
extern int str_pool_idx;
|
||||
extern pthread_mutex_t token_mutex;
|
||||
|
||||
long native_eval(long *args, int argc) {
|
||||
if (argc < 1 || !args) {
|
||||
@@ -86,6 +88,9 @@ long native_eval(long *args, int argc) {
|
||||
|
||||
Token *t = &temp_tokens[temp_tk_idx++];
|
||||
t->text = s;
|
||||
t->line = 1;
|
||||
t->column = 1;
|
||||
t->filename = "<eval>";
|
||||
|
||||
if (*s >= '0' && *s <= '9') {
|
||||
t->type = 128;
|
||||
@@ -115,27 +120,47 @@ long native_eval(long *args, int argc) {
|
||||
temp_tokens[temp_tk_idx].type = 0;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&token_mutex);
|
||||
|
||||
Token *saved_tokens = (Token*)malloc(sizeof(Token) * MAX_TOK);
|
||||
if (!saved_tokens) {
|
||||
pthread_mutex_unlock(&token_mutex);
|
||||
free(eval_copy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int saved_tk_idx = tk_idx;
|
||||
for (int i = 0; i < tk_idx && i < MAX_TOK; i++) {
|
||||
saved_tokens[i] = tokens[i];
|
||||
}
|
||||
|
||||
pc = 0;
|
||||
long result = 0;
|
||||
|
||||
if (temp_tk_idx > 0) {
|
||||
for (int i = 0; i < temp_tk_idx && i < 100; i++) {
|
||||
tokens[inserted_pos + i] = temp_tokens[i];
|
||||
tokens[i] = temp_tokens[i];
|
||||
}
|
||||
tk_idx = inserted_pos + temp_tk_idx;
|
||||
tk_idx = temp_tk_idx;
|
||||
if (tk_idx < MAX_TOK) {
|
||||
tokens[tk_idx].type = 0;
|
||||
}
|
||||
|
||||
pc = inserted_pos;
|
||||
pc = 0;
|
||||
result = expression();
|
||||
}
|
||||
|
||||
free(eval_copy);
|
||||
|
||||
tk_idx = original_tk_idx;
|
||||
for (int i = 0; i < saved_tk_idx && i < MAX_TOK; i++) {
|
||||
tokens[i] = saved_tokens[i];
|
||||
}
|
||||
tk_idx = saved_tk_idx;
|
||||
pc = saved_pc;
|
||||
|
||||
free(saved_tokens);
|
||||
pthread_mutex_unlock(&token_mutex);
|
||||
|
||||
free(eval_copy);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user