|
|
@ -22,21 +22,22 @@ char *str_undef = "(undefined)";
|
|
|
|
|
|
|
|
|
|
|
|
void iinit(interpreter *interp)
|
|
|
|
void iinit(interpreter *interp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
interp->vars = (variable *)malloc(MAX_VARS * sizeof(variable));
|
|
|
|
interp->vars = (variable *)calloc(MAX_VARS, sizeof(variable));
|
|
|
|
interp->vnames = (char **)malloc(MAX_VARS * sizeof(char *));
|
|
|
|
interp->vnames = (char **)calloc(MAX_VARS, sizeof(char *));
|
|
|
|
interp->stack = (stack_t *)malloc(MAX_STACK * sizeof(stack_t));
|
|
|
|
interp->stack = (stack_t *)calloc(MAX_STACK, sizeof(stack_t));
|
|
|
|
interp->stidx = 0;
|
|
|
|
interp->stidx = 0;
|
|
|
|
interp->lines = (variable ***)malloc(MAX_LINES * sizeof(variable **));
|
|
|
|
interp->lines = (variable ***)calloc(MAX_LINES, sizeof(variable **));
|
|
|
|
interp->lnidx = 0;
|
|
|
|
interp->lnidx = 0;
|
|
|
|
interp->indent = 0;
|
|
|
|
interp->indent = 0;
|
|
|
|
interp->sindent = 0;
|
|
|
|
interp->sindent = 0;
|
|
|
|
|
|
|
|
interp->ret = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < MAX_VARS; i++) {
|
|
|
|
//for (unsigned int i = 0; i < MAX_VARS; i++) {
|
|
|
|
interp->vars[i].used = 0;
|
|
|
|
// interp->vars[i].used = 0;
|
|
|
|
interp->vnames[i] = 0;
|
|
|
|
// interp->vnames[i] = 0;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
for (unsigned int i = 0; i < MAX_LINES; i++)
|
|
|
|
//for (unsigned int i = 0; i < MAX_LINES; i++)
|
|
|
|
interp->lines[i] = 0;
|
|
|
|
// interp->lines[i] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
iload_core(interp);
|
|
|
|
iload_core(interp);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -75,7 +76,8 @@ variable *interpreter_get_variable(interpreter *interp, const char *name)
|
|
|
|
v->valtype = STRING;
|
|
|
|
v->valtype = STRING;
|
|
|
|
v->value = 0;
|
|
|
|
v->value = 0;
|
|
|
|
v->svalue = str_undef;
|
|
|
|
v->svalue = str_undef;
|
|
|
|
interp->vnames[i] = strclone(name);
|
|
|
|
char *s = strclone(name);
|
|
|
|
|
|
|
|
interp->vnames[i] = s;
|
|
|
|
return v;
|
|
|
|
return v;
|
|
|
|
} else if (interp->vnames[i] != 0 && !strcmp(interp->vnames[i], name)) {
|
|
|
|
} else if (interp->vnames[i] != 0 && !strcmp(interp->vnames[i], name)) {
|
|
|
|
return &interp->vars[i];
|
|
|
|
return &interp->vars[i];
|
|
|
@ -187,9 +189,9 @@ variable *make_var(interpreter *interp, const char *line, uint32_t *next)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
variable *v;
|
|
|
|
variable *v;
|
|
|
|
if (dec) {
|
|
|
|
if (dec)
|
|
|
|
v = vmakef(strtof(line, 0));
|
|
|
|
v = vmakef(strtof(line, 0));
|
|
|
|
} else
|
|
|
|
else
|
|
|
|
v = vmake(0, INTEGER, (void *)atoi(line));
|
|
|
|
v = vmake(0, INTEGER, (void *)atoi(line));
|
|
|
|
*next = end;
|
|
|
|
*next = end;
|
|
|
|
return v;
|
|
|
|
return v;
|
|
|
@ -208,7 +210,8 @@ int idoline(interpreter *interp, const char *line)
|
|
|
|
if (line[offset] == '#')
|
|
|
|
if (line[offset] == '#')
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
interp->lines[interp->lnidx] = (variable **)calloc(8, sizeof(variable *));
|
|
|
|
variable **linebuf = (variable **)calloc(8, sizeof(variable *));
|
|
|
|
|
|
|
|
interp->lines[interp->lnidx] = linebuf;
|
|
|
|
variable **ops = interp->lines[interp->lnidx];
|
|
|
|
variable **ops = interp->lines[interp->lnidx];
|
|
|
|
|
|
|
|
|
|
|
|
// step 1 - convert to tokens
|
|
|
|
// step 1 - convert to tokens
|
|
|
@ -355,7 +358,7 @@ fail:
|
|
|
|
|
|
|
|
|
|
|
|
variable *idoexpr(interpreter *interp, const char *line)
|
|
|
|
variable *idoexpr(interpreter *interp, const char *line)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
variable *result = (variable *)malloc(sizeof(variable));
|
|
|
|
variable *result = (variable *)calloc(1, sizeof(variable));
|
|
|
|
char *mline = line;
|
|
|
|
char *mline = line;
|
|
|
|
void *ops[16];
|
|
|
|
void *ops[16];
|
|
|
|
uint32_t ooffset = 0;
|
|
|
|
uint32_t ooffset = 0;
|
|
|
@ -430,9 +433,8 @@ variable *idoexpr(interpreter *interp, const char *line)
|
|
|
|
// step 2 - do operations
|
|
|
|
// step 2 - do operations
|
|
|
|
result->valtype = ((variable *)ops[0])->valtype;
|
|
|
|
result->valtype = ((variable *)ops[0])->valtype;
|
|
|
|
result->value = ((variable *)ops[0])->value;
|
|
|
|
result->value = ((variable *)ops[0])->value;
|
|
|
|
for (uint32_t i = 1; i < ooffset; i += 2) {
|
|
|
|
for (uint32_t i = 1; i < ooffset; i += 2)
|
|
|
|
iopfuncs[(uint32_t)ops[i] - 1](result, result, ops[i + 1]);
|
|
|
|
iopfuncs[(uint32_t)ops[i] - 1](result, result, ops[i + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < ooffset; i += 2) {
|
|
|
|
for (uint32_t i = 0; i < ooffset; i += 2) {
|
|
|
|
if (!((variable *)ops[i])->used) {
|
|
|
|
if (!((variable *)ops[i])->used) {
|
|
|
|