forked from alex-eg/sex
read hex and binary literals
0x80 was not a number to string->number, so it became a symbol the printer escaped as |0x80|, and #x was rejected outright. Both spellings now read as the integer, which the C writes in decimal. Fixes #47.
This commit is contained in:
@@ -47,6 +47,13 @@
|
||||
(reader-test '(-1 -1.5) "-1 -1.5")
|
||||
(reader-test '(- -> ->> -- -=) "- -> ->> -- -=")
|
||||
|
||||
;; a number in another radix, spelled the way C does or the way
|
||||
;; Scheme does; either is an ordinary integer from here on
|
||||
(reader-test '(224 224 5 5 -16) "0xE0 0Xe0 0b101 0B101 -0x10")
|
||||
(reader-test '(128 128 5 8 -16) "#x80 #X80 #b101 #o10 #x-10")
|
||||
;; ...and only a number: a prefix with nothing after it is a name
|
||||
(reader-test '(0x 0xg) "0x 0xg")
|
||||
|
||||
;; `;' comments are preserved as (comment "...") forms
|
||||
(reader-test '((comment " hi")) "; hi")
|
||||
(reader-test '((comment ";; Prototypes")) ";;; Prototypes")
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"unsigned wins either way: 4294967295 4294967295"
|
||||
"toplevel: 1 2.5 hi 12"
|
||||
"closure in place: 5"
|
||||
"a type is not a call: 7")
|
||||
"a type is not a call: 7"
|
||||
"radix literals: 224 5 128")
|
||||
(return 0)
|
||||
|
||||
;;; The walk types an expression by its head, and the heads it had a
|
||||
@@ -87,4 +88,8 @@
|
||||
(var f (closure ((int)) int) (make-adder 1))
|
||||
(var fp (fn ((f int) (g int)) int) area)
|
||||
(printf "a type is not a call: %d\n" (f 6))
|
||||
|
||||
;; a mask reads best in the radix it is a mask in
|
||||
(var lead int 0xE5)
|
||||
(printf "radix literals: %d %d %d\n" (& lead 0xE0) (& lead 0b111) #x80)
|
||||
(return 0))
|
||||
|
||||
Reference in New Issue
Block a user