PrimOps.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ;;; For now these are written in Scheme.
  2. ;;; They should be re-written in Common Lisp, but there are still some
  3. ;;; limitations in the Common Lisp support making that difficult.
  4. ;; SYMBOLS
  5. (define (boundp symbol) :: |clisp:boolean|
  6. ((primitive-static-method <gnu.commonlisp.lang.Symbols> "isBound"
  7. <boolean> (<object>))
  8. symbol))
  9. (define (symbolp x) :: |clisp:boolean|
  10. (invoke-static <gnu.commonlisp.lang.Symbols> 'isSymbol x))
  11. (define (symbol-name symbol)
  12. (invoke-static <gnu.commonlisp.lang.Symbols> 'getPrintName symbol))
  13. ;(define (make-symbol NAME) ...)
  14. ; (define (intern name #!optional obarray) ...)
  15. ; (define (intern-soft NAME #!optonal obarray) ..)
  16. ;; obarray
  17. ;; mapatoms
  18. ;; unintern
  19. (define (symbol-plist symbol)
  20. (gnu.mapping.PropertyLocation:getPropertyList symbol))
  21. (define (setplist symbol plist)
  22. (gnu.mapping.PropertyLocation:setPropertyList symbol plist)
  23. plist)
  24. (define (plist-get plist prop #!optional default)
  25. (gnu.mapping.PropertyLocation:plistGet plist prop default))
  26. (define (plist-put plist prop value)
  27. (gnu.mapping.PropertyLocation:plistPut plist prop value))
  28. (define (plist-remprop plist prop)
  29. (gnu.mapping.PropertyLocation:plistRemove plist prop))
  30. (define (plist-member plist prop)
  31. (if (eq?
  32. (gnu.mapping.PropertyLocation:plistGet plist prop #!void)
  33. #!void)
  34. '() 't))
  35. (define (get (symbol :: <gnu.mapping.Symbol>) property #!optional (default '()))
  36. (gnu.mapping.PropertyLocation:getProperty symbol property default))
  37. (define (put symbol property value)
  38. (gnu.mapping.PropertyLocation:putProperty symbol property value))
  39. ;; VARIABLES
  40. ;;A `void-variable' error is signaled if SYMBOL has neither a local
  41. ;; binding nor a global value.
  42. (define (symbol-value sym)
  43. (invoke (gnu.mapping.Environment:getCurrent) 'get (invoke-static <gnu.commonlisp.lang.Symbols> 'getSymbol sym)))
  44. ;; setq
  45. ;(define (make-symbol NAME) ...)
  46. (define (set symbol value)
  47. ((gnu.mapping.Environment:getCurrent):put
  48. (<gnu.commonlisp.lang.Symbols>:getSymbol symbol)
  49. value))
  50. #|
  51. (define (add-to-list symbol value)
  52. (let ((old (symbol-value symbol)))
  53. (or (elisp::member value old) ;; FIXME
  54. (set symbol (cons value (symbol-value symbol))))))
  55. |#
  56. ;; FUNCTIONS
  57. ;; This returns the object in the function cell of SYMBOL. If the
  58. ;; symbol's function cell is void, a `void-function' error is signaled.
  59. (define (symbol-function symbol)
  60. (invoke-static <gnu.commonlisp.lang.Symbols> 'getFunctionBinding
  61. symbol))
  62. ;(define (fboundp x) ..)
  63. ;(fmakunboud symbol)
  64. (define (fset symbol object)
  65. (invoke-static <gnu.commonlisp.lang.Symbols> 'setFunctionBinding
  66. (invoke-static <gnu.mapping.Environment> 'getCurrent)
  67. symbol object))
  68. ;;; ARRAYS
  69. (define (length (x :: <gnu.lists.Sequence>))
  70. (invoke x 'size))
  71. (define (arrayp x) ::|clisp:boolean|
  72. (instance? x <gnu.lists.SimpleVector>))
  73. (define (aref
  74. (array ::gnu.lists.SimpleVector)
  75. (k ::int))
  76. (invoke array 'get k))
  77. (define (aset (array ::gnu.lists.SimpleVector)
  78. (k ::int)
  79. obj)
  80. (invoke array 'set k obj)
  81. obj)
  82. (define (fillarray (array ::gnu.lists.SimpleVector) obj)
  83. (invoke array 'fill obj)
  84. obj)
  85. ;;; STRINGS
  86. (define (stringp x) ::|clisp:boolean|
  87. (instance? x <string>))
  88. (define (make-string (count :: <int>) ch)
  89. (make <gnu.lists.FString> count (invoke-static <gnu.commonlisp.lang.CommonLisp> 'asChar ch)))
  90. (define (substring (str :: <string>) from #!optional (to '()))
  91. (if (eq? to '())
  92. (set! to (string-length str)))
  93. (if (< to 0)
  94. (set! to (- (string-length str) to)))
  95. (if (< from 0)
  96. (set! from (- (string-length str) from)))
  97. (make <gnu.lists.FString> str (as <int> from) (as <int> (- to from))))
  98. (define (char-to-string ch)
  99. (make <gnu.lists.FString> 1 (invoke-static <gnu.commonlisp.lang.CommonLisp> 'asChar ch)))
  100. (define (functionp x) ::|clisp:boolean|
  101. (instance? x <function>))
  102. (define (princ value #!optional (out (current-output-port))) :: <void>
  103. (gnu.commonlisp.lang.CommonLisp:displayFormat:format value out))
  104. (define (prin1 value #!optional (out (current-output-port))) :: <void>
  105. (gnu.commonlisp.lang.CommonLisp:writeFormat:format value out))
  106. (define (apply func #!rest args)
  107. (kawa.standard.Scheme:apply
  108. (if (symbol? func) (symbol-function func) func)
  109. @args))