microvium
Version:
A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.
222 lines (221 loc) • 9.01 kB
TypeScript
import * as IL from './il';
import * as VM from './virtual-machine-types';
import { SnapshotIL } from "./snapshot-il";
import { SnapshotClass } from './snapshot';
import { SynchronousWebSocketServer } from './synchronous-ws-server';
export * from "./virtual-machine-types";
export declare class VirtualMachine {
private resolveFFIImport;
private opts;
private allocations;
private nextHeapID;
private globalVariables;
private globalSlots;
private hostFunctions;
private catchTarget;
private frame;
private exception;
private functions;
private exports;
private ephemeralFunctions;
private ephemeralObjects;
private nextEphemeralFunctionNumericID;
private nextEphemeralObjectNumericID;
private handles;
private moduleCache;
private debuggerInstrumentation;
private builtins;
private jobQueue;
private cpsCallback;
constructor(resumeFromSnapshot: SnapshotIL | undefined, resolveFFIImport: VM.ResolveFFIImport, opts: VM.VirtualMachineOptions, debugServer?: SynchronousWebSocketServer);
evaluateModule(moduleSource: VM.ModuleSource): VM.ModuleObject;
createSnapshotIL(): SnapshotIL;
tryRunJobQueue(): void;
private dequeueJob;
createSnapshot(generateSourceMap: boolean): SnapshotClass;
ephemeralFunction(handler: VM.HostFunctionHandler, nameHint?: string): IL.Value;
ephemeralObject(handler: VM.HostObjectHandler, nameHint?: string): IL.Value;
unwrapEphemeralFunction(ephemeral: IL.EphemeralFunctionValue): any;
unwrapEphemeralObject(ephemeral: IL.EphemeralObjectValue): any;
vmExport(exportID: IL.ExportID, value: IL.Value): void;
vmImport(hostFunctionID: IL.HostFunctionID, defaultImplementation?: VM.HostFunctionHandler): IL.HostFunctionValue;
resolveExport(exportID: IL.ExportID): IL.Value;
setArrayPrototype(value: IL.Value): void;
/**
* "Relocates" a unit into the global "address space". I.e. remaps all its
* global and function IDs to unique IDs in the VM, and remaps all its import
* references to the corresponding resolve imports.
*
* @see evaluateModule
*/
private loadUnit;
private run;
runFunction(func: IL.CallableValue, args: IL.Value[], runJobQueue?: boolean): IL.Value | IL.Exception;
private sendToDebugClient;
private setupDebugServerListener;
private doDebuggerInstrumentation;
/** Create a new handle, starting at ref-count 1. Needs to be released with a call to `release` */
createHandle<T extends IL.Value>(value: T): VM.Handle<T>;
/**
* Gets the moduleContext provided to `runUnit` or `loadUnit` when the active
* function was loaded.
*/
callerModuleHostContext(): any;
private dispatchOperation;
private step;
private resolveOperand;
private operationArrayNew;
private operationUint8ArrayNew;
private operationArrayGet;
private operationArraySet;
private operationAsyncResume;
private addressOfFunctionEntry;
private operationAsyncReturn;
private operationAsyncComplete;
private scheduleContinuation;
private operationAwait;
private operationAwaitCall;
private readProgramAddress;
private operationAsyncStart;
setScoped(index: number, value: IL.Value): void;
getScoped(index: number): IL.NumberValue | IL.EphemeralObjectValue | IL.UndefinedValue | IL.NullValue | IL.BooleanValue | IL.StringValue | IL.FunctionValue | IL.HostFunctionValue | IL.ReferenceValue<IL.Allocation> | IL.EphemeralFunctionValue | IL.ClassValue | IL.ProgramAddressValue | IL.NoOpFunction | IL.ResumePoint;
private operationBinOp;
private operationBranch;
private operationNew;
isClosure(value: IL.Value): value is IL.ReferenceValue<IL.ClosureAllocation>;
private operationCall;
isCallableValue(value: IL.Value): value is IL.CallableValue;
private operationJump;
private operationLiteral;
private operationLoadArg;
private operationLoadGlobal;
private operationLoadScoped;
private findScopedVariable;
globalGet(name: string): IL.Value;
globalSet(name: string, value: IL.Value): void;
private operationLoadReg;
private operationLoadVar;
private operationNop;
private operationObjectNew;
private operationObjectGet;
private operationObjectKeys;
private operationObjectSet;
private operationClassCreate;
private operationClosureNew;
/**
* Converts a stack depth to a slot index relative to the bottom of the stack.
* Not quite the same index that would appear in the runtime VM, but
* consistent with the runtime VM within a single frame.
*/
private stackDepthToSlotIndex;
private frameList;
private slotIndexToStackDepth;
private operationStartTry;
private addressOfBlock;
private operationEndTry;
private pushCatchTarget;
/**
* Pops the catch target that is under the current stack pointer.
*/
private popCatchTarget;
private operationEnqueueJob;
private enqueueJob;
private operationPop;
private operationScopePush;
private operationScopeNew;
private operationScopeSave;
private createScope;
private operationScopePop;
private operationScopeDiscard;
private operationScopeClone;
private operationReturn;
private returnValue;
private operationTypeCodeOf;
private operationThrow;
private operationStoreGlobal;
private operationStoreScoped;
private operationStoreVar;
private operationUnOp;
typeOf(value: IL.Value): string;
private deepTypeOf;
typeCodeOf(value: IL.Value): number;
isTruthy(value: IL.Value): boolean;
private runtimeError;
/**
* An error that likely occurs because of malformed IL
* @param message
*/
private ilError;
get currentSourceLocation(): string | undefined;
private pop;
private checkIndexValue;
private push;
private pushString;
private pushUndefined;
private pushNumber;
private pushBoolean;
convertToString(value: IL.Value): string;
private convertToNumber;
areValuesEqual(value1: IL.Value, value2: IL.Value): boolean;
private callDynamic;
private callCommon;
getType(value: IL.Value): string;
private get internalFrame();
private get closure();
private set closure(value);
convertToNativePOD(value: IL.Value): any;
getStackAsString(): string;
numberValue(value: number): IL.NumberValue;
booleanValue(value: boolean): IL.BooleanValue;
stringValue(value: string): IL.StringValue;
newObject(prototype: IL.Value, internalSlotCount: number): IL.ReferenceValue<IL.ObjectAllocation>;
newClass(constructorFunc: IL.Value, prototype: IL.Value): IL.ClassValue;
newArray(fixedLength?: boolean, length?: number): IL.ReferenceValue<IL.ArrayAllocation>;
newUint8Array(length: number): IL.ReferenceValue<IL.Uint8ArrayAllocation>;
private allocate;
dereference<T extends IL.Allocation>(value: IL.ReferenceValue<T>): T;
garbageCollect(): void;
stringifyState(): string;
getProperty(objectValue: IL.Value, propertyNameValue: IL.Value): IL.Value;
objectKeys(objectValue: IL.Value): IL.Value;
private toPropertyName;
setProperty(objectValue: IL.Value, propertyNameValue: IL.Value, value: IL.Value): void;
private pushFrame;
private popFrame;
addBuiltinGlobals(): void;
private addGlobalPromiseClass;
importCustomILFunction(nameHint: string, il: Pick<VM.Function, 'entryBlockID' | 'blocks'>): IL.FunctionValue;
private asyncStartUnsafe;
/**
* Gets a value that represents the current depth in the stack. In the native
* VM, this can be a single number measuring the number of slots relative to
* the base of the stack.
*
* This is used for SetJmp to mark the current position in the stack so it can
* be restored later.
*/
private get stackPointer();
private get nextProgramCounter();
private set nextProgramCounter(value);
createAsyncCatchBlock(): IL.Value;
createObjectPrototype(internalSlotInitialValues: IL.Value[]): IL.Value;
createPromisePrototype(): IL.Value;
createAsyncContinueFunction(): IL.Value;
createAsyncHostCallbackFunction(): IL.Value;
private get args();
private get block();
private get callerFrame();
private get filename();
private get func();
private get nextOperationIndex();
private get operationBeingExecuted();
private get variables();
private set args(value);
private set block(value);
private set callerFrame(value);
private set filename(value);
private set func(value);
private set nextOperationIndex(value);
private set operationBeingExecuted(value);
private set variables(value);
}