-
Notifications
You must be signed in to change notification settings - Fork 71
/
primitive-types.lisp
76 lines (57 loc) · 2.37 KB
/
primitive-types.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;;; primitive-types.lisp
;;;;
;;;; Primitive types
(in-package #:coalton)
(named-readtables:in-readtable coalton:coalton)
#+coalton-release
(cl:declaim #.coalton-impl/settings:*coalton-optimize-library*)
(coalton-toplevel
(repr :native cl:t)
(define-type Void)
;; Boolean is an early type
(declare True Boolean)
(define True (lisp Boolean () cl:t))
(declare False Boolean)
(define False (lisp Boolean () cl:nil))
;; Unit is an early type
(declare Unit Unit)
(define Unit (lisp Unit () 'coalton::Unit/Unit))
;; List is an early type
(declare Cons (:a -> (List :a) -> (List :a)))
(define (Cons x xs)
(lisp (List :a) (x xs)
(cl:cons x xs)))
(declare Nil (List :a))
(define Nil
(lisp (List :a) ()
cl:nil))
(repr :native (cl:unsigned-byte 8))
(define-type U8
"Unsigned 8-bit integer capable of storing values in `[0, 255]`. Uses `(unsigned-byte 8)`.")
(repr :native (cl:unsigned-byte 16))
(define-type U16
"Unsigned 16-bit integer capable of storing values in `[0, 65535]`. Uses `(unsigned-byte 16)`.")
(repr :native (cl:unsigned-byte 32))
(define-type U32
"Unsigned 32-bit integer capable of storing values in `[0, 4294967295]`. Uses `(unsigned-byte 32)`.")
(repr :native (cl:unsigned-byte 64))
(define-type U64
"Unsigned 64-bit integer capable of storing values in `[0, 18446744073709551615]`. Uses `(unsigned-byte 64)`.")
(repr :native (cl:signed-byte 8))
(define-type I8
"Signed 8-bit integer capable of storing values in `[-128, 127]`. Uses `(signed-byte 8)`.")
(repr :native (cl:signed-byte 16))
(define-type I16
"Signed 16-bit integer capable of storing values in `[-32768, 32767]`. Uses `(signed-byte 16)`.")
(repr :native (cl:signed-byte 32))
(define-type I32
"Signed 32-bit integer capable of storing values in `[-2147483648, 2147483647]`. Uses `(signed-byte 32)`.")
(repr :native (cl:signed-byte 64))
(define-type I64
"Signed 64-bit integer capable of storing values in `[-9223372036854775808, 9223372036854775807]`. Uses `(signed-byte 64)`.")
(repr :native cl:fixnum)
(define-type IFix
"Non-allocating tagged integer; range is platform-dependent. Does not error on overflow. Uses `fixnum`.")
(repr :native (cl:and cl:fixnum cl:unsigned-byte))
(define-type UFix
"Non-allocating tagged non-negative integer; range is platform-dependent. Uses `(and fixnum unsigned-byte)`."))