primitives-module.scm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ;;; Modules
  2. ;;; Copyright (C) 2024 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 boot-primitives-module!)
  22. (import (hoot modules)
  23. (hoot errors)
  24. (hoot primitives))
  25. (define (install-primitive-definitions! m)
  26. (define-syntax-rule (install! prim v)
  27. (module-define! m 'prim v #:mutable? #f))
  28. (define-syntax-rule (install/1! prim)
  29. (install! prim (lambda (a) (prim a))))
  30. (define-syntax-rule (install/2! prim)
  31. (install! prim (lambda (a b) (prim a b))))
  32. (define-syntax-rule (install/3! prim)
  33. (install! prim (lambda (a b c) (prim a b c))))
  34. (install/2! %*)
  35. (install/2! %+)
  36. (install/2! %-)
  37. (install/2! %/)
  38. (install/2! %<)
  39. (install/2! %<=)
  40. (install/2! %=)
  41. (install/2! %>)
  42. (install/2! %>=)
  43. (install! %abort-to-prompt %abort-to-prompt)
  44. (install/1! %abs)
  45. (install/2! %append)
  46. (install/2! %ash)
  47. (install! %atan (case-lambda ((x) (%atan x)) ((x y) (%atan x y))))
  48. (install/3! %atomic-box-compare-and-swap!)
  49. (install/1! %atomic-box-ref)
  50. (install/2! %atomic-box-set!)
  51. (install/2! %atomic-box-swap!)
  52. (install/1! %bitvector?)
  53. (install/1! %box-ref)
  54. (install/2! %box-set!)
  55. (install/2! %bytevector-ieee-double-native-ref)
  56. (install/3! %bytevector-ieee-double-native-set!)
  57. (install/2! %bytevector-ieee-single-native-ref)
  58. (install/3! %bytevector-ieee-single-native-set!)
  59. (install/1! %bytevector-length)
  60. (install/2! %bytevector-s16-native-ref)
  61. (install/3! %bytevector-s16-native-set!)
  62. (install/2! %bytevector-s32-native-ref)
  63. (install/3! %bytevector-s32-native-set!)
  64. (install/2! %bytevector-s64-native-ref)
  65. (install/3! %bytevector-s64-native-set!)
  66. (install/2! %bytevector-s8-ref)
  67. (install/3! %bytevector-s8-set!)
  68. (install/2! %bytevector-u16-native-ref)
  69. (install/3! %bytevector-u16-native-set!)
  70. (install/2! %bytevector-u32-native-ref)
  71. (install/3! %bytevector-u32-native-set!)
  72. (install/2! %bytevector-u64-native-ref)
  73. (install/3! %bytevector-u64-native-set!)
  74. (install/2! %bytevector-u8-ref)
  75. (install/3! %bytevector-u8-set!)
  76. (install/1! %bytevector?)
  77. (install/3! %call-with-prompt)
  78. ;(install/2! %call-with-values)
  79. (install/1! %car)
  80. (install/1! %cdr)
  81. (install/1! %ceiling)
  82. (install/1! %char->integer)
  83. (install/1! %char?)
  84. (install/1! %complex?)
  85. (install/2! %cons)
  86. ;(install/3! %dynamic-wind)
  87. (install/1! %eof-object?)
  88. (install/2! %eq?)
  89. (install/2! %eqv?)
  90. (install/1! %exact-integer?)
  91. (install/1! %exact?)
  92. (install/1! %floor)
  93. (install/1! %fluid-ref)
  94. (install/2! %fluid-set!)
  95. (install/1! %inexact)
  96. (install/1! %inexact?)
  97. (install/1! %integer->char)
  98. (install/1! %integer?)
  99. (install/1! %keyword->symbol)
  100. (install/1! %keyword?)
  101. (install/2! %logand)
  102. ;(install/2! %logbit?)
  103. (install/2! %logior)
  104. ;(install/1! %lognot)
  105. (install/2! %logtest)
  106. (install/2! %logxor)
  107. (install/1! %make-atomic-box)
  108. (install/1! %make-box)
  109. (install/2! %make-vector)
  110. (install/2! %modulo)
  111. (install/1! %null?)
  112. (install/1! %number?)
  113. (install/1! %pair?)
  114. (install/1! %procedure?)
  115. (install/2! %quotient)
  116. (install/1! %raise-exception)
  117. (install/1! %rational?)
  118. (install/1! %real?)
  119. (install/2! %remainder)
  120. (install/2! %set-car!)
  121. (install/2! %set-cdr!)
  122. (install/1! %sqrt)
  123. (install/1! %string->symbol)
  124. (install/1! %string->utf8)
  125. (install/1! %string-length)
  126. (install/2! %string-ref)
  127. ;(install/1! %string-utf8-length)
  128. (install/1! %string?)
  129. ;(install/2! %struct-ref)
  130. ;(install/3! %struct-set!)
  131. (install/1! %struct-vtable)
  132. (install/1! %struct?)
  133. (install/1! %symbol->keyword)
  134. (install/1! %symbol->string)
  135. (install/1! %symbol?)
  136. (install/1! %utf8->string)
  137. (install! %values %values)
  138. (install/1! %vector-length)
  139. (install/2! %vector-ref)
  140. (install/3! %vector-set!)
  141. (install/1! %vector?)
  142. (install/2! %with-dynamic-state)
  143. (install/3! %with-fluid*)
  144. (install! apply apply)
  145. ;; TODO:
  146. ;(vector . %vector)
  147. ;(error . %error)
  148. ;(cons* %cons*)
  149. ;(the-eof-object . %the-eof-object)
  150. ;%inline-wasm, %wasm-import, include-from-path...
  151. ;; FIXME: make-struct -> allocate-struct + struct-init!
  152. #t)
  153. (define (boot-primitives-module! mod)
  154. (check-type mod module? 'module-local-variable)
  155. (define root (resolve-module mod '()))
  156. (unless (submodule-ref root '(hoot primitives))
  157. (let ((m (submodule-define! root '(hoot primitives))))
  158. (install-primitive-definitions! m)))
  159. (%values)))