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 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?
@@ -348,7 +348,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)

View File

@@ -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
;; for the tests ;; for the tests
parse-all) parse-all)
@@ -226,8 +226,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))))
@@ -240,19 +240,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]?)"))
@@ -284,7 +284,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)
@@ -313,7 +313,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

View File

@@ -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
@@ -1245,9 +1245,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))
@@ -1266,7 +1267,7 @@
(define (compute-expression-type expr env) (define (compute-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))