forked from alex-eg/sex
rename the reader's number record to number-literal
sex-fmt-c exports a c-literal? of its own, and the writer imports both; which one it got depended on the order of its imports.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
sex-fmt-c
|
sex-fmt-c
|
||||||
matchable
|
matchable
|
||||||
(chicken irregex) ; unkebabify
|
(chicken irregex) ; unkebabify
|
||||||
reader ; c-literal?
|
reader ; number-literal?
|
||||||
srfi-1 ; lists
|
srfi-1 ; lists
|
||||||
srfi-13 ; strings
|
srfi-13 ; strings
|
||||||
types ; array-bound?, named-arg?
|
types ; array-bound?, named-arg?
|
||||||
@@ -339,7 +339,8 @@ forms, and what remains."
|
|||||||
(remove comment-form? (cdr clause)))))
|
(remove comment-form? (cdr clause)))))
|
||||||
(if (pair? parts)
|
(if (pair? parts)
|
||||||
(fold (lambda (value seen)
|
(fold (lambda (value seen)
|
||||||
(unless (or (number? value) (char? value) (c-literal? value)
|
(unless (or (number? value) (char? value)
|
||||||
|
(number-literal? value)
|
||||||
(and (symbol? value) (not (operator-arity value))))
|
(and (symbol? value) (not (operator-arity value))))
|
||||||
(sex-error form "a case label is a value" (car parts)))
|
(sex-error form "a case label is a value" (car parts)))
|
||||||
(when (member value seen)
|
(when (member value seen)
|
||||||
|
|||||||
34
reader.scm
34
reader.scm
@@ -31,9 +31,9 @@
|
|||||||
current-features
|
current-features
|
||||||
platform-features
|
platform-features
|
||||||
|
|
||||||
c-literal?
|
number-literal?
|
||||||
c-literal-value
|
number-literal-value
|
||||||
c-literal-suffix)
|
number-literal-suffix)
|
||||||
|
|
||||||
;;; Sentinels for structural tokens
|
;;; Sentinels for structural tokens
|
||||||
(define close-paren (list '%close-paren))
|
(define close-paren (list '%close-paren))
|
||||||
@@ -223,8 +223,8 @@
|
|||||||
(cond ((exact-integer? n)
|
(cond ((exact-integer? n)
|
||||||
(cond ((> (abs n) +ullong-max+)
|
(cond ((> (abs n) +ullong-max+)
|
||||||
(error "too large for any C integer type" s))
|
(error "too large for any C integer type" s))
|
||||||
((> n +llong-max+) (make-c-literal n "u" #f))
|
((> n +llong-max+) (make-number-literal n "u" #f))
|
||||||
((< n +llong-min+) (list '- (make-c-literal (- n) "u" #f)))
|
((< n +llong-min+) (list '- (make-number-literal (- n) "u" #f)))
|
||||||
(else n)))
|
(else n)))
|
||||||
((and (real? n) (inexact? n) (finite? n)) n)
|
((and (real? n) (inexact? n) (finite? n)) n)
|
||||||
(else (error "C has no literal for this number" s))))
|
(else (error "C has no literal for this number" s))))
|
||||||
@@ -237,19 +237,19 @@
|
|||||||
;;; could round to another float, and 0.1L would
|
;;; could round to another float, and 0.1L would
|
||||||
;;; lose all it has over one
|
;;; lose all it has over one
|
||||||
;;; -1u -> (- 1u) which is what C reads it as too
|
;;; -1u -> (- 1u) which is what C reads it as too
|
||||||
(define-record-type <c-literal>
|
(define-record-type <number-literal>
|
||||||
(make-c-literal value suffix digits)
|
(make-number-literal value suffix digits)
|
||||||
c-literal?
|
number-literal?
|
||||||
(value c-literal-value)
|
(value number-literal-value)
|
||||||
(suffix c-literal-suffix)
|
(suffix number-literal-suffix)
|
||||||
(digits c-literal-digits))
|
(digits number-literal-digits))
|
||||||
|
|
||||||
(set-record-printer! <c-literal>
|
(set-record-printer! <number-literal>
|
||||||
(lambda (literal port)
|
(lambda (literal port)
|
||||||
(display (or (c-literal-digits literal)
|
(display (or (number-literal-digits literal)
|
||||||
(number->string (c-literal-value literal)))
|
(number->string (number-literal-value literal)))
|
||||||
port)
|
port)
|
||||||
(display (c-literal-suffix literal) port)))
|
(display (number-literal-suffix literal) port)))
|
||||||
|
|
||||||
(define suffixed-integer
|
(define suffixed-integer
|
||||||
(irregex "(0[xX][0-9a-fA-F]+|0[bB][01]+|[0-9]+)([uU](?:ll|LL|l|L)?|(?:ll|LL|l|L)[uU]?)"))
|
(irregex "(0[xX][0-9a-fA-F]+|0[bB][01]+|[0-9]+)([uU](?:ll|LL|l|L)?|(?:ll|LL|l|L)[uU]?)"))
|
||||||
@@ -281,7 +281,7 @@
|
|||||||
(widest (if (irregex-search "[uU]" suffix) +ullong-max+ +llong-max+)))
|
(widest (if (irregex-search "[uU]" suffix) +ullong-max+ +llong-max+)))
|
||||||
(when (> n widest)
|
(when (> n widest)
|
||||||
(error "too large for its suffix" s))
|
(error "too large for its suffix" s))
|
||||||
(make-c-literal n suffix #f)))))
|
(make-number-literal n suffix #f)))))
|
||||||
|
|
||||||
;;; 0x1.8p3 is 0x18 sixteenths times 2^3
|
;;; 0x1.8p3 is 0x18 sixteenths times 2^3
|
||||||
(define (hex-float-literal body s)
|
(define (hex-float-literal body s)
|
||||||
@@ -310,7 +310,7 @@
|
|||||||
(define (float-literal n suffix digits s)
|
(define (float-literal n suffix digits s)
|
||||||
(unless (in-range? n suffix)
|
(unless (in-range? n suffix)
|
||||||
(error "C has no literal for this number" s))
|
(error "C has no literal for this number" s))
|
||||||
(make-c-literal n suffix digits))
|
(make-number-literal n suffix digits))
|
||||||
|
|
||||||
;;; A float overflows where it would round past FLT_MAX; a long double
|
;;; A float overflows where it would round past FLT_MAX; a long double
|
||||||
;;; may be wider than any double, so whatever a double holds it does too
|
;;; may be wider than any double, so whatever a double holds it does too
|
||||||
|
|||||||
11
semen.scm
11
semen.scm
@@ -13,7 +13,7 @@
|
|||||||
sex-modules
|
sex-modules
|
||||||
types
|
types
|
||||||
matchable ; pattern matching
|
matchable ; pattern matching
|
||||||
reader ; c-literal
|
reader ; number-literal
|
||||||
srfi-1 ; list routines
|
srfi-1 ; list routines
|
||||||
srfi-69 ; hash tables
|
srfi-69 ; hash tables
|
||||||
utils
|
utils
|
||||||
@@ -1240,9 +1240,10 @@
|
|||||||
;;; 4000000000 -> (long long) 10L -> long
|
;;; 4000000000 -> (long long) 10L -> long
|
||||||
;;; 1.5f -> float 0.1L -> (long double)
|
;;; 1.5f -> float 0.1L -> (long double)
|
||||||
;;; 0x1.8p3 -> double
|
;;; 0x1.8p3 -> double
|
||||||
(define (c-literal-type literal)
|
(define (number-literal-type literal)
|
||||||
(let ((n (c-literal-value literal))
|
(let ((n (number-literal-value literal))
|
||||||
(suffix (map char-downcase (string->list (c-literal-suffix literal)))))
|
(suffix (map char-downcase
|
||||||
|
(string->list (number-literal-suffix literal)))))
|
||||||
(cond ((exact? n) (integer-literal-type n suffix))
|
(cond ((exact? n) (integer-literal-type n suffix))
|
||||||
((memv #\f suffix) 'float)
|
((memv #\f suffix) 'float)
|
||||||
((memv #\l suffix) '(long double))
|
((memv #\l suffix) '(long double))
|
||||||
@@ -1258,7 +1259,7 @@
|
|||||||
|
|
||||||
(define (expression-type expr env)
|
(define (expression-type expr env)
|
||||||
(cond
|
(cond
|
||||||
((c-literal? expr) (c-literal-type expr))
|
((number-literal? expr) (number-literal-type expr))
|
||||||
((and (number? expr) (exact? expr)) (integer-literal-type expr '()))
|
((and (number? expr) (exact? expr)) (integer-literal-type expr '()))
|
||||||
((number? expr) 'double)
|
((number? expr) 'double)
|
||||||
((string? expr) '(* const char))
|
((string? expr) '(* const char))
|
||||||
|
|||||||
Reference in New Issue
Block a user