vm.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (C) 2001, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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_NUM_HOOKS,
  29. };
  30. #define SCM_VM_REGULAR_ENGINE 0
  31. #define SCM_VM_DEBUG_ENGINE 1
  32. #define SCM_VM_NUM_ENGINES 2
  33. struct scm_vm {
  34. scm_t_uint32 *ip; /* instruction pointer */
  35. union scm_vm_stack_element *sp; /* stack pointer */
  36. union scm_vm_stack_element *fp; /* frame pointer */
  37. union scm_vm_stack_element *stack_limit; /* stack limit address */
  38. int trace_level; /* traces enabled if trace_level > 0 */
  39. union scm_vm_stack_element *sp_min_since_gc; /* deepest sp since last gc */
  40. size_t stack_size; /* stack size */
  41. union scm_vm_stack_element *stack_bottom; /* lowest address in allocated stack */
  42. union scm_vm_stack_element *stack_top; /* highest address in allocated stack */
  43. SCM overflow_handler_stack; /* alist of max-stack-size -> thunk */
  44. SCM hooks[SCM_VM_NUM_HOOKS]; /* hooks */
  45. const void *resumable_prompt_cookie; /* opaque cookie */
  46. int engine; /* which vm engine we're using */
  47. };
  48. SCM_INTERNAL struct scm_vm *scm_the_vm (void);
  49. SCM_API SCM scm_call_with_vm (SCM proc, SCM args);
  50. SCM_API SCM scm_call_with_stack_overflow_handler (SCM limit, SCM thunk,
  51. SCM handler);
  52. SCM_API SCM scm_vm_apply_hook (void);
  53. SCM_API SCM scm_vm_push_continuation_hook (void);
  54. SCM_API SCM scm_vm_pop_continuation_hook (void);
  55. SCM_API SCM scm_vm_abort_continuation_hook (void);
  56. SCM_API SCM scm_vm_next_hook (void);
  57. SCM_API SCM scm_vm_trace_level (void);
  58. SCM_API SCM scm_set_vm_trace_level_x (SCM level);
  59. SCM_API SCM scm_vm_engine (void);
  60. SCM_API SCM scm_set_vm_engine_x (SCM engine);
  61. SCM_API SCM scm_set_default_vm_engine_x (SCM engine);
  62. SCM_API void scm_c_set_vm_engine_x (int engine);
  63. SCM_API void scm_c_set_default_vm_engine_x (int engine);
  64. struct GC_ms_entry;
  65. SCM_INTERNAL struct GC_ms_entry * scm_i_vm_mark_stack (struct scm_vm *,
  66. struct GC_ms_entry *,
  67. struct GC_ms_entry *);
  68. SCM_INTERNAL void scm_i_vm_free_stack (struct scm_vm *vp);
  69. #define SCM_F_VM_CONT_PARTIAL 0x1
  70. #define SCM_F_VM_CONT_REWINDABLE 0x2
  71. struct scm_vm_cont {
  72. /* IP of newest frame. */
  73. scm_t_uint32 *ra;
  74. /* Offset of FP of newest frame, relative to stack top. */
  75. scm_t_ptrdiff fp_offset;
  76. /* Besides being the stack size, this is also the offset of the SP of
  77. the newest frame. */
  78. scm_t_ptrdiff stack_size;
  79. /* Stack bottom, which also keeps saved stack alive for GC. */
  80. union scm_vm_stack_element *stack_bottom;
  81. /* Saved dynamic stack, with prompts relocated to record saved SP/FP
  82. offsets from the stack top of this scm_vm_cont. */
  83. scm_t_dynstack *dynstack;
  84. /* See the continuation is partial and/or rewindable. */
  85. scm_t_uint32 flags;
  86. };
  87. #define SCM_VM_CONT_P(OBJ) (SCM_HAS_TYP7 (OBJ, scm_tc7_vm_cont))
  88. #define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT))
  89. #define SCM_VM_CONT_PARTIAL_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_PARTIAL)
  90. #define SCM_VM_CONT_REWINDABLE_P(CONT) (SCM_VM_CONT_DATA (CONT)->flags & SCM_F_VM_CONT_REWINDABLE)
  91. SCM_API SCM scm_load_compiled_with_vm (SCM file);
  92. SCM_INTERNAL SCM scm_i_call_with_current_continuation (SCM proc);
  93. SCM_INTERNAL SCM scm_i_capture_current_stack (void);
  94. SCM_INTERNAL SCM scm_i_vm_capture_stack (union scm_vm_stack_element *stack_top,
  95. union scm_vm_stack_element *fp,
  96. union scm_vm_stack_element *sp,
  97. scm_t_uint32 *ra,
  98. scm_t_dynstack *dynstack,
  99. scm_t_uint32 flags);
  100. SCM_INTERNAL int scm_i_vm_cont_to_frame (SCM cont, struct scm_frame *frame);
  101. SCM_INTERNAL void scm_i_vm_cont_print (SCM x, SCM port,
  102. scm_print_state *pstate);
  103. SCM_INTERNAL int scm_i_vm_is_boot_continuation_code (scm_t_uint32 *ip);
  104. SCM_INTERNAL void scm_bootstrap_vm (void);
  105. SCM_INTERNAL void scm_init_vm (void);
  106. #endif /* _SCM_VM_H_ */
  107. /*
  108. Local Variables:
  109. c-file-style: "gnu"
  110. End:
  111. */