promote the prelude's integer types like C's own
u8 and i32 are typedefs of <stdint.h> names nothing parses, so they had no rank: (+ a a) over two u8 200s was a u8 holding 144, and (+ n 1) over an i32 could not be typed at all.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"partial: 1 2.5"
|
"partial: 1 2.5"
|
||||||
"joined: 43.5 84 49 1"
|
"joined: 43.5 84 49 1"
|
||||||
"promoted: 200 60000 3705032704"
|
"promoted: 200 60000 3705032704"
|
||||||
|
"prelude: 400 6"
|
||||||
"from elements: 4 9 0")
|
"from elements: 4 9 0")
|
||||||
(return 0)
|
(return 0)
|
||||||
|
|
||||||
@@ -105,6 +106,14 @@
|
|||||||
(var unpromoted _ (+ kept kept))
|
(var unpromoted _ (+ kept kept))
|
||||||
(printf "promoted: %d %d %u\n" narrow narrower unpromoted)
|
(printf "promoted: %d %d %u\n" narrow narrower unpromoted)
|
||||||
|
|
||||||
|
;; the prelude's widths are C's own types under other names, and
|
||||||
|
;; promote the way those do
|
||||||
|
(var b8 u8 200)
|
||||||
|
(var w32 i32 5)
|
||||||
|
(var bytes _ (+ b8 b8))
|
||||||
|
(var next _ (+ w32 1))
|
||||||
|
(printf "prelude: %d %d\n" bytes next)
|
||||||
|
|
||||||
;; a brace initializer has no type of its own, but its elements solve
|
;; a brace initializer has no type of its own, but its elements solve
|
||||||
;; the hole in the array type around it -- and the length stays as
|
;; the hole in the array type around it -- and the length stays as
|
||||||
;; written, whether or not every slot is initialized
|
;; written, whether or not every slot is initialized
|
||||||
|
|||||||
@@ -42,14 +42,17 @@
|
|||||||
#f
|
#f
|
||||||
(get-fields 't-color))
|
(get-fields 't-color))
|
||||||
|
|
||||||
(add-typedef 't-u8 '(typedef t-u8 uint8-t))
|
(add-typedef 't-u8 '(typedef t-u8 gl-ubyte))
|
||||||
(test "a typedef resolves to its target"
|
(test "a typedef resolves to its target"
|
||||||
'uint8-t
|
'gl-ubyte
|
||||||
(get-underlying-type 't-u8))
|
(get-underlying-type 't-u8))
|
||||||
(add-typedef 't-byte '(typedef t-byte t-u8))
|
(add-typedef 't-byte '(typedef t-byte t-u8))
|
||||||
(test "and chains are followed to the end"
|
(test "and chains are followed to the end"
|
||||||
'uint8-t
|
'gl-ubyte
|
||||||
(get-underlying-type 't-byte))
|
(get-underlying-type 't-byte))
|
||||||
|
(test "stdint.h's exact-width types are C's own"
|
||||||
|
'(unsigned char)
|
||||||
|
(get-underlying-type 'uint8-t))
|
||||||
(test "a struct is not a typedef"
|
(test "a struct is not a typedef"
|
||||||
#f
|
#f
|
||||||
(get-underlying-type 't-point))
|
(get-underlying-type 't-point))
|
||||||
|
|||||||
10
types.scm
10
types.scm
@@ -125,6 +125,16 @@
|
|||||||
(hash-table-set! +type-db+ name
|
(hash-table-set! +type-db+ name
|
||||||
(list 'typedef name (last (strip-pub form)))))
|
(list 'typedef name (last (strip-pub form)))))
|
||||||
|
|
||||||
|
;;; <stdint.h>, which nothing parses, as far as arithmetic asks: the
|
||||||
|
;;; prelude's `u8' is a `uint8-t', so (+ a a) over two of them is an
|
||||||
|
;;; `int', promoted like any narrow type. The 64-bit pair is `long' on
|
||||||
|
;;; some hosts; it ranks above the narrower ones either way.
|
||||||
|
(for-each (lambda (entry) (add-typedef (car entry) (cons 'typedef entry)))
|
||||||
|
'((int8-t (signed char)) (uint8-t (unsigned char))
|
||||||
|
(int16-t short) (uint16-t (unsigned short))
|
||||||
|
(int32-t int) (uint32-t (unsigned int))
|
||||||
|
(int64-t (long long)) (uint64-t (unsigned long long))))
|
||||||
|
|
||||||
;;; (define name value ...) -- a C #define, kept so a macro can read a
|
;;; (define name value ...) -- a C #define, kept so a macro can read a
|
||||||
;;; compile-time constant rather than re-parse the source.
|
;;; compile-time constant rather than re-parse the source.
|
||||||
(define (add-define name form)
|
(define (add-define name form)
|
||||||
|
|||||||
Reference in New Issue
Block a user