vm.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Copyright (C) 2001, 2009, 2010, 2011, 2012 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. enum {
  23. SCM_VM_APPLY_HOOK,
  24. SCM_VM_PUSH_CONTINUATION_HOOK,
  25. SCM_VM_POP_CONTINUATION_HOOK,
  26. SCM_VM_NEXT_HOOK,
  27. SCM_VM_ABORT_CONTINUATION_HOOK,
  28. SCM_VM_RESTORE_CONTINUATION_HOOK,
  29. SCM_VM_NUM_HOOKS,
  30. };
  31. struct scm_vm;
  32. typedef SCM (*scm_t_vm_engine) (SCM vm, 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_t_uint8 *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. int trace_level; /* traces enabled if trace_level > 0 */
  46. };
  47. SCM_API SCM scm_the_vm_fluid;
  48. #define SCM_VM_P(x) (SCM_HAS_TYP7 (x, scm_tc7_vm))
  49. #define SCM_VM_DATA(vm) ((struct scm_vm *) SCM_CELL_WORD_1 (vm))
  50. #define SCM_VALIDATE_VM(pos,x) SCM_MAKE_VALIDATE (pos, x, VM_P)
  51. SCM_API SCM scm_the_vm (void);
  52. SCM_API SCM scm_make_vm (void);
  53. SCM_API SCM scm_the_vm (void);
  54. SCM_API SCM scm_call_with_vm (SCM vm, SCM proc, SCM args);
  55. SCM_API SCM scm_vm_p (SCM obj);
  56. SCM_API SCM scm_vm_ip (SCM vm);
  57. SCM_API SCM scm_vm_sp (SCM vm);
  58. SCM_API SCM scm_vm_fp (SCM vm);
  59. SCM_API SCM scm_vm_apply_hook (SCM vm);
  60. SCM_API SCM scm_vm_push_continuation_hook (SCM vm);
  61. SCM_API SCM scm_vm_pop_continuation_hook (SCM vm);
  62. SCM_API SCM scm_vm_abort_continuation_hook (SCM vm);
  63. SCM_API SCM scm_vm_restore_continuation_hook (SCM vm);
  64. SCM_API SCM scm_vm_next_hook (SCM vm);
  65. SCM_API SCM scm_vm_trace_level (SCM vm);
  66. SCM_API SCM scm_set_vm_trace_level_x (SCM vm, SCM level);
  67. SCM_API SCM scm_vm_engine (SCM vm);
  68. SCM_API SCM scm_set_vm_engine_x (SCM vm, SCM engine);
  69. SCM_API SCM scm_set_default_vm_engine_x (SCM engine);
  70. SCM_API void scm_c_set_vm_engine_x (SCM vm, int engine);
  71. SCM_API void scm_c_set_default_vm_engine_x (int engine);
  72. #define SCM_F_VM_CONT_PARTIAL 0x1
  73. #define SCM_F_VM_CONT_REWINDABLE 0x2
  74. struct scm_vm_cont {
  75. SCM *sp;
  76. SCM *fp;
  77. scm_t_uint8 *ra, *mvra;
  78. scm_t_ptrdiff stack_size;
  79. SCM *stack_base;
  80. scm_t_ptrdiff reloc;
  81. scm_t_dynstack *dynstack;
  82. scm_t_uint32 flags;
  83. };
  84. #define SCM_VM_CONT_P(OBJ) (SCM_HAS_TYP7 (OBJ, scm_tc7_vm_cont))
  85. #define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT))
  86. #define SCM_VM_CONT_PARTIAL_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_PARTIAL)
  87. #define SCM_VM_CONT_REWINDABLE_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_REWINDABLE)
  88. SCM_API SCM scm_load_compiled_with_vm (SCM file);
  89. SCM_INTERNAL SCM scm_c_vm_run (SCM vm, SCM program, SCM *argv, int nargs);
  90. SCM_INTERNAL void scm_i_vm_print (SCM x, SCM port,
  91. scm_print_state *pstate);
  92. SCM_INTERNAL SCM scm_i_capture_current_stack (void);
  93. SCM_INTERNAL SCM scm_i_vm_capture_stack (SCM *stack_base, SCM *fp, SCM *sp,
  94. scm_t_uint8 *ra, scm_t_uint8 *mvra,
  95. scm_t_dynstack *dynstack,
  96. scm_t_uint32 flags);
  97. SCM_INTERNAL void scm_i_vm_cont_print (SCM x, SCM port,
  98. scm_print_state *pstate);
  99. SCM_INTERNAL void scm_bootstrap_vm (void);
  100. SCM_INTERNAL void scm_init_vm (void);
  101. #endif /* _SCM_VM_H_ */
  102. /*
  103. Local Variables:
  104. c-file-style: "gnu"
  105. End:
  106. */