UNPKG

microvium

Version:

A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.

75 lines (74 loc) 2.94 kB
import * as IL from './il'; import * as VM from './virtual-machine-types'; import { mvm_Value, UInt8, UInt4 } from './runtime-types'; import { BinaryRegion, Future, FutureLike } from './binary-region'; import { vm_TeOpcode } from './bytecode-opcodes'; import { Referenceable } from './encode-snapshot'; export declare function writeFunctionBody(output: BinaryRegion, func: IL.Function, ctx: InstructionEmitContext, addressableReferences: Map<string, Future<Referenceable>>): void; export interface FutureInstructionSourceMapping { start: Future<number>; end: Future<number>; source: IL.OperationSourceLoc; op: IL.Operation; } export interface InstructionEmitContext { getShortCallIndex(callInfo: CallInfo): number; offsetOfFunction: (id: IL.FunctionID) => Future<number>; indexOfGlobalSlot: (globalSlotID: VM.GlobalSlotID) => number; getImportIndexOfHostFunctionID: (hostFunctionID: IL.HostFunctionID) => HostFunctionIndex; encodeValue: (value: IL.Value) => FutureLike<mvm_Value>; preferBlockToBeNext?: (blockId: IL.BlockID) => void; addName(offset: Future, type: string, name: string): void; sourceMapAdd?(mapping: FutureInstructionSourceMapping): void; } interface InstructionWriter { maxSize: number; requireAlignment?: '2-byte'; emitPass2: EmitPass2; } declare type EmitPass2 = (ctx: Pass2Context) => EmitPass2Output; interface EmitPass2Output { size: number; emitPass3: EmitPass3; } declare type EmitPass3 = (ctx: Pass3Context) => void; interface Pass2Context { isFinal: boolean; address: number; ilAddress: IL.ProgramAddressValue; tentativeOffsetOfBlock(blockId: string): number; } interface Pass3Context { region: BinaryRegion; address: number; absoluteAddress: Future<number>; offsetOfBlock(blockId: string): number; addressOfBlock(blockId: string): Future<number>; declareAddressablePoint(ilAddress: IL.ProgramAddressValue, physicalAddress: Future<number>, debugType: string): void; } declare type InstructionPayloadPart = { type: 'UInt8'; value: FutureLike<number>; } | { type: 'SInt8'; value: FutureLike<number>; } | { type: 'UInt16'; value: FutureLike<number>; } | { type: 'SInt16'; value: FutureLike<number>; }; export declare function customInstruction(op: IL.Operation, nibble1: vm_TeOpcode, nibble2: UInt4, ...payload: InstructionPayloadPart[]): InstructionWriter; export declare function appendCustomInstruction(region: BinaryRegion, op: IL.Operation, nibble1: vm_TeOpcode, nibble2: UInt4, ...payload: InstructionPayloadPart[]): undefined; export declare type CallInfo = { type: 'InternalFunction'; functionID: IL.FunctionID; argCount: UInt8; } | { type: 'HostFunction'; hostFunctionIndex: HostFunctionIndex; argCount: UInt8; }; declare type HostFunctionIndex = number; export {};