[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.7.10.1 Vtables
A vtable is a structure type, specifying its layout, and other information. A vtable is actually itself a structure, but there’s no need to worry about that initially (see section Vtable Contents.)
- Scheme Procedure: make-vtable fields [print]
Create a new vtable.
fields is a string describing the fields in the structures to be created. Each field is represented by two characters, a type letter and a permissions letter, for example
"pw"
. The types are as follows.-
p
– a Scheme value. “p” stands for “protected” meaning it’s protected against garbage collection. -
u
– an arbitrary word of data (anscm_t_bits
). At the Scheme level it’s read and written as an unsigned integer. “u” stands for “uninterpreted” (it’s not treated as a Scheme value), or “unprotected” (it’s not marked during GC), or “unsigned long” (its size), or all of these things. -
s
– a self-reference. Such a field holds theSCM
value of the structure itself (a circular reference). This can be useful in C code where you might have a pointer to the data array, and want to get the SchemeSCM
handle for the structure. In Scheme code it has no use.
The second letter for each field is a permission code,
-
w
– writable, the field can be read and written. -
r
– read-only, the field can be read but not written. -
o
– opaque, the field can be neither read nor written at the Scheme level. This can be used for fields which should only be used from C code.
Here are some examples. See section Tail Arrays, for information on the legacy tail array facility.
(make-vtable "pw") ;; one writable field (make-vtable "prpw") ;; one read-only and one writable (make-vtable "pwuwuw") ;; one scheme and two uninterpreted
The optional print argument is a function called by
display
andwrite
(etc) to give a printed representation of a structure created from this vtable. It’s called(print struct port)
and should look at struct and write to port. The default print merely gives a form like ‘#<struct ADDR:ADDR>’ with a pair of machine addresses.The following print function for example shows the two fields of its structure.
(make-vtable "prpw" (lambda (struct port) (format port "#<~a and ~a>" (struct-ref struct 0) (struct-ref struct 1))))
-
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on April 20, 2013 using texi2html 5.0.