-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype-sizes.lisp
More file actions
60 lines (52 loc) · 1.45 KB
/
type-sizes.lisp
File metadata and controls
60 lines (52 loc) · 1.45 KB
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
;;; -*- mode: Lisp; coding: utf-8-unix -*-
#+:sbcl
(in-package :repl)
(require "cpu")
#+:repl (require "runtime/eq")
#+:repl (require "runtime/logic")
#+:repl (require "runtime/error")
#+:repl (require "runtime/math")
(defvar *SIZEOF_BYTE* 1)
(defvar *SIZEOF_SHORT* 2)
(defvar *SIZEOF_USHORT* 2)
(defvar *SIZEOF_POINTER* 4)
(defvar *SIZEOF_LONG* 4)
(defvar *SIZEOF_ULONG* 4)
(defvar *SIZEOF_LONG64* 8)
(defvar *SIZEOF_ULONG64* 8)
(defvar *SIZEOF_FLOAT* 4)
#+:sbcl (require "conditions")
#+:repl (require "runtime/error")
#+:sbcl
(define-condition unknown-data-type-error (repl-error)
((type :initarg :type))
(:report (lambda (condition stream)
(format stream "Unknown data type: ~A~%" (slot-value condition 'type)))))
(defun type-atom? (type)
(cond
((eq type :pointer) t)
((eq type :byte) t)
((eq type :short) t)
((eq type :long) t)
((eq type :long64) t)
((eq type :float) t)
((eq type :ubyte) t)
((eq type :ushort) t)
((eq type :ulong) t)
((eq type :ulong64) t)
(t nil)))
(defun type-size (type)
(cond
((or (eq type :long64) (eq type :ulong64))
*SIZEOF_LONG64*)
((or (eq type :long) (or (eq type :ulong) (eq type :pointer)))
*SIZEOF_LONG*)
((or (eq type :short) (eq type :ushort))
*SIZEOF_SHORT*)
((or (eq type :byte) (eq type :ubyte))
*SIZEOF_BYTE*)
((eq type :float)
*SIZEOF_FLOAT*)
((eq type nil)
0)
(t (error 'unknown-data-type-error :type type))))