/* tripl/arch/interp/interp.c
*
* This file is part of tripl.
*
* tripl is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* tripl is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with tripl. If not, see
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int interp_init(void);
__arch int interp_new_var(char *name, long value, int attr);
__arch int interp_stack_dump(void);
__arch int interp_set_var(char *name, long value, int attr);
extern char *psave;
struct klist_node stack;
struct arch interp_arch_fn = {
.arch_init = interp_init,
.arch_new_var = interp_new_var,
.arch_stack_dump = interp_stack_dump,
.arch_import_shared = NULL,
.arch_funcall = NULL,
.arch_set_var = interp_set_var
};
__arch int interp_init(void) {
klist_init(&stack);
return 0;
}
static struct klist_node *find_name(char *name) {
struct klist_node *n;
for (n = stack.next; n != &stack; n = n->next)
if (!strcmp(n->payload, name))
return n;
return NULL;
}
__arch int interp_new_var(char *name, long value, int attr) {
push_nr(value, name, attr);
return 0;
}
__arch int interp_set_var(char *name, long value, int attr) {
struct klist_node *n;
/* find the name */
if (!(n = find_name(name)))
exit(generic_error("name not found", psave, lno));
if (n->xmask & 4)
exit(generic_error("variable sets to be read-only", psave, lno));
n->value = value;
return 0;
}
__arch int interp_stack_dump(void) {
struct klist_node *n;
int i;
ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_LIGHTBLUE, BG_BLACK);
printf("stack dump: \n");
ansi_csi_ed(stdout);
for (i = 0, n = stack.next; n != &stack; n = n->next, i++)
printf("\t%3d: %s \t%ld @ %08x\n", i, (char *) n->payload, n->value, n->xmask);
return 0;
}