UNPKG

mathjslab

Version:

MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.

81 lines (80 loc) 2.38 kB
import type { FunctionTable, NodeExpr, NodeInput } from './AST'; import { MultiArray } from './AST'; /** * Minimal scope contract required by introspection helpers. */ type IntrospectionScope = { /** * Functions visible from the inspected workspace. */ functionTable: FunctionTable; }; /** * Minimal call-frame contract required by `dbstack` and `localfunctions`. */ type IntrospectionFrame = { /** * Workspace associated with the frame. */ scope: IntrospectionScope; /** * Callable metadata, when the frame represents a function call. */ func?: { type: string; node?: { id?: string; }; }; /** * AST node that originated the call, used for line information. */ callSite?: NodeExpr; /** * Explicit frame display name, if one was supplied by the caller. */ name?: string; /** * Caller frame. */ parentFrame?: IntrospectionFrame; }; /** * Syntax-error callback supplied by the interpreter. */ type ThrowSyntaxError = (message: string) => never; /** * Implements stack and local-function introspection built-ins. * * The browser runtime has no real MATLAB/Octave file stack, so file names are * intentionally empty. Function names, line numbers, and local function handles * are still derived from active call frames and scopes. */ declare class FunctionIntrospection { /** * Return handles for user-defined functions visible in the nearest function scope. */ static localFunctionHandles(currentFrame: IntrospectionFrame | undefined, currentScope: IntrospectionScope): MultiArray; /** * Compute the display name for a stack frame. */ static frameName(frame: IntrospectionFrame): string; /** * Build the structure array returned by `dbstack`. */ static dbstackResult(args: NodeInput[], callStack: IntrospectionFrame[], throwSyntaxError: ThrowSyntaxError): MultiArray; /** * Find the nearest user-defined function frame. */ private static nearestFunctionFrame; /** * Parse `dbstack` skip/options arguments. */ private static dbstackSkip; } export type { IntrospectionFrame, IntrospectionScope }; export { FunctionIntrospection }; declare const _default: { FunctionIntrospection: typeof FunctionIntrospection; }; export default _default;