mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-08 22:50:27 +02:00
Move `define-inlinable' into the default namespace
* module/ice-9/boot-9.scm (define-inlineable): Moved here from SRFI-9. * module/srfi/srfi-9 (define-inlinable): Removed here. * doc/ref/api-procedures.texi (Inlinable Procedures): Add subsection about `define-inlinable'.
This commit is contained in:
parent
6ebecdeb7d
commit
165b10ddfa
3 changed files with 64 additions and 33 deletions
|
@ -3496,6 +3496,42 @@ module '(ice-9 q) '(make-q q-length))}."
|
|||
(syntax-violation 'require-extension "Not a recognized extension type"
|
||||
x)))))
|
||||
|
||||
|
||||
;;; Defining transparently inlinable procedures
|
||||
;;;
|
||||
|
||||
(define-syntax define-inlinable
|
||||
;; Define a macro and a procedure such that direct calls are inlined, via
|
||||
;; the macro expansion, whereas references in non-call contexts refer to
|
||||
;; the procedure. Inspired by the `define-integrable' macro by Dybvig et al.
|
||||
(lambda (x)
|
||||
;; Use a space in the prefix to avoid potential -Wunused-toplevel
|
||||
;; warning
|
||||
(define prefix (string->symbol "% "))
|
||||
(define (make-procedure-name name)
|
||||
(datum->syntax name
|
||||
(symbol-append prefix (syntax->datum name)
|
||||
'-procedure)))
|
||||
|
||||
(syntax-case x ()
|
||||
((_ (name formals ...) body ...)
|
||||
(identifier? #'name)
|
||||
(with-syntax ((proc-name (make-procedure-name #'name))
|
||||
((args ...) (generate-temporaries #'(formals ...))))
|
||||
#`(begin
|
||||
(define (proc-name formals ...)
|
||||
body ...)
|
||||
(define-syntax name
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ args ...)
|
||||
#'((lambda (formals ...)
|
||||
body ...)
|
||||
args ...))
|
||||
(_
|
||||
(identifier? x)
|
||||
#'proc-name))))))))))
|
||||
|
||||
|
||||
|
||||
(define using-readline?
|
||||
|
|
|
@ -64,38 +64,6 @@
|
|||
|
||||
(cond-expand-provide (current-module) '(srfi-9))
|
||||
|
||||
(define-syntax define-inlinable
|
||||
;; Define a macro and a procedure such that direct calls are inlined, via
|
||||
;; the macro expansion, whereas references in non-call contexts refer to
|
||||
;; the procedure. Inspired by the `define-integrable' macro by Dybvig et al.
|
||||
(lambda (x)
|
||||
;; Use a space in the prefix to avoid potential -Wunused-toplevel
|
||||
;; warning
|
||||
(define prefix (string->symbol "% "))
|
||||
(define (make-procedure-name name)
|
||||
(datum->syntax name
|
||||
(symbol-append prefix (syntax->datum name)
|
||||
'-procedure)))
|
||||
|
||||
(syntax-case x ()
|
||||
((_ (name formals ...) body ...)
|
||||
(identifier? #'name)
|
||||
(with-syntax ((proc-name (make-procedure-name #'name))
|
||||
((args ...) (generate-temporaries #'(formals ...))))
|
||||
#`(begin
|
||||
(define (proc-name formals ...)
|
||||
body ...)
|
||||
(define-syntax name
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ args ...)
|
||||
#'((lambda (formals ...)
|
||||
body ...)
|
||||
args ...))
|
||||
(_
|
||||
(identifier? x)
|
||||
#'proc-name))))))))))
|
||||
|
||||
(define-syntax define-record-type
|
||||
(lambda (x)
|
||||
(define (field-identifiers field-specs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue