intrinsics.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* Copyright 2018-2019
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _SCM_INTRINSICS_H_
  16. #define _SCM_INTRINSICS_H_
  17. #ifndef BUILDING_LIBGUILE
  18. #error intrinsics.h is private and uninstalled
  19. #endif
  20. #include <setjmp.h>
  21. #include <libguile/scm.h>
  22. typedef SCM (*scm_t_scm_from_scm_scm_intrinsic) (SCM, SCM);
  23. typedef SCM (*scm_t_scm_from_scm_uimm_intrinsic) (SCM, uint8_t);
  24. typedef void (*scm_t_scm_sz_u32_intrinsic) (SCM, size_t, uint32_t);
  25. typedef SCM (*scm_t_scm_from_scm_intrinsic) (SCM);
  26. typedef double (*scm_t_f64_from_scm_intrinsic) (SCM);
  27. typedef SCM (*scm_t_scm_from_f64_intrinsic) (double);
  28. /* If we don't have 64-bit registers, the intrinsics will take and
  29. return 64-bit values by reference. */
  30. #if SIZEOF_UINTPTR_T >= 8
  31. #define INDIRECT_INT64_INTRINSICS 0
  32. #else
  33. #define INDIRECT_INT64_INTRINSICS 1
  34. #endif
  35. #if INDIRECT_INT64_INTRINSICS
  36. typedef void (*scm_t_u64_from_scm_intrinsic) (uint64_t*, SCM);
  37. typedef void (*scm_t_s64_from_scm_intrinsic) (int64_t*, SCM);
  38. typedef SCM (*scm_t_scm_from_u64_intrinsic) (uint64_t*);
  39. typedef SCM (*scm_t_scm_from_s64_intrinsic) (int64_t*);
  40. typedef SCM (*scm_t_scm_from_scm_u64_intrinsic) (SCM, uint64_t*);
  41. #else
  42. typedef uint64_t (*scm_t_u64_from_scm_intrinsic) (SCM);
  43. typedef int64_t (*scm_t_s64_from_scm_intrinsic) (SCM);
  44. typedef SCM (*scm_t_scm_from_u64_intrinsic) (uint64_t);
  45. typedef SCM (*scm_t_scm_from_s64_intrinsic) (int64_t);
  46. typedef SCM (*scm_t_scm_from_scm_u64_intrinsic) (SCM, uint64_t);
  47. #endif
  48. typedef void (*scm_t_thread_intrinsic) (scm_thread*);
  49. typedef void (*scm_t_thread_scm_intrinsic) (scm_thread*, SCM);
  50. typedef void (*scm_t_thread_scm_scm_intrinsic) (scm_thread*, SCM, SCM);
  51. typedef SCM (*scm_t_scm_from_thread_scm_intrinsic) (scm_thread*, SCM);
  52. typedef int (*scm_t_bool_from_scm_scm_intrinsic) (SCM, SCM);
  53. typedef enum scm_compare (*scm_t_compare_from_scm_scm_intrinsic) (SCM, SCM);
  54. typedef void (*scm_t_thread_sp_intrinsic) (scm_thread*, union scm_vm_stack_element*);
  55. typedef SCM (*scm_t_scm_from_thread_u32_intrinsic) (scm_thread*, uint32_t);
  56. typedef uint32_t (*scm_t_u32_from_thread_u32_u32_intrinsic) (scm_thread*, uint32_t, uint32_t);
  57. typedef void (*scm_t_thread_u32_u32_scm_u8_u8_intrinsic) (scm_thread*, uint32_t,
  58. uint32_t, SCM, uint8_t,
  59. uint8_t);
  60. typedef SCM (*scm_t_scm_from_scm_scm_scmp_sp_intrinsic) (SCM, SCM, SCM*,
  61. const union scm_vm_stack_element*);
  62. typedef void (*scm_t_thread_noreturn_intrinsic) (scm_thread*) SCM_NORETURN;
  63. typedef void (*scm_t_thread_scm_noreturn_intrinsic) (scm_thread*, SCM) SCM_NORETURN;
  64. typedef int (*scm_t_int_from_scm_intrinsic) (SCM);
  65. typedef void (*scm_t_scm_scm_noreturn_intrinsic) (SCM, SCM) SCM_NORETURN;
  66. typedef void (*scm_t_noreturn_intrinsic) (void) SCM_NORETURN;
  67. typedef void (*scm_t_scm_noreturn_intrinsic) (SCM) SCM_NORETURN;
  68. typedef void (*scm_t_u32_noreturn_intrinsic) (uint32_t) SCM_NORETURN;
  69. typedef SCM (*scm_t_scm_from_thread_sz_intrinsic) (scm_thread*, size_t);
  70. typedef SCM (*scm_t_scm_from_thread_intrinsic) (scm_thread*);
  71. typedef void (*scm_t_thread_u8_scm_sp_vra_mra_intrinsic) (scm_thread*,
  72. uint8_t, SCM,
  73. const union scm_vm_stack_element*,
  74. uint32_t*, uint8_t*);
  75. typedef void (*scm_t_thread_mra_intrinsic) (scm_thread*, uint8_t*);
  76. typedef uint32_t* (*scm_t_vra_from_thread_intrinsic) (scm_thread*);
  77. typedef uint8_t* (*scm_t_mra_from_thread_scm_intrinsic) (scm_thread*, SCM);
  78. typedef uint8_t* (*scm_t_mra_from_thread_mra_intrinsic) (scm_thread*, uint8_t*);
  79. typedef SCM (*scm_t_scm_from_ptr_intrinsic) (SCM*);
  80. typedef void (*scm_t_ptr_scm_intrinsic) (SCM*, SCM);
  81. typedef SCM (*scm_t_scm_from_ptr_scm_intrinsic) (SCM*, SCM);
  82. typedef SCM (*scm_t_scm_from_ptr_scm_scm_intrinsic) (SCM*, SCM, SCM);
  83. typedef uint32_t* scm_t_vcode_intrinsic;
  84. #define SCM_FOR_ALL_VM_INTRINSICS(M) \
  85. M(scm_from_scm_scm, add, "add", ADD) \
  86. M(scm_from_scm_uimm, add_immediate, "add/immediate", ADD_IMMEDIATE) \
  87. M(scm_from_scm_scm, sub, "sub", SUB) \
  88. M(scm_from_scm_uimm, sub_immediate, "sub/immediate", SUB_IMMEDIATE) \
  89. M(scm_from_scm_scm, mul, "mul", MUL) \
  90. M(scm_from_scm_scm, div, "div", DIV) \
  91. M(scm_from_scm_scm, quo, "quo", QUO) \
  92. M(scm_from_scm_scm, rem, "rem", REM) \
  93. M(scm_from_scm_scm, mod, "mod", MOD) \
  94. M(scm_from_scm_scm, logand, "logand", LOGAND) \
  95. M(scm_from_scm_scm, logior, "logior", LOGIOR) \
  96. M(scm_from_scm_scm, logxor, "logxor", LOGXOR) \
  97. M(scm_sz_u32, string_set_x, "string-set!", STRING_SET_X) \
  98. M(scm_from_scm, string_to_number, "string->number", STRING_TO_NUMBER) \
  99. M(scm_from_scm, string_to_symbol, "string->symbol", STRING_TO_SYMBOL) \
  100. M(scm_from_scm, symbol_to_keyword, "symbol->keyword", SYMBOL_TO_KEYWORD) \
  101. M(scm_from_scm, class_of, "class-of", CLASS_OF) \
  102. M(f64_from_scm, scm_to_f64, "scm->f64", SCM_TO_F64) \
  103. M(u64_from_scm, scm_to_u64, "scm->u64", SCM_TO_U64) \
  104. M(u64_from_scm, scm_to_u64_truncate, "scm->u64/truncate", SCM_TO_U64_TRUNCATE) \
  105. M(s64_from_scm, scm_to_s64, "scm->s64", SCM_TO_S64) \
  106. M(scm_from_u64, u64_to_scm, "u64->scm", U64_TO_SCM) \
  107. M(scm_from_s64, s64_to_scm, "s64->scm", S64_TO_SCM) \
  108. M(scm_from_scm_scm, logsub, "logsub", LOGSUB) \
  109. M(thread_scm_scm, wind, "wind", WIND) \
  110. M(thread, unwind, "unwind", UNWIND) \
  111. M(thread_scm_scm, push_fluid, "push-fluid", PUSH_FLUID) \
  112. M(thread, pop_fluid, "pop-fluid", POP_FLUID) \
  113. M(scm_from_thread_scm, fluid_ref, "fluid-ref", FLUID_REF) \
  114. M(thread_scm_scm, fluid_set_x, "fluid-set!", FLUID_SET_X) \
  115. M(thread_scm, push_dynamic_state, "push-dynamic-state", PUSH_DYNAMIC_STATE) \
  116. M(thread, pop_dynamic_state, "pop-dynamic-state", POP_DYNAMIC_STATE) \
  117. M(scm_from_scm_u64, lsh, "lsh", LSH) \
  118. M(scm_from_scm_u64, rsh, "rsh", RSH) \
  119. M(scm_from_scm_uimm, lsh_immediate, "lsh/immediate", LSH_IMMEDIATE) \
  120. M(scm_from_scm_uimm, rsh_immediate, "rsh/immediate", RSH_IMMEDIATE) \
  121. M(bool_from_scm_scm, heap_numbers_equal_p, "heap-numbers-equal?", HEAP_NUMBERS_EQUAL_P) \
  122. M(compare_from_scm_scm, less_p, "<?", LESS_P) \
  123. M(bool_from_scm_scm, numerically_equal_p, "=?", NUMERICALLY_EQUAL_P) \
  124. M(scm_from_scm_uimm, resolve_module, "resolve-module", RESOLVE_MODULE) \
  125. M(scm_from_scm_scm, lookup, "lookup", LOOKUP) \
  126. M(scm_from_scm_scm, define_x, "define!", DEFINE_X) \
  127. M(thread_sp, expand_stack, "expand-stack", EXPAND_STACK) \
  128. M(scm_from_thread_u32, cons_rest, "cons-rest", CONS_REST) \
  129. M(u32_from_thread_u32_u32, compute_kwargs_npositional, "compute-kwargs-npositional", COMPUTE_KWARGS_NPOSITIONAL) \
  130. M(thread_u32_u32_scm_u8_u8, bind_kwargs, "bind-kwargs", BIND_KWARGS) \
  131. M(thread_mra, push_interrupt_frame, "push-interrupt-frame", PUSH_INTERRUPT_FRAME) \
  132. M(thread_scm_scm, foreign_call, "foreign-call", FOREIGN_CALL) \
  133. M(thread_scm_noreturn, reinstate_continuation_x, "reinstate-continuation!", REINSTATE_CONTINUATION_X) \
  134. M(scm_from_thread, capture_continuation, "capture-continuation", CAPTURE_CONTINUATION) \
  135. M(mra_from_thread_scm, compose_continuation, "compose-continuation", COMPOSE_CONTINUATION) \
  136. M(thread, expand_apply_argument, "expand-apply-argument", EXPAND_APPLY_ARGUMENT) \
  137. M(mra_from_thread_mra, abort_to_prompt, "abort-to-prompt", ABORT_TO_PROMPT) \
  138. M(scm_scm_noreturn, throw_, "throw", THROW) \
  139. M(scm_scm_noreturn, throw_with_value, "throw/value", THROW_WITH_VALUE) \
  140. M(scm_scm_noreturn, throw_with_value_and_data, "throw/value+data", THROW_WITH_VALUE_AND_DATA) \
  141. M(thread_noreturn, error_wrong_num_args, "wrong-num-args", ERROR_WRONG_NUM_ARGS) \
  142. M(noreturn, error_no_values, "no-values", ERROR_NO_VALUES) \
  143. M(noreturn, error_not_enough_values, "not-enough-values", ERROR_NOT_ENOUGH_VALUES) \
  144. M(u32_noreturn, error_wrong_number_of_values, "wrong-number-of-values", ERROR_WRONG_NUMBER_OF_VALUES) \
  145. M(vra_from_thread, get_callee_vcode, "get-callee-vcode", GET_CALLEE_VCODE) \
  146. M(scm_from_thread_sz, allocate_words, "allocate-words", ALLOCATE_WORDS) \
  147. M(scm_from_thread, current_module, "current-module", CURRENT_MODULE) \
  148. M(thread_u8_scm_sp_vra_mra, push_prompt, "push-prompt", PUSH_PROMPT) \
  149. M(thread_scm, unpack_values_object, "unpack-values-object", UNPACK_VALUES_OBJECT) \
  150. M(vcode, handle_interrupt_code, "%handle-interrupt-code", HANDLE_INTERRUPT_CODE) \
  151. M(scm_from_f64, f64_to_scm, "f64->scm", F64_TO_SCM) \
  152. /* Add new intrinsics here; also update scm_bootstrap_intrinsics. */
  153. enum scm_vm_intrinsic
  154. {
  155. #define DEFINE_ENUM(type, id, name, ID) SCM_VM_INTRINSIC_##ID,
  156. SCM_FOR_ALL_VM_INTRINSICS(DEFINE_ENUM)
  157. #undef DEFINE_ENUM
  158. SCM_VM_INTRINSIC_COUNT
  159. };
  160. SCM_INTERNAL struct scm_vm_intrinsics
  161. {
  162. #define DEFINE_MEMBER(type, id, name, ID) scm_t_##type##_intrinsic id;
  163. SCM_FOR_ALL_VM_INTRINSICS(DEFINE_MEMBER)
  164. #undef DEFINE_MEMBER
  165. } scm_vm_intrinsics;
  166. SCM_INTERNAL SCM scm_intrinsic_list (void);
  167. SCM_INTERNAL void scm_bootstrap_intrinsics (void);
  168. SCM_INTERNAL void scm_init_intrinsics (void);
  169. #endif /* _SCM_INTRINSICS_H_ */