manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5 Inline procedures

Bigloo allows procedures called inline and which differ from normal ones only in the type of code planted. An inline procedure is a first class object which can be manipulated in the same way as any other procedure but when Bigloo sees a reference to one, rather than generating a C function call to the function, the body of the inline procedure is open-coded. The definition of an inline is given in the following way:

bigloo syntax: define-inline (name args …) body
bigloo syntax: define-inline (name args … . arg) body

Apart from the initial word, this form has the same syntax as that used by define for procedures. Inline procedures are exportable which means that the compiler scans imported files to find the bodies of all inline procedures. Here is a small example of a module which exports an inline and a module which imports it.

;; the exporter module
(module exporter
        (export (inline make-list . objs)))

(define-inline (make-list . objs) objs)
;; the importer module
(module importer
        (import exporter))

(print (make-list 1 2 3 4 5))

Because of the open-coding of the exporter procedure, the above print statement is equivalent to:

(print (let ((objs (list 1 2 3 4 5)))
          objs))

Any procedure can be an inline. Also any exported procedure can be an inline provided all global variables and functions it uses are also exported.

Note: Bigloo can decide to inline procedures declared with define but this can be achieved only with local procedures whereas procedures declared with the define-inline form are open-coded even through module importation.

Note: Procedures declared inline are macro expanded with the macro defined in the module where they are invoked. That is, if module module1 declares an inline procedure p and module module2 imports it, p may have two different macro-expansions: one for module1 and one for module2.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on October 23, 2011 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.