interp.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* tripl/arch/interp/interp.c
  2. *
  3. * This file is part of tripl.
  4. *
  5. * tripl is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * tripl is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with tripl. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <stdlib.h>
  21. #include <sys/types.h>
  22. #include <string.h>
  23. #include <dlfcn.h>
  24. #include <errno.h>
  25. #include <klist.h>
  26. #include <tripl/tripl.h>
  27. #include <tripl/limits.h>
  28. #include <tripl/arch.h>
  29. int interp_init(void);
  30. __arch int interp_new_var(char *name, long value, int attr);
  31. __arch int interp_stack_dump(void);
  32. struct klist_node stack;
  33. struct arch interp_arch_fn = {
  34. .arch_init = interp_init,
  35. .arch_new_var = interp_new_var,
  36. .arch_stack_dump = interp_stack_dump,
  37. .arch_import_shared = NULL,
  38. .arch_funcall = NULL,
  39. .arch_set_var = NULL
  40. };
  41. __arch int interp_init(void) {
  42. klist_init(&stack);
  43. return 0;
  44. }
  45. __arch int interp_new_var(char *name, long value, int attr) {
  46. push_nr(value, name, attr);
  47. return 0;
  48. }
  49. __arch int interp_stack_dump(void) {
  50. struct klist_node *n;
  51. int i;
  52. ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_LIGHTBLUE, BG_BLACK);
  53. printf("stack dump: \n");
  54. ansi_csi_ed(stdout);
  55. for (i = 0, n = stack.next; n != &stack; n = n->next, i++)
  56. printf("\t%3d: %s \t%ld @ %08x\n", i, (char *) n->payload, n->value, n->xmask);
  57. return 0;
  58. }