(chibi ast)

Abstract Syntax Tree. Interface to the types used by the compiler, and other core types less commonly needed in user code, plus related utilities.

Analysis and Expansion

(analyze x [env])

Expands and analyzes the expression x and returns the resulting AST.

(optimize ast)

Runs an optimization pass on ast and returns the resulting simplified expression.

(flatten-dot x)

(macroexpand x)

Performs a full syntax expansion of the form x and returns the resulting s-expression.

(ast->sexp ast)

Convert ast to a s-expression, renaming variables if necessary.


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.

The following extended type predicates may also be used to test individual objects for their type:

(type-of x)

Returns the type of any object x.

(type-name type)

Returns the name of type type.

(type-parent type)

Returns the immediate parent of type type, or #f for a type with no parent.

(type-cpl type)

Returns the class precedence list of type type as a vector, or #f for a type with no parent.

(type-slots type)

Returns the slot list of type type.


This section describes additional accessors on AST and other core types.


(procedure-name x)

(procedure-name-set! x name)


Bytecode Objects

Syntactic Closures

Return the environment, free variables, and expression associated with sc respectively.


Return the kind, message, and irritants associated with exn respectively.








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.

Miscellaneous Utilities


Force a garbage collection.

(object-size x)

Returns the heap space directly used by x, not counting any elements of x.

(integer->immediate n)

Returns the interpretation of the integer n as an immediate object, useful for debugging.

(string-contains str pat [start])


Returns the first string cursor of pat in str, of #f if it's not found.

(string-cursor-copy! dst src from start end)

Copies the characters from src[start..end] to dst starting at from.

(safe-setenv name value)

Equivalent to setenv but does nothing and returns #f if value is a function definition. Used to circumvent the vulnerability of the shellshock bug.

(atomically expr)

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.

(thread-interrupt! thread)