ffi/unsafe: fix _bitmask in non-application position

The exported `_bitmask` is a macro that picks up a compile-time name
when available, but the macro expanded inconsistently.

Closes #3367
This commit is contained in:
Matthew Flatt 2020-08-28 14:26:50 -06:00
parent 7382f5d7e4
commit f086075093
2 changed files with 9 additions and 3 deletions

View File

@ -157,6 +157,10 @@
(check s 'c 14)
(check s 'd 16))
(let ([_bm _bitmask])
(let ([s (_bm '(a b c = 14 d))])
(test 2 values (cast 'b s _int))))
(let ()
(define _test32_enum (_enum `(TEST32 = 1073741906) _sint32))
(define _test64_enum (_enum `(TEST64 = 4611686018427387904) _sint64))

View File

@ -964,8 +964,7 @@
;; the above with '= -- but the numbers have to be specified in some way. The
;; generated type will convert a list of these symbols into the logical-or of
;; their values and back.
(define (_bitmask name orig-s->i . base?)
(define basetype (if (pair? base?) (car base?) _uint))
(define (_bitmask/named name orig-s->i [basetype _uint])
(define s->c
(if name (string->symbol (format "bitmask:~a->int" name)) 'bitmask->int))
(define symbols->integers
@ -1005,12 +1004,15 @@
(cons (caar s->i) l)
l)))))))))
(define (_bitmask orig-s->i [base _uint])
(_bitmask/named #f orig-s->i base))
;; Macro wrapper -- no need for a name
(provide (rename-out [_bitmask* _bitmask]))
(define-syntax (_bitmask* stx)
(syntax-case stx ()
[(_ x ...)
(with-syntax ([name (syntax-local-name)]) #'(_bitmask 'name x ...))]
(with-syntax ([name (syntax-local-name)]) #'(_bitmask/named 'name x ...))]
[id (identifier? #'id) #'_bitmask]))
;; ----------------------------------------------------------------------------