@holgerengels/compute-engine
Version:
Symbolic computing and numeric evaluations for JavaScript and Node.js
31 lines (30 loc) • 1.53 kB
TypeScript
/* 0.26.0-alpha2 */
import type { MathJsonIdentifier } from '../math-json/types';
import type { BoxedExpression } from './public';
export type CompiledType = boolean | number | string | object;
type JSSource = string;
export type CompiledOperators = Record<MathJsonIdentifier, [
op: string,
prec: number
]>;
export type CompiledFunctions = {
[id: MathJsonIdentifier]: string | ((args: ReadonlyArray<BoxedExpression>, compile: (expr: BoxedExpression) => JSSource, target: CompileTarget) => JSSource);
};
export type CompileTarget = {
operators?: (op: MathJsonIdentifier) => [op: string, prec: number];
functions?: (id: MathJsonIdentifier) => string | ((...args: CompiledType[]) => string);
var: (id: MathJsonIdentifier) => string | undefined;
string: (str: string) => string;
number: (n: number) => string;
ws: (s?: string) => string;
indent: number;
};
/** This is an extension of the Function class that allows us to pass
* a custom scope for "global" functions. */
export declare class ComputeEngineFunction extends Function {
private sys;
constructor(body: string);
}
export declare function compileToTarget(expr: BoxedExpression, target: CompileTarget): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
export declare function compileToJavascript(expr: BoxedExpression): ((_: Record<string, CompiledType>) => CompiledType) | undefined;
export declare function compile(expr: BoxedExpression | undefined, target: CompileTarget, prec?: number): JSSource;
export {};