intrinsics.c 19 KB

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