Provides class-based organization for tokenization, parsing, macro expansion, evaluation, and environment management.
Methods
Method new()
Initialize engine components and base environment.
Usage
Engine$new(
coverage_tracker = NULL,
load_prelude = TRUE,
disable_tco = NULL,
disable_constant_folding = NULL,
disable_optimizations = NULL,
disable_arithmetic_infix = NULL,
disable_bytecode = NULL,
r_packages = "search_path"
)Arguments
coverage_trackerOptional CoverageTracker instance to enable coverage tracking from the start. If provided, coverage will be tracked during stdlib loading. Intended for internal development use.
load_preludeLogical. If TRUE (the default), loads prelude modules during initialization. Set to FALSE to create a bare engine with only builtins — useful for testing or when you want to import specific modules.
disable_tcoOptional logical. If TRUE, disables self-tail-call optimization in the compiler, preserving natural call stacks for debugging. Defaults to NULL, which inherits from global option
getOption("arl.disable_tco", FALSE).disable_constant_foldingOptional logical. If TRUE, disables compile-time constant folding, forcing all expressions to be evaluated at runtime. Useful for testing that builtins match R semantics. Defaults to NULL, which inherits from global option
getOption("arl.disable_constant_folding", FALSE).disable_optimizationsOptional logical. If TRUE, disables all non-essential compiler optimizations (constant folding, TCO, dead code elimination, strength reduction, identity elimination, truthiness optimization, begin simplification, and boolean flattening). Individual toggles like
disable_tcoanddisable_constant_foldingare applied after this and can override it. Defaults to NULL, which inherits from global optiongetOption("arl.disable_optimizations", FALSE).disable_arithmetic_infixLogical; if TRUE, disable 2-arg arithmetic infix compilation.
disable_bytecodeLogical; if TRUE, disable bytecode compilation of cached modules.
r_packagesControls which R packages are visible to Arl code.
"search_path"(default) tracks R'ssearch()dynamically; a character vector pins a fixed set;NULLexposes onlybaseenv().
Method read()
Tokenize and parse source into expressions. The format returned by this method is not guaranteed to be stable across package versions.
Method write()
Convert an Arl expression to its string representation. Inverse of read(). The format returned by this method is not guaranteed to be stable across package versions.
Method eval()
Evaluate one or more expressions.
Method eval_text()
Read and evaluate Arl source text. Convenience wrapper around
read() and eval().
Method eval_string()
Alias for eval_text().
Method load_file_in_env()
Load and evaluate an Arl source file in the given environment. Definitions
and imports in the file are visible in env. To evaluate in an
isolated child scope, create one explicitly:
load_file_in_env(path, new.env(parent = env)).
Method macroexpand()
Expand macros in an expression. With depth = NULL (the default),
fully and recursively expand all macros. With depth = N, expand
only the top-level macro up to N times without walking into subexpressions.
Method inspect_compilation()
Inspect expansion and compilation for debugging. Parse text, expand macros in env, then compile to R. Returns parsed AST, expanded form, compiled R expression, and deparsed R code so you can see exactly what an Arl program becomes.
Method help()
Show help for a topic.
Method enable_coverage()
Enable coverage tracking.
Creates a coverage tracker and installs it in the eval context. Should be called before running code you want to track.
Method define()
Define a binding in the engine's top-level environment. This is the supported way to inject R objects for use in Arl code.