primitives-module.scm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ;;; Modules
  2. ;;; Copyright (C) 2024, 2025 Igalia, S.L.
  3. ;;;
  4. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  5. ;;; you may not use this file except in compliance with the License.
  6. ;;; You may obtain a copy of the License at
  7. ;;;
  8. ;;; http://www.apache.org/licenses/LICENSE-2.0
  9. ;;;
  10. ;;; Unless required by applicable law or agreed to in writing, software
  11. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  12. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ;;; See the License for the specific language governing permissions and
  14. ;;; limitations under the License.
  15. ;;; Commentary:
  16. ;;;
  17. ;;; Run-time representation of module trees.
  18. ;;;
  19. ;;; Code:
  20. (library (hoot primitives-module)
  21. (export initialize-primitives!)
  22. (import (hoot modules)
  23. (hoot errors)
  24. (hoot primitives))
  25. (define (install-primitive-definitions! m)
  26. (define-syntax-rule (install! prim v)
  27. (begin
  28. (module-define! m 'prim v #:mutable? #f)
  29. (module-export! m 'prim)))
  30. (define-syntax-rule (install/1! prim)
  31. (install! prim (lambda (a) (prim a))))
  32. (define-syntax-rule (install/2! prim)
  33. (install! prim (lambda (a b) (prim a b))))
  34. (define-syntax-rule (install/3! prim)
  35. (install! prim (lambda (a b c) (prim a b c))))
  36. (define-syntax-rule (install-placeholder! prim)
  37. (install! prim (lambda args (error "placeholder definition" 'prim))))
  38. (install/2! %*)
  39. (install/2! %+)
  40. (install/2! %-)
  41. (install/2! %/)
  42. (install/2! %<)
  43. (install/2! %<=)
  44. (install/2! %=)
  45. (install/2! %>)
  46. (install/2! %>=)
  47. (install! %abort-to-prompt %abort-to-prompt)
  48. (install/1! %abs)
  49. (install/2! %append)
  50. (install/2! %ash)
  51. (install! %atan (case-lambda ((x) (%atan x)) ((x y) (%atan x y))))
  52. (install/3! %atomic-box-compare-and-swap!)
  53. (install/1! %atomic-box-ref)
  54. (install/2! %atomic-box-set!)
  55. (install/2! %atomic-box-swap!)
  56. (install/1! %bitvector?)
  57. (install/1! %box-ref)
  58. (install/2! %box-set!)
  59. (install/2! %bytevector-ieee-double-native-ref)
  60. (install/3! %bytevector-ieee-double-native-set!)
  61. (install/2! %bytevector-ieee-single-native-ref)
  62. (install/3! %bytevector-ieee-single-native-set!)
  63. (install/1! %bytevector-length)
  64. (install/2! %bytevector-s16-native-ref)
  65. (install/3! %bytevector-s16-native-set!)
  66. (install/2! %bytevector-s32-native-ref)
  67. (install/3! %bytevector-s32-native-set!)
  68. (install/2! %bytevector-s64-native-ref)
  69. (install/3! %bytevector-s64-native-set!)
  70. (install/2! %bytevector-s8-ref)
  71. (install/3! %bytevector-s8-set!)
  72. (install/2! %bytevector-u16-native-ref)
  73. (install/3! %bytevector-u16-native-set!)
  74. (install/2! %bytevector-u32-native-ref)
  75. (install/3! %bytevector-u32-native-set!)
  76. (install/2! %bytevector-u64-native-ref)
  77. (install/3! %bytevector-u64-native-set!)
  78. (install/2! %bytevector-u8-ref)
  79. (install/3! %bytevector-u8-set!)
  80. (install/1! %bytevector?)
  81. (install/3! %call-with-prompt)
  82. (install-placeholder! %call-with-values) ; /2
  83. (install/1! %car)
  84. (install/1! %cdr)
  85. (install/1! %ceiling)
  86. (install/1! %char->integer)
  87. (install/1! %char?)
  88. (install/1! %complex?)
  89. (install/2! %cons)
  90. (install-placeholder! %dynamic-wind) ; /3
  91. (install/1! %eof-object?)
  92. (install/2! %eq?)
  93. (install/2! %eqv?)
  94. (install/1! %exact-integer?)
  95. (install/1! %exact?)
  96. (install/1! %floor)
  97. (install/1! %fluid-ref)
  98. (install/2! %fluid-set!)
  99. (install/1! %inexact)
  100. (install/1! %inexact?)
  101. (install/1! %integer->char)
  102. (install/1! %integer?)
  103. (install/1! %keyword->symbol)
  104. (install/1! %keyword?)
  105. (install/2! %logand)
  106. (install-placeholder! %logbit?) ; /2
  107. (install/2! %logior)
  108. (install-placeholder! %lognot) ; /1
  109. (install/2! %logtest)
  110. (install/2! %logxor)
  111. (install/1! %make-atomic-box)
  112. (install/1! %make-box)
  113. (install/2! %make-vector)
  114. (install/2! %modulo)
  115. (install/1! %null?)
  116. (install/1! %number?)
  117. (install/1! %pair?)
  118. (install/1! %procedure?)
  119. (install/2! %quotient)
  120. (install/1! %raise-exception)
  121. (install/1! %rational?)
  122. (install/1! %real?)
  123. (install/2! %remainder)
  124. (install/2! %set-car!)
  125. (install/2! %set-cdr!)
  126. (install/1! %sqrt)
  127. (install/1! %string->symbol)
  128. (install/1! %string->utf8)
  129. (install/1! %string-length)
  130. (install/2! %string-ref)
  131. (install-placeholder! %string-utf8-length) ; /1
  132. (install/1! %string?)
  133. (install-placeholder! %struct-ref) ; /2
  134. (install-placeholder! %struct-set!) ; /3
  135. (install/1! %struct-vtable)
  136. (install/1! %struct?)
  137. (install/1! %symbol->keyword)
  138. (install/1! %symbol->string)
  139. (install/1! %symbol?)
  140. (install/1! %utf8->string)
  141. (install! %values %values)
  142. (install/1! %vector-length)
  143. (install/2! %vector-ref)
  144. (install/3! %vector-set!)
  145. (install/1! %vector?)
  146. (install/2! %with-dynamic-state)
  147. (install/3! %with-fluid*)
  148. (install! apply apply)
  149. ;; TODO:
  150. (install-placeholder! %vector)
  151. (install-placeholder! %error)
  152. (install-placeholder! %cons*)
  153. (install-placeholder! %the-eof-object)
  154. (install-placeholder! %inline-wasm)
  155. (install-placeholder! %wasm-import)
  156. (install-placeholder! include-from-path)
  157. (install-placeholder! guile:syntax-module-bindings)
  158. #t)
  159. (define (initialize-primitives! mod)
  160. (install-primitive-definitions! mod)
  161. (%values)))