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:
2026-10-16 19:06:55 +03:00
parent 09340ef981
commit 194152b3b6
3 changed files with 26 additions and 24 deletions

View File

@@ -12,7 +12,7 @@
sex-fmt-c
matchable
(chicken irregex) ; unkebabify
reader ; c-literal?
reader ; number-literal?
srfi-1 ; lists
srfi-13 ; strings
types ; array-bound?, named-arg?
@@ -348,7 +348,8 @@ forms, and what remains."
(remove comment-form? (cdr clause)))))
(if (pair? parts)
(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))))
(sex-error form "a case label is a value" (car parts)))
(when (member value seen)

View File

@@ -31,9 +31,9 @@
current-features
platform-features
c-literal?
c-literal-value
c-literal-suffix
number-literal?
number-literal-value
number-literal-suffix
;; for the tests
parse-all)
@@ -226,8 +226,8 @@
(cond ((exact-integer? n)
(cond ((> (abs n) +ullong-max+)
(error "too large for any C integer type" s))
((> n +llong-max+) (make-c-literal n "u" #f))
((< n +llong-min+) (list '- (make-c-literal (- n) "u" #f)))
((> n +llong-max+) (make-number-literal n "u" #f))
((< n +llong-min+) (list '- (make-number-literal (- n) "u" #f)))
(else n)))
((and (real? n) (inexact? n) (finite? n)) n)
(else (error "C has no literal for this number" s))))
@@ -240,19 +240,19 @@
;;; could round to another float, and 0.1L would
;;; lose all it has over one
;;; -1u -> (- 1u) which is what C reads it as too
(define-record-type <c-literal>
(make-c-literal value suffix digits)
c-literal?
(value c-literal-value)
(suffix c-literal-suffix)
(digits c-literal-digits))
(define-record-type <number-literal>
(make-number-literal value suffix digits)
number-literal?
(value number-literal-value)
(suffix number-literal-suffix)
(digits number-literal-digits))
(set-record-printer! <c-literal>
(set-record-printer! <number-literal>
(lambda (literal port)
(display (or (c-literal-digits literal)
(number->string (c-literal-value literal)))
(display (or (number-literal-digits literal)
(number->string (number-literal-value literal)))
port)
(display (c-literal-suffix literal) port)))
(display (number-literal-suffix literal) port)))
(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]?)"))
@@ -284,7 +284,7 @@
(widest (if (irregex-search "[uU]" suffix) +ullong-max+ +llong-max+)))
(when (> n widest)
(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
(define (hex-float-literal body s)
@@ -313,7 +313,7 @@
(define (float-literal n suffix digits s)
(unless (in-range? n suffix)
(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
;;; may be wider than any double, so whatever a double holds it does too

View File

@@ -13,7 +13,7 @@
sex-modules
types
matchable ; pattern matching
reader ; c-literal
reader ; number-literal
srfi-1 ; list routines
srfi-69 ; hash tables
utils
@@ -1245,9 +1245,10 @@
;;; 4000000000 -> (long long) 10L -> long
;;; 1.5f -> float 0.1L -> (long double)
;;; 0x1.8p3 -> double
(define (c-literal-type literal)
(let ((n (c-literal-value literal))
(suffix (map char-downcase (string->list (c-literal-suffix literal)))))
(define (number-literal-type literal)
(let ((n (number-literal-value literal))
(suffix (map char-downcase
(string->list (number-literal-suffix literal)))))
(cond ((exact? n) (integer-literal-type n suffix))
((memv #\f suffix) 'float)
((memv #\l suffix) '(long double))
@@ -1266,7 +1267,7 @@
(define (compute-expression-type expr env)
(cond
((c-literal? expr) (c-literal-type expr))
((number-literal? expr) (number-literal-type expr))
((and (number? expr) (exact? expr)) (integer-literal-type expr '()))
((number? expr) 'double)
((string? expr) '(* const char))