Abstract Syntax Tree. Interface to the types used by the compiler, and other core types less commonly needed in user code, plus related utilities.
Expands and analyzes the expression x
and returns the
resulting AST.
Runs an optimization pass on ast
and returns the
resulting simplified expression.
Performs a full syntax expansion of the form x
and
returns the resulting s-expression.
Convert ast
to a s-expression, renaming variables if
necessary.
Returns a new procedure wrapping the input procedure proc
.
The returned procedure, if used as a macro transformer procedure,
can expand an instance of set!
with its keyword on the
left hand side.
A high-level form for creating identifier macros. See the R6RS specification.
All objects have an associated type, and types may have parent
types. When using
SRFI-9
define-record-type
, the name is bound to a first class
type object.
The following core types are also available by name, and may be
used in the match
($ ...)
syntax.
Object
- the parent of all typesNumber
- abstract numeric typeBignum
- arbitrary precision exact integersFlonum
- inexact real numbersInteger
- abstract integer typeSymbol
- symbolsChar
- characterBoolean
-#t
or#f
String
- strings of charactersByte-Vector
- uniform vector of octetsPair
- acar
andcdr
, the basis for listsVector
- vectorsOpcode
- a primitive opcode or C functionProcedure
- a closureBytecode
- the compiled code for a closureEnv
- an environment structureMacro
- a macro object, usually not first-classLam
- a lambda AST typeCnd
- an conditional AST type (i.e.if
)Ref
- a reference AST typeSet
- a mutation AST type (i.e.set!
)Seq
- a sequence AST typeLit
- a literal AST typeSc
- a syntactic closureContext
- a context object (including threads)Exception
- an exception object
The following extended type predicates may also be used to test individual objects for their type:
environment?
bytecode?
macro?
syntactic-closure?
lambda?
cnd?
ref?
set?
seq?
lit?
opcode?
type?
context?
exception?
Returns the type of any object x
.
Returns the name of type type
.
Returns the immediate parent of type type
,
or #f
for a type with no parent.
Returns the class precedence list of type type
as a
vector, or #f
for a type with no parent.
Returns the slot list of type type
.
This section describes additional accessors on AST and other core types.
(procedure-code f)
- the compiled bytecode object(procedure-vars f)
- the variables closed over byf
(procedure-name f)
- the name off
if known, else#f
(macro-procedure f)
- the macro procedure(macro-env f)
- the environment the macro was defined in(macro-source f)
- the source location the macro was defined in(macro-aux f)
- custom auxiliary data stored with the macro(macro-aux-set! f x)
(bytecode-name bc)
- the macro procedure(bytecode-literals bc)
- literals the bytecode references(bytecode-source bc)
- the source location the procedure was defined in
(syntactic-closure-env sc)
(syntactic-closure-vars sc)
(syntactic-closure-expr sc)
Return the environment, free variables, and expression
associated with sc
respectively.
(exception-kind exn)
(exception-message exn)
(exception-irritants exn)
Return the kind, message, and irritants
associated with exn
respectively.
(lambda-name lam)
- the name of the lambda, if known(lambda-name-set! lam x)
(lambda-params lam)
- the lambda parameter list(lambda-params-set! lam x)
(lambda-body lam)
- the body of the lambda(lambda-body-set! lam x)
(lambda-defs lam)
- internal definitions of the lambda(lambda-defs-set! lam x)
(lambda-locals lam)
- local variables as a list of identifiers(lambda-locals-set! lam x)
(lambda-flags lam)
- various flags describing the lambda(lambda-flags-set! lam x)
(lambda-free-vars lam)
- free variables the lambda will need to close over(lambda-free-vars-set! lam x)
(lambda-set-vars lam)
- variables the lambda mutates(lambda-set-vars-set! lam x)
(lambda-return-type lam)
- the return type of the lambda(lambda-return-type-set! lam x)
(lambda-param-types lam)
- the types of the input parameters(lambda-param-types-set! lam x)
(lambda-source lam)
- the source code of the lambda(lambda-source-set! lam x)
(cnd-test cnd)
- the test for the conditional(cnd-test-set! cnd x)
(cnd-pass cnd)
- the success branch(cnd-pass-set! cnd x)
(cnd-fail cnd)
- the failure branch(cnd-fail-set! cnd x)
(seq-ls seq)
- the list of sequence expressions(seq-ls-set! seq x)
(ref-name ref)
- the name of the referenced variable(ref-name-set! ref x)
(ref-cell ref)
- the environment cell the reference resolves to(ref-cell-set! ref x)
(set-var set)
- a reference to the mutated variable(set-var-set! set x)
(set-value set)
- the value to set the variable to(set-value-set! set x)
(lit-value lit)
- the literal value(lit-value-set! lit x)
(pair-source x)
(pair-source-set! x source)
Set or return the source code info associated with a pair x.
Source info is represented as another pair whose car
is
the source file name and whose cdr
is the line number.
Force a garbage collection.
Returns the heap space directly used by x
, not
counting any elements of x
.
Returns the interpretation of the integer n
as
an immediate object, useful for debugging.
Returns the first string cursor of pat
in str
,
of #f
if it's not found.
Copies the characters from src
[start
..end
]
to dst
starting at from
.
Equivalent to setenv
but does nothing and returns
#f
if value
is a function definition. Used to
circumvent the vulnerability of the shellshock bug.
Run expr
atomically, disabling yields. Ideally should only be
used for brief, deterministic expressions. If used incorrectly (e.g.
running an infinite loop) can render the system unusable.
Never expose to a sandbox.