Go to the previous, next section.

Byte-Code Objects

Byte-compiled functions have a special data type: they are byte-code function objects.

Internally, a byte-code function object is much like a vector; however, the evaluator handles this data type specially when it appears as a function to be called. The printed representation for a byte-code function object is like that for a vector, with an additional `#' before the opening `['.

In Emacs version 18, there was no byte-code function object data type; compiled functions used the function byte-code to run the byte code.

A byte-code function object must have at least four elements; there is no maximum number, but only the first six elements are actually used. They are:

arglist
The list of argument symbols.

byte-code
The string containing the byte-code instructions.

constants
The vector of constants referenced by the byte code.

stacksize
The maximum stack size this function needs.

docstring
The documentation string (if any); otherwise, nil. For functions preloaded before Emacs is dumped, this is usually an integer which is an index into the `DOC' file; use documentation to convert this into a string (see section Access to Documentation Strings).

interactive
The interactive spec (if any). This can be a string or a Lisp expression. It is nil for a function that isn't interactive.

Here's an example of a byte-code function object, in printed representation. It is the definition of the command backward-sexp.

#[(&optional arg)
  "^H\204^F^@\301^P\302^H[!\207"
  [arg 1 forward-sexp]
  2
  254435
  "p"]

The primitive way to create a byte-code object is with make-byte-code:

Function: make-byte-code &rest elements

This function constructs and returns a byte-code function object with elements as its elements.

You should not try to come up with the elements for a byte-code function yourself, because if they are inconsistent, Emacs may crash when you call the function. Always leave it to the byte-compiler to create these objects; it, we hope, always makes the elements consistent.

You can access the elements of a byte-code object using aref; you can also use vconcat to create a vector with the same elements.

Go to the previous, next section.