diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-09-02 00:07:27 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-09-02 01:37:37 +0200 |
commit | 5f236208d0d864546e59afa0f5a11c9b3ba14b10 (patch) | |
tree | eed5d9203a2633c8efb85c1b36425eab87574299 /doc/ref/api-procedures.texi | |
parent | f0eb5ae6c173aed35965b0561897fda1d8ff0db1 (diff) | |
parent | d7e7a02a6251c8ed4f76933d9d30baeee3f599c0 (diff) | |
download | guile-bdw-gc-static-alloc.tar.gz |
Merge branch 'boehm-demers-weiser-gc' into bdw-gc-static-allocbdw-gc-static-alloc
Conflicts:
acinclude.m4
libguile/strings.c
Diffstat (limited to 'doc/ref/api-procedures.texi')
-rw-r--r-- | doc/ref/api-procedures.texi | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/doc/ref/api-procedures.texi b/doc/ref/api-procedures.texi index 7fd0f4fa4..8098b4ffb 100644 --- a/doc/ref/api-procedures.texi +++ b/doc/ref/api-procedures.texi @@ -11,6 +11,7 @@ @menu * Lambda:: Basic procedure creation using lambda. * Primitive Procedures:: Procedures defined in C. +* Compiled Procedures:: Scheme procedures can be compiled. * Optional Arguments:: Handling keyword, optional and rest arguments. * Procedure Properties:: Procedure properties and meta-information. * Procedures with Setters:: Procedures with setters. @@ -131,6 +132,156 @@ use @code{scm_c_make_subr} and also @code{scm_makcclo} if necessary. It is advisable to use the gsubr variants since they provide a slightly higher-level abstraction of the Guile implementation. +@node Compiled Procedures +@subsection Compiled Procedures + +Procedures that were created when loading a compiled file are +themselves compiled. (In contrast, procedures that are defined by +loading a Scheme source file are interpreted, and often not as fast as +compiled procedures.) + +Loading compiled files is the normal way that compiled procedures come +to being, though procedures can be compiled at runtime as well. +@xref{Read/Load/Eval/Compile}, for more information on runtime +compilation. + +Compiled procedures, also known as @dfn{programs}, respond all +procedures that operate on procedures. In addition, there are a few +more accessors for low-level details on programs. + +Most people won't need to use the routines described in this section, +but it's good to have them documented. You'll have to include the +appropriate module first, though: + +@example +(use-modules (system vm program)) +@end example + +@deffn {Scheme Procedure} program? obj +@deffnx {C Function} scm_program_p (obj) +Returns @code{#t} iff @var{obj} is a compiled procedure. +@end deffn + +@deffn {Scheme Procedure} program-objcode program +@deffnx {C Function} scm_program_objcode (program) +Returns the object code associated with this program. @xref{Bytecode +and Objcode}, for more information. +@end deffn + +@deffn {Scheme Procedure} program-objects program +@deffnx {C Function} scm_program_objects (program) +Returns the ``object table'' associated with this program, as a +vector. @xref{VM Programs}, for more information. +@end deffn + +@deffn {Scheme Procedure} program-module program +@deffnx {C Function} scm_program_module (program) +Returns the module that was current when this program was created. Can +return @code{#f} if the compiler could determine that this information +was unnecessary. +@end deffn + +@deffn {Scheme Procedure} program-external program +@deffnx {C Function} scm_program_external (program) +Returns the set of heap-allocated variables that this program captures +in its closure, as a list. If a closure is code with data, you can get +the code from @code{program-bytecode}, and the data via +@code{program-external}. + +Users must not modify the returned value unless they think they're +really clever. +@end deffn + +@deffn {Scheme Procedure} program-external-set! program external +@deffnx {C Function} scm_program_external_set_x (program, external) +Set @var{external} as the set of closure variables on @var{program}. + +The Guile maintainers will not be held responsible for side effects of +calling this function, including but not limited to replacement of +shampoo with hair dye, and a slight salty taste in tomorrow's dinner. +@end deffn + +@deffn {Scheme Procedure} program-arity program +@deffnx {C Function} scm_program_arity (program) +@deffnx {Scheme Procedure} arity:nargs arity +@deffnx {Scheme Procedure} arity:nrest arity +@deffnx {Scheme Procedure} arity:nlocs arity +@deffnx {Scheme Procedure} arity:nexts arity +Accessors for a representation of the ``arity'' of a program. + +@code{nargs} is the number of arguments to the procedure, and +@code{nrest} will be non-zero if the last argument is a rest argument. + +The other two accessors determine the number of local and external +(heap-allocated) variables that this procedure will need to have +allocated. +@end deffn + +@deffn {Scheme Procedure} program-meta program +@deffnx scm_program_meta (program) +Return the metadata thunk of @var{program}, or @code{#f} if it has no +metadata. + +When called, a metadata thunk returns a list of the following form: +@code{(@var{bindings} @var{sources} . @var{properties})}. The format +of each of these elements is discussed below. +@end deffn + +@deffn {Scheme Procedure} program-bindings program +@deffnx {Scheme Procedure} make-binding name extp index start end +@deffnx {Scheme Procedure} binding:name binding +@deffnx {Scheme Procedure} binding:extp binding +@deffnx {Scheme Procedure} binding:index binding +@deffnx {Scheme Procedure} binding:start binding +@deffnx {Scheme Procedure} binding:end binding +Bindings annotations for programs, along with their accessors. + +Bindings declare names and liveness extents for block-local variables. +The best way to see what these are is to play around with them at a +REPL. The only tricky bit is that @var{extp} is a boolean, declaring +whether the binding is heap-allocated or not. @xref{VM Concepts}, for +more information. + +Note that bindings information is stored in a program as part of its +metadata thunk, so including it in the generated object code does not +impose a runtime performance penalty. +@end deffn + +@deffn {Scheme Procedure} program-sources program +@deffnx {Scheme Procedure} source:addr source +@deffnx {Scheme Procedure} source:line source +@deffnx {Scheme Procedure} source:column source +@deffnx {Scheme Procedure} source:file source +Source location annotations for programs, along with their accessors. + +Source location information propagates through the compiler and ends +up being serialized to the program's metadata. This information is +keyed by the offset of the instruction pointer within the object code +of the program. Specifically, it is keyed on the @code{ip} @emph{just +following} an instruction, so that backtraces can find the source +location of a call that is in progress. +@end deffn + +@deffn {Scheme Procedure} program-properties program +Return the properties of a @code{program} as an association list, +keyed by property name (a symbol). + +Some interesting properties include: +@itemize +@item @code{name}, the name of the procedure +@item @code{documentation}, the procedure's docstring +@end itemize +@end deffn + +@deffn {Scheme Procedure} program-property program name +Access a program's property by name, returning @code{#f} if not found. +@end deffn + +@deffn {Scheme Procedure} program-documentation program +@deffnx {Scheme Procedure} program-name program +Accessors for specific properties. +@end deffn + @node Optional Arguments @subsection Optional Arguments |