vm.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright (C) 2001 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. #ifndef _SCM_VM_H_
  19. #define _SCM_VM_H_
  20. #include <libguile.h>
  21. #include <libguile/programs.h>
  22. #define SCM_VM_BOOT_HOOK 0
  23. #define SCM_VM_HALT_HOOK 1
  24. #define SCM_VM_NEXT_HOOK 2
  25. #define SCM_VM_BREAK_HOOK 3
  26. #define SCM_VM_ENTER_HOOK 4
  27. #define SCM_VM_APPLY_HOOK 5
  28. #define SCM_VM_EXIT_HOOK 6
  29. #define SCM_VM_RETURN_HOOK 7
  30. #define SCM_VM_NUM_HOOKS 8
  31. struct scm_vm;
  32. typedef SCM (*scm_t_vm_engine) (struct scm_vm *vp, SCM program, SCM *argv, int nargs);
  33. #define SCM_VM_REGULAR_ENGINE 0
  34. #define SCM_VM_DEBUG_ENGINE 1
  35. #define SCM_VM_NUM_ENGINES 2
  36. struct scm_vm {
  37. scm_byte_t *ip; /* instruction pointer */
  38. SCM *sp; /* stack pointer */
  39. SCM *fp; /* frame pointer */
  40. size_t stack_size; /* stack size */
  41. SCM *stack_base; /* stack base address */
  42. SCM *stack_limit; /* stack limit address */
  43. int engine; /* which vm engine we're using */
  44. SCM hooks[SCM_VM_NUM_HOOKS]; /* hooks */
  45. SCM options; /* options */
  46. unsigned long time; /* time spent */
  47. unsigned long clock; /* bogos clock */
  48. SCM trace_frame; /* a frame being traced */
  49. };
  50. SCM_API SCM scm_the_vm_fluid;
  51. #define SCM_VM_P(x) SCM_SMOB_PREDICATE (scm_tc16_vm, x)
  52. #define SCM_VM_DATA(vm) ((struct scm_vm *) SCM_SMOB_DATA (vm))
  53. #define SCM_VALIDATE_VM(pos,x) SCM_MAKE_VALIDATE (pos, x, VM_P)
  54. SCM_API SCM scm_the_vm ();
  55. SCM_API SCM scm_make_vm (void);
  56. SCM_API SCM scm_vm_apply (SCM vm, SCM program, SCM args);
  57. SCM_API SCM scm_c_vm_run (SCM vm, SCM program, SCM *argv, int nargs);
  58. SCM_API SCM scm_vm_option_ref (SCM vm, SCM key);
  59. SCM_API SCM scm_vm_option_set_x (SCM vm, SCM key, SCM val);
  60. SCM_API SCM scm_vm_version (void);
  61. SCM_API SCM scm_the_vm (void);
  62. SCM_API SCM scm_vm_p (SCM obj);
  63. SCM_API SCM scm_vm_ip (SCM vm);
  64. SCM_API SCM scm_vm_sp (SCM vm);
  65. SCM_API SCM scm_vm_fp (SCM vm);
  66. SCM_API SCM scm_vm_boot_hook (SCM vm);
  67. SCM_API SCM scm_vm_halt_hook (SCM vm);
  68. SCM_API SCM scm_vm_next_hook (SCM vm);
  69. SCM_API SCM scm_vm_break_hook (SCM vm);
  70. SCM_API SCM scm_vm_enter_hook (SCM vm);
  71. SCM_API SCM scm_vm_apply_hook (SCM vm);
  72. SCM_API SCM scm_vm_exit_hook (SCM vm);
  73. SCM_API SCM scm_vm_return_hook (SCM vm);
  74. SCM_API SCM scm_vm_option (SCM vm, SCM key);
  75. SCM_API SCM scm_set_vm_option_x (SCM vm, SCM key, SCM val);
  76. SCM_API SCM scm_vm_stats (SCM vm);
  77. SCM_API SCM scm_vm_trace_frame (SCM vm);
  78. struct scm_vm_cont {
  79. scm_byte_t *ip;
  80. SCM *sp;
  81. SCM *fp;
  82. scm_t_ptrdiff stack_size;
  83. SCM *stack_base;
  84. scm_t_ptrdiff reloc;
  85. };
  86. SCM_API scm_t_bits scm_tc16_vm_cont;
  87. #define SCM_VM_CONT_P(OBJ) SCM_SMOB_PREDICATE (scm_tc16_vm_cont, OBJ)
  88. #define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT))
  89. SCM_API SCM scm_vm_capture_continuations (void);
  90. SCM_API void scm_vm_reinstate_continuations (SCM conts);
  91. SCM_API SCM scm_load_compiled_with_vm (SCM file);
  92. SCM_INTERNAL void scm_init_vm (void);
  93. #endif /* _SCM_VM_H_ */
  94. /*
  95. Local Variables:
  96. c-file-style: "gnu"
  97. End:
  98. */