import { EventEmitter } from "events"; import * as PP from "../preprocessor"; import { BrsType, BrsInvalid, BrsBoolean, BrsString, Int32, RoArray, Callable, Float, Signature } from "../brsTypes"; import { Location } from "../lexer"; import { Expr, Stmt } from "../parser"; import { BrsError, RuntimeError } from "../Error"; import { Scope, Environment } from "./Environment"; import { OutputProxy } from "./OutputProxy"; import MemoryFileSystem from "memory-fs"; import { ComponentDefinition } from "../scenegraph"; import { CoverageCollector } from "../coverage"; import { ManifestValue } from "../preprocessor/Manifest"; /** The set of options used to configure an interpreter's execution. */ export interface ExecutionOptions { /** The base path for the project. Default: process.cwd() */ root: string; /** The stdout stream that brs should use. Default: process.stdout. */ stdout: NodeJS.WriteStream; /** The stderr stream that brs should use. Default: process.stderr. */ stderr: NodeJS.WriteStream; /** Whether or not to collect coverage statistics. Default: false. */ generateCoverage: boolean; /** Additional directories to search for component definitions. Default: [] */ componentDirs: string[]; /** Whether or not a component library is being processed. */ isComponentLibrary: boolean; /** Suppress console colors */ noColor: boolean; } /** The default set of execution options. Includes the `stdout`/`stderr` pair from the process that invoked `brs`. */ export declare const defaultExecutionOptions: ExecutionOptions; /** The definition of a trace point to be added to the stack trace */ export interface TracePoint { functionName: string; functionLocation: Location; callLocation: Location; signature?: Signature; } export declare class Interpreter implements Expr.Visitor, Stmt.Visitor { private _environment; private _stack; private _tryMode; private _coverageCollector; private _manifest; readonly options: ExecutionOptions; readonly stdout: OutputProxy; readonly stderr: OutputProxy; readonly temporaryVolume: MemoryFileSystem; location: Location; /** Allows consumers to observe errors as they're detected. */ readonly events: EventEmitter<[never]>; /** The set of errors detected from executing an AST. */ errors: (BrsError | RuntimeError)[]; get environment(): Environment; get stack(): TracePoint[]; get manifest(): PP.Manifest; set manifest(manifest: PP.Manifest); addToStack(tracePoint: TracePoint): void; setCoverageCollector(collector: CoverageCollector): void; reportCoverageHit(statement: Expr.Expression | Stmt.Statement): void; /** * Convenience function to subscribe to the `err` events emitted by `interpreter.events`. * @param errorHandler the function to call for every runtime error emitted after subscribing * @returns an object with a `dispose` function, used to unsubscribe from errors */ onError(errorHandler: (err: BrsError | RuntimeError) => void): { dispose: () => void; }; /** * Convenience function to subscribe to a single `err` event emitted by `interpreter.events`. * @param errorHandler the function to call for the first runtime error emitted after subscribing */ onErrorOnce(errorHandler: (err: BrsError | RuntimeError) => void): void; /** * Builds out all the sub-environments for the given components. Components are saved into the calling interpreter * instance. This function will mutate the state of the calling interpreter. * @param componentMap Map of all components to be assigned to this interpreter * @param parseFn Function used to parse components into interpretable statements * @param options */ static withSubEnvsFromComponents(componentMap: Map, manifest: Map, options?: ExecutionOptions): Promise; /** * Merges this environment's node definition mapping with the ones included in an array of other * interpreters, acting logically equivalent to * `Object.assign(this.environment, other1.environment, other2.environment, …)`. * @param interpreters the array of interpreters who's environment's node definition maps will * be merged into this one */ mergeNodeDefinitionsWith(interpreters: Interpreter[]): void; /** * Creates a new Interpreter, including any global properties and functions. * @param options configuration for the execution, including the streams to use for `stdout` and * `stderr` and the base directory for path resolution */ constructor(options?: ExecutionOptions); /** * Temporarily sets an interpreter's environment to the provided one, then * passes the sub-interpreter to the provided JavaScript function. Always * reverts the current interpreter's environment to its original value. * @param func the JavaScript function to execute with the sub interpreter. * @param environment (Optional) the environment to run the interpreter in. */ inSubEnv(func: (interpreter: Interpreter) => BrsType, environment?: Environment): BrsType; exec(statements: ReadonlyArray, ...args: BrsType[]): BrsType[]; getCallableFunction(functionName: string): Callable | undefined; /** * Returns the init method (if any) in the current environment as a Callable */ getInitMethod(): BrsType; visitLibrary(statement: Stmt.Library): BrsInvalid; visitNamedFunction(statement: Stmt.Function): BrsType; visitReturn(statement: Stmt.Return): never; visitExpression(statement: Stmt.Expression): BrsType; visitPrint(statement: Stmt.Print): BrsType; visitAssignment(statement: Stmt.Assignment): BrsType; visitDim(statement: Stmt.Dim): BrsType; visitBinary(expression: Expr.Binary): BrsBoolean | BrsString | import("../brsTypes/BrsNumber").BrsNumber; visitTryCatch(statement: Stmt.TryCatch): BrsInvalid; visitThrow(statement: Stmt.Throw): never; visitBlock(block: Stmt.Block): BrsType; visitContinueFor(statement: Stmt.ContinueFor): never; visitExitFor(statement: Stmt.ExitFor): never; visitContinueWhile(statement: Stmt.ContinueWhile): never; visitExitWhile(statement: Stmt.ExitWhile): never; visitCall(expression: Expr.Call): BrsType; visitDottedGet(expression: Expr.DottedGet): BrsType; visitIndexedGet(expression: Expr.IndexedGet): BrsType; visitGrouping(expr: Expr.Grouping): BrsType; visitFor(statement: Stmt.For): BrsType; visitForEach(statement: Stmt.ForEach): BrsType; visitWhile(statement: Stmt.While): BrsType; visitIf(statement: Stmt.If): BrsType; visitAnonymousFunction(func: Expr.Function): BrsType; visitLiteral(expression: Expr.Literal): BrsType; visitArrayLiteral(expression: Expr.ArrayLiteral): RoArray; visitAALiteral(expression: Expr.AALiteral): BrsType; visitDottedSet(statement: Stmt.DottedSet): BrsInvalid; visitIndexedSet(statement: Stmt.IndexedSet): BrsInvalid; visitIncrement(statement: Stmt.Increment): BrsInvalid; visitUnary(expression: Expr.Unary): BrsInvalid | BrsBoolean | Int32 | import("../brsTypes").Int64 | Float | import("../brsTypes").Double; visitVariable(expression: Expr.Variable): BrsType; evaluate(this: Interpreter, expression: Expr.Expression): BrsType; execute(this: Interpreter, statement: Stmt.Statement): BrsType; /** * Returns the Backtrace formatted as an array for Try/Catch * @param loc the location of the error * @param bt the backtrace array, default is current stack trace * @returns an array with the backtrace formatted */ formatBacktrace(loc: Location, bt?: TracePoint[]): RoArray; /** * Method to return the selected scope of the interpreter for the REPL and Micro Debugger * @returns a string representation of the variables in the selected scope */ formatVariables(scope?: Scope): string; /** Method to return a string with the current source code location * @returns a string representation of the location */ formatLocation(location?: Location): string; /** * Emits an error via this processor's `events` property, then throws it. * @param err the ParseError to emit then throw */ addError(err: BrsError): never; /** * Method to evaluate if a number is positive * @param value number to evaluate * @returns boolean indicating if the number is positive */ private isPositive; /** * Method to evaluate if a number is lees than the other * @param value Number to evaluate * @param compare Number to compare * @returns Boolean indicating if the number is less than the other */ private lessThan; } /** * Colorizes the console messages. * */ export declare function colorize(log: string): string;