DME — Code Reflection

class avulto.DME

A representation of a single Dreammaker environment.

The DME class provides reflection information for a BYOND project. This includes looking up available types, proc and var names on those types, and basic support for AST walking.

DME instances are created with the following methods:

static from_file(filename: os.PathLike[str] | str, parse_procs: bool = False) → DME

Read the BYOND environment from the filename referring to a “.dme” file.

Parameters:
  • filename – Path to the “.dme” file.

  • parse_procs – If True, parsing is slower but reflection data is made available for all procs.

Raises:
  • OSError – If the file is not found or there was an error opening it.

  • RuntimeError – If there was an error parsing the DME environment.

Once instantiated, the following properties and methods are available:

property types: dict[TypePath | str, TypeDef]

A mapping of paths in the DME to their type definitions.

typesof(prefix: TypePath | str) → list[TypePath]

Returns a list of type paths with the given prefix, including itself.

subtypesof(prefix: TypePath | str) → list[TypePath]

Returns a list of type paths with the given prefix, excluding prefix itself.

class avulto.ProcDef

A single proc declaration.

walk(walker: Any) → None

Walk this proc’s AST with walker.

For each node class X in ast.Node and ast.Expression, walker may define visit_X(node, source_loc); it is called with the node and its SourceLoc. Undefined methods are skipped. As with ast.NodeVisitor, the children of a node handled by a custom visitor are not visited.

There is currently no analogous generic_visit support.

class avulto.VarDef

A single variable declaration.

property name: str

The name of the variable.

property type_path: Any

The type path the proc is declared on.

property declared_type: TypePath | None

The declared type of the variable, if specified.

property const_val: Any | None

The variable’s value, if it can be evaluated as a constant expression.

property source_loc: SourceLoc

The location of the variable declaration in the source tree.

class avulto.TypeDef

A single type declaration.

property path: TypePath

The typepath of the TypeDef.

property source_loc: SourceLoc

The location of the TypeDef’s first declaration in source.

property procs: ProcHolder

A class to access procs on this typepath.

property vars: VarHolder

A class to access variables on this typepath.

class avulto.ProcHolder

A collection of the procs on a TypeDef, returned from TypeDef.procs.

__getitem__(key: Any) → list[ProcDef]

Usage: procs[name]. Return an array of ProcDef instances for proc declaration with the given name. Raises KeyError if the type has no such procs.

names() → list[str]

Return the names of all procs visible from this type path.

all() → list[ProcDef]

Return all proc declarations visible from this type path.

declared() → list[ProcDef]

Return procs declared directly on this type path.

modified() → list[ProcDef]

Return procs that override inherited values on this subtype.

unmodified() → list[ProcDef]

Return inherited procs that were not changed on this subtype.

class avulto.VarHolder

A collection of the vars on a TypeDef, returned from TypeDef.vars.

vars[name]

Return the VarDef for the var name. Raises KeyError if the type has no such var.

iter(vars)

Return an iterator over every VarDef on the type.

names() → list[str]

Return the names of all variables visible from this type path.

all() → list[VarDef]

Return all variable declarations visible from this type path.

declared() → list[VarDef]

Return variables declared directly on this type path.

modified() → list[VarDef]

Return variables that override inherited values on this subtype.

unmodified() → list[VarDef]

Return inherited variables that were not changed on this subtype.