intrinsics.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /* Copyright 2018-2021, 2023
  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. #if HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <math.h>
  19. #include "alist.h"
  20. #include "atomics-internal.h"
  21. #include "boolean.h"
  22. #include "cache-internal.h"
  23. #include "extensions.h"
  24. #include "fluids.h"
  25. #include "frames.h"
  26. #include "gc-inline.h"
  27. #include "goops.h"
  28. #include "gsubr.h"
  29. #include "keywords.h"
  30. #include "modules.h"
  31. #include "numbers.h"
  32. #include "struct.h"
  33. #include "symbols.h"
  34. #include "threads.h"
  35. #include "variable.h"
  36. #include "version.h"
  37. #include "intrinsics.h"
  38. struct scm_vm_intrinsics scm_vm_intrinsics;
  39. SCM_DEFINE (scm_intrinsic_list, "intrinsic-list", 0, 0, 0,
  40. (void),
  41. "")
  42. #define FUNC_NAME s_scm_intrinsic_list
  43. {
  44. SCM list = SCM_EOL;
  45. #define ADD_INTRINSIC(type, id, name, ID) \
  46. if (name) \
  47. list = scm_acons (scm_from_latin1_symbol (name), \
  48. scm_from_int (SCM_VM_INTRINSIC_##ID), \
  49. list);
  50. SCM_FOR_ALL_VM_INTRINSICS (ADD_INTRINSIC);
  51. #undef ADD_INTRINSIC
  52. return list;
  53. }
  54. #undef FUNC_NAME
  55. static SCM
  56. add_immediate (SCM a, uint8_t b)
  57. {
  58. if (SCM_LIKELY (SCM_I_INUMP (a)))
  59. {
  60. scm_t_signed_bits sum = SCM_I_INUM (a) + b;
  61. if (SCM_LIKELY (SCM_POSFIXABLE (sum)))
  62. return SCM_I_MAKINUM (sum);
  63. }
  64. return scm_sum (a, scm_from_uint8 (b));
  65. }
  66. static SCM
  67. sub_immediate (SCM a, uint8_t b)
  68. {
  69. if (SCM_LIKELY (SCM_I_INUMP (a)))
  70. {
  71. scm_t_signed_bits diff = SCM_I_INUM (a) - b;
  72. if (SCM_LIKELY (SCM_NEGFIXABLE (diff)))
  73. return SCM_I_MAKINUM (diff);
  74. }
  75. return scm_difference (a, scm_from_uint8 (b));
  76. }
  77. static void
  78. string_set_x (SCM str, size_t idx, uint32_t ch)
  79. {
  80. str = scm_i_string_start_writing (str);
  81. scm_i_string_set_x (str, idx, ch);
  82. scm_i_string_stop_writing ();
  83. }
  84. static SCM
  85. string_to_number (SCM str)
  86. {
  87. return scm_string_to_number (str, SCM_UNDEFINED /* radix = 10 */);
  88. }
  89. static uint64_t
  90. scm_to_uint64_truncate (SCM x)
  91. {
  92. if (SCM_LIKELY (SCM_I_INUMP (x)))
  93. return (uint64_t) SCM_I_INUM (x);
  94. else
  95. return scm_to_uint64 (scm_logand (x, scm_from_uint64 ((uint64_t) -1)));
  96. }
  97. #if INDIRECT_INT64_INTRINSICS
  98. static void
  99. indirect_scm_to_int64 (int64_t *dst, SCM x)
  100. {
  101. *dst = scm_to_int64 (x);
  102. }
  103. static void
  104. indirect_scm_to_uint64 (uint64_t *dst, SCM x)
  105. {
  106. *dst = scm_to_uint64 (x);
  107. }
  108. static void
  109. indirect_scm_to_uint64_truncate (uint64_t *dst, SCM x)
  110. {
  111. *dst = scm_to_uint64_truncate (x);
  112. }
  113. static SCM
  114. indirect_scm_from_int64 (int64_t *src)
  115. {
  116. return scm_from_int64 (*src);
  117. }
  118. static SCM
  119. indirect_scm_from_uint64 (uint64_t *src)
  120. {
  121. return scm_from_uint64 (*src);
  122. }
  123. #endif
  124. static SCM
  125. logsub (SCM x, SCM y)
  126. {
  127. if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
  128. {
  129. scm_t_signed_bits a, b;
  130. a = SCM_I_INUM (x);
  131. b = SCM_I_INUM (y);
  132. return SCM_I_MAKINUM (a & ~b);
  133. }
  134. return scm_logand (x, scm_lognot (y));
  135. }
  136. static void
  137. wind (scm_thread *thread, SCM winder, SCM unwinder)
  138. {
  139. scm_dynstack_push_dynwind (&thread->dynstack, winder, unwinder);
  140. }
  141. static void
  142. unwind (scm_thread *thread)
  143. {
  144. scm_dynstack_pop (&thread->dynstack);
  145. }
  146. static void
  147. push_fluid (scm_thread *thread, SCM fluid, SCM value)
  148. {
  149. scm_dynstack_push_fluid (&thread->dynstack, fluid, value,
  150. thread->dynamic_state);
  151. }
  152. static void
  153. pop_fluid (scm_thread *thread)
  154. {
  155. scm_dynstack_unwind_fluid (&thread->dynstack, thread->dynamic_state);
  156. }
  157. static SCM
  158. fluid_ref (scm_thread *thread, SCM fluid)
  159. {
  160. struct scm_cache_entry *entry;
  161. /* If we find FLUID in the cache, then it is indeed a fluid. */
  162. entry = scm_cache_lookup (&thread->dynamic_state->cache, fluid);
  163. if (SCM_LIKELY (scm_is_eq (SCM_PACK (entry->key), fluid)
  164. && !SCM_UNBNDP (SCM_PACK (entry->value))))
  165. return SCM_PACK (entry->value);
  166. return scm_fluid_ref (fluid);
  167. }
  168. static void
  169. fluid_set_x (scm_thread *thread, SCM fluid, SCM value)
  170. {
  171. struct scm_cache_entry *entry;
  172. /* If we find FLUID in the cache, then it is indeed a fluid. */
  173. entry = scm_cache_lookup (&thread->dynamic_state->cache, fluid);
  174. if (SCM_LIKELY (scm_is_eq (SCM_PACK (entry->key), fluid)))
  175. entry->value = SCM_UNPACK (value);
  176. else
  177. scm_fluid_set_x (fluid, value);
  178. }
  179. static void
  180. push_dynamic_state (scm_thread *thread, SCM state)
  181. {
  182. scm_dynstack_push_dynamic_state (&thread->dynstack, state,
  183. thread->dynamic_state);
  184. }
  185. static void
  186. pop_dynamic_state (scm_thread *thread)
  187. {
  188. scm_dynstack_unwind_dynamic_state (&thread->dynstack,
  189. thread->dynamic_state);
  190. }
  191. static SCM
  192. lsh (SCM a, uint64_t b)
  193. {
  194. if (SCM_LIKELY (SCM_I_INUMP (a))
  195. && b < (uint64_t) (SCM_I_FIXNUM_BIT - 1)
  196. && ((scm_t_bits)
  197. (SCM_SRS (SCM_I_INUM (a), (SCM_I_FIXNUM_BIT-1 - b)) + 1)
  198. <= 1))
  199. {
  200. scm_t_signed_bits nn = SCM_I_INUM (a);
  201. return SCM_I_MAKINUM (nn < 0 ? -(-nn << b) : (nn << b));
  202. }
  203. else
  204. return scm_ash (a, scm_from_uint64 (b));
  205. }
  206. static SCM
  207. rsh (SCM a, uint64_t b)
  208. {
  209. if (SCM_LIKELY (SCM_I_INUMP (a)))
  210. {
  211. if (b > (uint64_t) (SCM_I_FIXNUM_BIT - 1))
  212. b = SCM_I_FIXNUM_BIT - 1;
  213. return SCM_I_MAKINUM (SCM_SRS (SCM_I_INUM (a), b));
  214. }
  215. else
  216. return scm_ash (a, scm_difference (SCM_INUM0, scm_from_uint64 (b)));
  217. }
  218. #if INDIRECT_INT64_INTRINSICS
  219. static SCM
  220. indirect_lsh (SCM a, uint64_t *b)
  221. {
  222. return lsh (a, *b);
  223. }
  224. static SCM
  225. indirect_rsh (SCM a, uint64_t *b)
  226. {
  227. return rsh (a, *b);
  228. }
  229. #endif
  230. static SCM
  231. lsh_immediate (SCM a, uint8_t b)
  232. {
  233. return lsh (a, b);
  234. }
  235. static SCM
  236. rsh_immediate (SCM a, uint8_t b)
  237. {
  238. return rsh (a, b);
  239. }
  240. static enum scm_compare
  241. less_p (SCM a, SCM b)
  242. {
  243. if (SCM_LIKELY (SCM_I_INUMP (a) && SCM_I_INUMP (b)))
  244. {
  245. scm_t_signed_bits a_bits = SCM_UNPACK (a);
  246. scm_t_signed_bits b_bits = SCM_UNPACK (b);
  247. return a_bits < b_bits ? SCM_F_COMPARE_LESS_THAN : SCM_F_COMPARE_NONE;
  248. }
  249. if ((SCM_REALP (a) && scm_is_true (scm_nan_p (a)))
  250. || (SCM_REALP (b) && scm_is_true (scm_nan_p (b))))
  251. return SCM_F_COMPARE_INVALID;
  252. else if (scm_is_true (scm_less_p (a, b)))
  253. return SCM_F_COMPARE_LESS_THAN;
  254. else
  255. return SCM_F_COMPARE_NONE;
  256. }
  257. static int
  258. numerically_equal_p (SCM a, SCM b)
  259. {
  260. if (SCM_LIKELY (SCM_I_INUMP (a) && SCM_I_INUMP (b)))
  261. return scm_is_eq (a, b);
  262. return scm_is_true (scm_num_eq_p (a, b));
  263. }
  264. static SCM
  265. resolve_module (SCM name, uint8_t public_p)
  266. {
  267. SCM mod;
  268. if (!scm_module_system_booted_p)
  269. return SCM_BOOL_F;
  270. mod = scm_maybe_resolve_module (name);
  271. if (scm_is_false (mod))
  272. scm_misc_error (NULL, "Module named ~s does not exist",
  273. scm_list_1 (name));
  274. if (public_p)
  275. {
  276. mod = scm_module_public_interface (mod);
  277. if (scm_is_false (mod))
  278. scm_misc_error (NULL, "Module named ~s has no public interface",
  279. scm_list_1 (name));
  280. }
  281. return mod;
  282. }
  283. static SCM
  284. module_variable (SCM module, SCM name)
  285. {
  286. /* If MODULE was captured before modules were booted, use the root
  287. module. Not so nice, but hey... */
  288. if (scm_is_false (module))
  289. module = scm_the_root_module ();
  290. return scm_module_variable (module, name);
  291. }
  292. static SCM
  293. lookup (SCM module, SCM name)
  294. {
  295. SCM var = module_variable (module, name);
  296. if (!SCM_VARIABLEP (var))
  297. scm_error (scm_from_latin1_symbol ("unbound-variable"), NULL,
  298. "Unbound variable: ~S", scm_list_1 (name), SCM_BOOL_F);
  299. return var;
  300. }
  301. static SCM
  302. lookup_bound (SCM module, SCM name)
  303. {
  304. SCM var = lookup (module, name);
  305. if (SCM_UNBNDP (SCM_VARIABLE_REF (var)))
  306. scm_error (scm_from_latin1_symbol ("unbound-variable"), NULL,
  307. "Unbound variable: ~S", scm_list_1 (name), SCM_BOOL_F);
  308. return var;
  309. }
  310. /* lookup-bound-public and lookup-bound-private take the name as a
  311. string instead of a symbol in order to reduce relocations at program
  312. startup. */
  313. static SCM
  314. lookup_bound_public (SCM module, SCM name)
  315. {
  316. return lookup_bound (resolve_module (module, 1),
  317. scm_string_to_symbol (name));
  318. }
  319. static SCM
  320. lookup_bound_private (SCM module, SCM name)
  321. {
  322. return lookup_bound (resolve_module (module, 0),
  323. scm_string_to_symbol (name));
  324. }
  325. static void throw_ (SCM key, SCM args) SCM_NORETURN;
  326. static void throw_with_value (SCM val, SCM key_subr_and_message) SCM_NORETURN;
  327. static void throw_with_value_and_data (SCM val, SCM key_subr_and_message) SCM_NORETURN;
  328. static void
  329. throw_ (SCM key, SCM args)
  330. {
  331. scm_throw (key, args);
  332. abort(); /* not reached */
  333. }
  334. static void
  335. throw_with_value (SCM val, SCM key_subr_and_message)
  336. {
  337. SCM key, subr, message, args, data;
  338. key = SCM_SIMPLE_VECTOR_REF (key_subr_and_message, 0);
  339. subr = SCM_SIMPLE_VECTOR_REF (key_subr_and_message, 1);
  340. message = SCM_SIMPLE_VECTOR_REF (key_subr_and_message, 2);
  341. args = scm_list_1 (val);
  342. data = SCM_BOOL_F;
  343. throw_ (key, scm_list_4 (subr, message, args, data));
  344. }
  345. static void
  346. throw_with_value_and_data (SCM val, SCM key_subr_and_message)
  347. {
  348. SCM key, subr, message, args, data;
  349. key = SCM_SIMPLE_VECTOR_REF (key_subr_and_message, 0);
  350. subr = SCM_SIMPLE_VECTOR_REF (key_subr_and_message, 1);
  351. message = SCM_SIMPLE_VECTOR_REF (key_subr_and_message, 2);
  352. args = scm_list_1 (val);
  353. data = args;
  354. throw_ (key, scm_list_4 (subr, message, args, data));
  355. }
  356. static void error_wrong_num_args (scm_thread *) SCM_NORETURN;
  357. static void error_no_values (void) SCM_NORETURN;
  358. static void error_not_enough_values (void) SCM_NORETURN;
  359. static void error_wrong_number_of_values (uint32_t expected) SCM_NORETURN;
  360. static void
  361. error_wrong_num_args (scm_thread *thread)
  362. {
  363. SCM callee = SCM_FRAME_LOCAL (thread->vm.fp, 0);
  364. scm_wrong_num_args (callee);
  365. }
  366. static void
  367. error_no_values (void)
  368. {
  369. scm_misc_error (NULL, "Zero values returned to single-valued continuation",
  370. SCM_EOL);
  371. }
  372. static void
  373. error_not_enough_values (void)
  374. {
  375. scm_misc_error (NULL, "Too few values returned to continuation", SCM_EOL);
  376. }
  377. static void
  378. error_wrong_number_of_values (uint32_t expected)
  379. {
  380. scm_misc_error (NULL,
  381. "Wrong number of values returned to continuation (expected ~a)",
  382. scm_list_1 (scm_from_uint32 (expected)));
  383. }
  384. static SCM
  385. allocate_words (scm_thread *thread, size_t n)
  386. {
  387. return SCM_PACK_POINTER (scm_inline_gc_malloc_words (thread, n));
  388. }
  389. static SCM
  390. allocate_words_with_freelist (scm_thread *thread, size_t freelist_idx)
  391. {
  392. return SCM_PACK_POINTER
  393. (scm_inline_gc_alloc (&thread->freelists[freelist_idx],
  394. freelist_idx,
  395. SCM_INLINE_GC_KIND_NORMAL));
  396. }
  397. static SCM
  398. allocate_pointerless_words (scm_thread *thread, size_t n)
  399. {
  400. return SCM_PACK_POINTER (scm_inline_gc_malloc_pointerless_words (thread, n));
  401. }
  402. static SCM
  403. allocate_pointerless_words_with_freelist (scm_thread *thread, size_t freelist_idx)
  404. {
  405. return SCM_PACK_POINTER
  406. (scm_inline_gc_alloc (&thread->pointerless_freelists[freelist_idx],
  407. freelist_idx,
  408. SCM_INLINE_GC_KIND_POINTERLESS));
  409. }
  410. static SCM
  411. current_module (scm_thread *thread)
  412. {
  413. return scm_i_current_module (thread);
  414. }
  415. static void
  416. push_prompt (scm_thread *thread, uint8_t escape_only_p,
  417. SCM tag, const union scm_vm_stack_element *sp, uint32_t *vra,
  418. uint8_t *mra)
  419. {
  420. struct scm_vm *vp = &thread->vm;
  421. scm_t_dynstack_prompt_flags flags;
  422. flags = escape_only_p ? SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY : 0;
  423. scm_dynstack_push_prompt (&thread->dynstack, flags, tag,
  424. vp->stack_top - vp->fp, vp->stack_top - sp,
  425. vra, mra, thread->vm.registers);
  426. }
  427. static SCM
  428. scm_atan1 (SCM x)
  429. {
  430. return scm_atan (x, SCM_UNDEFINED);
  431. }
  432. static void
  433. set_car_x (SCM x, SCM y)
  434. {
  435. scm_set_car_x (x, y);
  436. }
  437. static void
  438. set_cdr_x (SCM x, SCM y)
  439. {
  440. scm_set_cdr_x (x, y);
  441. }
  442. static void
  443. variable_set_x (SCM x, SCM y)
  444. {
  445. scm_variable_set_x (x, y);
  446. }
  447. static void
  448. vector_set_x (SCM x, SCM y, SCM z)
  449. {
  450. scm_vector_set_x (x, y, z);
  451. }
  452. static SCM
  453. vector_ref_immediate (SCM x, uint8_t idx)
  454. {
  455. return scm_c_vector_ref (x, idx);
  456. }
  457. static void
  458. vector_set_x_immediate (SCM x, uint8_t idx, SCM z)
  459. {
  460. scm_c_vector_set_x (x, idx, z);
  461. }
  462. static void
  463. struct_set_x (SCM x, SCM y, SCM z)
  464. {
  465. scm_struct_set_x (x, y, z);
  466. }
  467. static SCM
  468. struct_ref_immediate (SCM x, uint8_t idx)
  469. {
  470. return scm_struct_ref (x, scm_from_uint8 (idx));
  471. }
  472. static void
  473. struct_set_x_immediate (SCM x, uint8_t idx, SCM z)
  474. {
  475. scm_struct_set_x (x, scm_from_uint8 (idx), z);
  476. }
  477. void
  478. scm_bootstrap_intrinsics (void)
  479. {
  480. scm_vm_intrinsics.add = scm_sum;
  481. scm_vm_intrinsics.add_immediate = add_immediate;
  482. scm_vm_intrinsics.sub = scm_difference;
  483. scm_vm_intrinsics.sub_immediate = sub_immediate;
  484. scm_vm_intrinsics.mul = scm_product;
  485. scm_vm_intrinsics.div = scm_divide;
  486. scm_vm_intrinsics.quo = scm_quotient;
  487. scm_vm_intrinsics.rem = scm_remainder;
  488. scm_vm_intrinsics.mod = scm_modulo;
  489. scm_vm_intrinsics.logand = scm_logand;
  490. scm_vm_intrinsics.logior = scm_logior;
  491. scm_vm_intrinsics.logxor = scm_logxor;
  492. scm_vm_intrinsics.string_set_x = string_set_x;
  493. scm_vm_intrinsics.string_to_number = string_to_number;
  494. scm_vm_intrinsics.string_to_symbol = scm_string_to_symbol;
  495. scm_vm_intrinsics.symbol_to_keyword = scm_symbol_to_keyword;
  496. scm_vm_intrinsics.class_of = scm_class_of;
  497. scm_vm_intrinsics.scm_to_f64 = scm_to_double;
  498. #if INDIRECT_INT64_INTRINSICS
  499. scm_vm_intrinsics.scm_to_u64 = indirect_scm_to_uint64;
  500. scm_vm_intrinsics.scm_to_u64_truncate = indirect_scm_to_uint64_truncate;
  501. scm_vm_intrinsics.scm_to_s64 = indirect_scm_to_int64;
  502. scm_vm_intrinsics.u64_to_scm = indirect_scm_from_uint64;
  503. scm_vm_intrinsics.s64_to_scm = indirect_scm_from_int64;
  504. #else
  505. scm_vm_intrinsics.scm_to_u64 = scm_to_uint64;
  506. scm_vm_intrinsics.scm_to_u64_truncate = scm_to_uint64_truncate;
  507. scm_vm_intrinsics.scm_to_s64 = scm_to_int64;
  508. scm_vm_intrinsics.u64_to_scm = scm_from_uint64;
  509. scm_vm_intrinsics.s64_to_scm = scm_from_int64;
  510. #endif
  511. scm_vm_intrinsics.logsub = logsub;
  512. scm_vm_intrinsics.wind = wind;
  513. scm_vm_intrinsics.unwind = unwind;
  514. scm_vm_intrinsics.push_fluid = push_fluid;
  515. scm_vm_intrinsics.pop_fluid = pop_fluid;
  516. scm_vm_intrinsics.fluid_ref = fluid_ref;
  517. scm_vm_intrinsics.fluid_set_x = fluid_set_x;
  518. scm_vm_intrinsics.push_dynamic_state = push_dynamic_state;
  519. scm_vm_intrinsics.pop_dynamic_state = pop_dynamic_state;
  520. #if INDIRECT_INT64_INTRINSICS
  521. scm_vm_intrinsics.lsh = indirect_lsh;
  522. scm_vm_intrinsics.rsh = indirect_rsh;
  523. #else
  524. scm_vm_intrinsics.lsh = lsh;
  525. scm_vm_intrinsics.rsh = rsh;
  526. #endif
  527. scm_vm_intrinsics.lsh_immediate = lsh_immediate;
  528. scm_vm_intrinsics.rsh_immediate = rsh_immediate;
  529. scm_vm_intrinsics.heap_numbers_equal_p = scm_i_heap_numbers_equal_p;
  530. scm_vm_intrinsics.less_p = less_p;
  531. scm_vm_intrinsics.numerically_equal_p = numerically_equal_p;
  532. scm_vm_intrinsics.resolve_module = resolve_module;
  533. scm_vm_intrinsics.module_variable = module_variable;
  534. scm_vm_intrinsics.lookup = lookup;
  535. scm_vm_intrinsics.lookup_bound = lookup_bound;
  536. scm_vm_intrinsics.lookup_bound_public = lookup_bound_public;
  537. scm_vm_intrinsics.lookup_bound_private = lookup_bound_private;
  538. scm_vm_intrinsics.define_x = scm_module_ensure_local_variable;
  539. scm_vm_intrinsics.throw_ = throw_;
  540. scm_vm_intrinsics.throw_with_value = throw_with_value;
  541. scm_vm_intrinsics.throw_with_value_and_data = throw_with_value_and_data;
  542. scm_vm_intrinsics.error_wrong_num_args = error_wrong_num_args;
  543. scm_vm_intrinsics.error_no_values = error_no_values;
  544. scm_vm_intrinsics.error_not_enough_values = error_not_enough_values;
  545. scm_vm_intrinsics.error_wrong_number_of_values = error_wrong_number_of_values;
  546. scm_vm_intrinsics.allocate_words = allocate_words;
  547. scm_vm_intrinsics.current_module = current_module;
  548. scm_vm_intrinsics.push_prompt = push_prompt;
  549. scm_vm_intrinsics.allocate_words_with_freelist = allocate_words_with_freelist;
  550. scm_vm_intrinsics.abs = scm_abs;
  551. scm_vm_intrinsics.sqrt = scm_sqrt;
  552. scm_vm_intrinsics.fabs = fabs;
  553. scm_vm_intrinsics.fsqrt = sqrt;
  554. scm_vm_intrinsics.floor = scm_floor;
  555. scm_vm_intrinsics.ceiling = scm_ceiling;
  556. scm_vm_intrinsics.sin = scm_sin;
  557. scm_vm_intrinsics.cos = scm_cos;
  558. scm_vm_intrinsics.tan = scm_tan;
  559. scm_vm_intrinsics.asin = scm_asin;
  560. scm_vm_intrinsics.acos = scm_acos;
  561. scm_vm_intrinsics.atan = scm_atan1;
  562. scm_vm_intrinsics.atan2 = scm_atan;
  563. scm_vm_intrinsics.ffloor = floor;
  564. scm_vm_intrinsics.fceiling = ceil;
  565. scm_vm_intrinsics.fsin = sin;
  566. scm_vm_intrinsics.fcos = cos;
  567. scm_vm_intrinsics.ftan = tan;
  568. scm_vm_intrinsics.fasin = asin;
  569. scm_vm_intrinsics.facos = acos;
  570. scm_vm_intrinsics.fatan = atan;
  571. scm_vm_intrinsics.fatan2 = atan2;
  572. scm_vm_intrinsics.allocate_pointerless_words = allocate_pointerless_words;
  573. scm_vm_intrinsics.allocate_pointerless_words_with_freelist =
  574. allocate_pointerless_words_with_freelist;
  575. scm_vm_intrinsics.inexact = scm_exact_to_inexact;
  576. /* Intrinsics for the baseline compiler. */
  577. scm_vm_intrinsics.car = scm_car;
  578. scm_vm_intrinsics.cdr = scm_cdr;
  579. scm_vm_intrinsics.set_car_x = set_car_x;
  580. scm_vm_intrinsics.set_cdr_x = set_cdr_x;
  581. scm_vm_intrinsics.variable_ref = scm_variable_ref;
  582. scm_vm_intrinsics.variable_set_x = variable_set_x;
  583. scm_vm_intrinsics.vector_length = scm_vector_length;
  584. scm_vm_intrinsics.vector_ref = scm_vector_ref;
  585. scm_vm_intrinsics.vector_set_x = vector_set_x;
  586. scm_vm_intrinsics.vector_ref_immediate = vector_ref_immediate;
  587. scm_vm_intrinsics.vector_set_x_immediate = vector_set_x_immediate;
  588. scm_vm_intrinsics.allocate_struct = scm_allocate_struct;
  589. scm_vm_intrinsics.struct_vtable = scm_struct_vtable;
  590. scm_vm_intrinsics.struct_ref = scm_struct_ref;
  591. scm_vm_intrinsics.struct_set_x = struct_set_x;
  592. scm_vm_intrinsics.struct_ref_immediate = struct_ref_immediate;
  593. scm_vm_intrinsics.struct_set_x_immediate = struct_set_x_immediate;
  594. scm_vm_intrinsics.symbol_to_string = scm_symbol_to_string;
  595. scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
  596. "scm_init_intrinsics",
  597. (scm_t_extension_init_func)scm_init_intrinsics,
  598. NULL);
  599. }
  600. void
  601. scm_init_intrinsics (void)
  602. {
  603. #ifndef SCM_MAGIC_SNARFER
  604. #include "intrinsics.x"
  605. #endif
  606. }