forked from coalton-lang/coalton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchar.lisp
50 lines (41 loc) · 1.25 KB
/
char.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(coalton-library/utils:defstdlib-package #:coalton-library/char
(:use
#:coalton
#:coalton-library/classes
#:coalton-library/builtin)
(:export
#:char-code
#:char-code-unchecked
#:code-char))
#+coalton-release
(cl:declaim #.coalton-impl:*coalton-optimize-library*)
(cl:in-package #:coalton-library/char)
(coalton-toplevel
(declare char-code (Char -> UFix))
(define (char-code char)
(lisp UFix (char)
(cl:char-code char)))
(declare code-char-unchecked (UFix -> Char))
(define (code-char-unchecked code)
(lisp Char (code)
(cl:code-char code)))
(declare code-char (UFix -> (Optional Char)))
(define (code-char code)
(lisp (Optional Char) (code)
;; not sufficient to compare against `char-code-limit', because the char-code space may be sparse.
(alexandria:if-let (char (cl:code-char code))
(Some char)
None)))
(define-instance (Eq Char)
(define (== x y)
(lisp Boolean (x y) (to-boolean (cl:char= x y)))))
(define-instance (Ord Char)
(define (<=> x y)
(if (== x y)
EQ
(if (lisp Boolean (x y) (to-boolean (cl:char> x y)))
GT
LT)))))
(define-sxhash-hasher Char)
#+sb-package-locks
(sb-ext:lock-package "COALTON-LIBRARY/CHAR")