| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- /* 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 <https://www.gnu.org/licenses/>
- */
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <string.h>
- #include <dlfcn.h>
- #include <errno.h>
- #include <klist.h>
- #include <tripl/tripl.h>
- #include <tripl/limits.h>
- #include <tripl/arch.h>
- 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;
- }
|