pxt-core
Version:
Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors
1,270 lines • 86.7 kB
TypeScript
/// <reference path="../localtypings/vscode-debug-protocol.d.ts" />
/// <reference path="../localtypings/pxtparts.d.ts" />
/// <reference path="../localtypings/pxtarget.d.ts" />
/// <reference path="../localtypings/pxtmusic.d.ts" />
declare namespace pxsim.accessibility {
function makeFocusable(elem: SVGElement): void;
function getGlobalAction(e: KeyboardEvent): pxsim.GlobalAction | null;
function postKeyboardEvent(): void;
function enableKeyboardInteraction(elem: Element, handlerKeyDown?: () => void, handlerKeyUp?: () => void): void;
function setAria(elem: Element, role?: string, label?: string): void;
function setLiveContent(value: string): void;
}
declare namespace pxsim {
interface AllocatorOpts {
boardDef: BoardDefinition;
partDefs: Map<PartDefinition>;
partsList: string[];
fnArgs: any;
getBBCoord: (loc: BBLoc) => visuals.Coord;
}
interface AllocatorResult {
partsAndWires: PartAndWiresInst[];
requiresBreadboard?: boolean;
hideBreadboard?: boolean;
parts: pxsim.visuals.IBoardPart<any>[];
wires: pxsim.visuals.Wire[];
}
interface PartInst {
name: string;
simulationBehavior?: string;
visual: PartVisualDefinition;
bbFit: PartBBFit;
startColumnIdx: number;
startRowIdx: number;
breadboardConnections: BBLoc[];
params: Map<string>;
}
interface WireInst {
start: Loc;
end: Loc;
color: string;
}
interface AssemblyStep {
part?: boolean;
wireIndices?: number[];
}
interface PartAndWiresInst {
part?: PartInst;
wires?: WireInst[];
assembly: AssemblyStep[];
}
interface PartBBFit {
xOffset: number;
yOffset: number;
rowCount: number;
colCount: number;
}
function readPin(arg: string): string;
function allocateDefinitions(opts: AllocatorOpts): AllocatorResult;
}
/**
* Heavily adapted from https://github.com/microsoft/vscode-debugadapter-node
* and altered to run in a browser and communcate via JSON over a websocket
* rather than through stdin and stdout
*/
declare namespace pxsim.protocol {
/**
* Host for debug session that is responsible with communication with
* the debugger's user interface.
*/
interface DebugSessionHost {
send(msg: string): void;
onData(cb: (msg: DebugProtocol.ProtocolMessage) => void): void;
onError(cb: (e?: any) => void): void;
onClose(cb: () => void): void;
close(): void;
}
class Message implements DebugProtocol.ProtocolMessage {
seq: number;
type: string;
constructor(type: string);
}
class Response extends Message implements DebugProtocol.Response {
request_seq: number;
success: boolean;
command: string;
constructor(request: DebugProtocol.Request, message?: string);
}
class Event extends Message implements DebugProtocol.Event {
event: string;
constructor(event: string, body?: any);
}
class Source implements DebugProtocol.Source {
name: string;
path: string;
sourceReference: number;
constructor(name: string, path: string, id?: number, origin?: string, data?: any);
}
class Scope implements DebugProtocol.Scope {
name: string;
variablesReference: number;
expensive: boolean;
constructor(name: string, reference: number, expensive?: boolean);
}
class StackFrame implements DebugProtocol.StackFrame {
id: number;
source: Source;
line: number;
column: number;
name: string;
constructor(i: number, nm: string, src?: Source, ln?: number, col?: number);
}
class Thread implements DebugProtocol.Thread {
id: number;
name: string;
constructor(id: number, name: string);
}
class Variable implements DebugProtocol.Variable {
name: string;
value: string;
variablesReference: number;
constructor(name: string, value: string, ref?: number, indexedVariables?: number, namedVariables?: number);
}
class Breakpoint implements DebugProtocol.Breakpoint {
verified: boolean;
constructor(verified: boolean, line?: number, column?: number, source?: Source);
}
class Module implements DebugProtocol.Module {
id: number | string;
name: string;
constructor(id: number | string, name: string);
}
class CompletionItem implements DebugProtocol.CompletionItem {
label: string;
start: number;
length: number;
constructor(label: string, start: number, length?: number);
}
class StoppedEvent extends Event implements DebugProtocol.StoppedEvent {
body: {
reason: string;
threadId: number;
};
constructor(reason: string, threadId: number, exception_text?: string);
}
class ContinuedEvent extends Event implements DebugProtocol.ContinuedEvent {
body: {
threadId: number;
};
constructor(threadId: number, allThreadsContinued?: boolean);
}
class InitializedEvent extends Event implements DebugProtocol.InitializedEvent {
constructor();
}
class TerminatedEvent extends Event implements DebugProtocol.TerminatedEvent {
constructor(restart?: boolean);
}
class OutputEvent extends Event implements DebugProtocol.OutputEvent {
body: {
category: string;
output: string;
data?: any;
};
constructor(output: string, category?: string, data?: any);
}
class ThreadEvent extends Event implements DebugProtocol.ThreadEvent {
body: {
reason: string;
threadId: number;
};
constructor(reason: string, threadId: number);
}
class BreakpointEvent extends Event implements DebugProtocol.BreakpointEvent {
body: {
reason: string;
breakpoint: Breakpoint;
};
constructor(reason: string, breakpoint: Breakpoint);
}
class ModuleEvent extends Event implements DebugProtocol.ModuleEvent {
body: {
reason: 'new' | 'changed' | 'removed';
module: Module;
};
constructor(reason: 'new' | 'changed' | 'removed', module: Module);
}
class ProtocolServer {
private host;
private _pendingRequests;
private _sequence;
start(host: DebugSessionHost): void;
stop(): void;
sendEvent(event: DebugProtocol.Event): void;
sendResponse(response: DebugProtocol.Response): void;
sendRequest(command: string, args: any, timeout: number, cb: (response: DebugProtocol.Response) => void): void;
private send;
protected dispatchRequest(request: DebugProtocol.Request): void;
}
class DebugSession extends ProtocolServer {
private _debuggerLinesStartAt1;
private _debuggerColumnsStartAt1;
private _debuggerPathsAreURIs;
private _clientLinesStartAt1;
private _clientColumnsStartAt1;
private _clientPathsAreURIs;
private _isServer;
shutdown(): void;
protected dispatchRequest(request: DebugProtocol.Request): void;
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void;
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void;
protected launchRequest(response: DebugProtocol.LaunchResponse, args: DebugProtocol.LaunchRequestArguments): void;
protected attachRequest(response: DebugProtocol.AttachResponse, args: DebugProtocol.AttachRequestArguments): void;
protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void;
protected setFunctionBreakPointsRequest(response: DebugProtocol.SetFunctionBreakpointsResponse, args: DebugProtocol.SetFunctionBreakpointsArguments): void;
protected setExceptionBreakPointsRequest(response: DebugProtocol.SetExceptionBreakpointsResponse, args: DebugProtocol.SetExceptionBreakpointsArguments): void;
protected configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse, args: DebugProtocol.ConfigurationDoneArguments): void;
protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments): void;
protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void;
protected stepInRequest(response: DebugProtocol.StepInResponse, args: DebugProtocol.StepInArguments): void;
protected stepOutRequest(response: DebugProtocol.StepOutResponse, args: DebugProtocol.StepOutArguments): void;
protected stepBackRequest(response: DebugProtocol.StepBackResponse, args: DebugProtocol.StepBackArguments): void;
protected restartFrameRequest(response: DebugProtocol.RestartFrameResponse, args: DebugProtocol.RestartFrameArguments): void;
protected gotoRequest(response: DebugProtocol.GotoResponse, args: DebugProtocol.GotoArguments): void;
protected pauseRequest(response: DebugProtocol.PauseResponse, args: DebugProtocol.PauseArguments): void;
protected sourceRequest(response: DebugProtocol.SourceResponse, args: DebugProtocol.SourceArguments): void;
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void;
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void;
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void;
protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): void;
protected setVariableRequest(response: DebugProtocol.SetVariableResponse, args: DebugProtocol.SetVariableArguments): void;
protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void;
protected stepInTargetsRequest(response: DebugProtocol.StepInTargetsResponse, args: DebugProtocol.StepInTargetsArguments): void;
protected gotoTargetsRequest(response: DebugProtocol.GotoTargetsResponse, args: DebugProtocol.GotoTargetsArguments): void;
protected completionsRequest(response: DebugProtocol.CompletionsResponse, args: DebugProtocol.CompletionsArguments): void;
/**
* Override this hook to implement custom requests.
*/
protected customRequest(command: string, response: DebugProtocol.Response, args: any): void;
protected sendErrorResponse(response: DebugProtocol.Response, codeOrMessage: number | DebugProtocol.Message, format?: string, variables?: any): void;
protected convertClientLineToDebugger(line: number): number;
protected convertDebuggerLineToClient(line: number): number;
protected convertClientColumnToDebugger(column: number): number;
protected convertDebuggerColumnToClient(column: number): number;
protected convertClientPathToDebugger(clientPath: string): string;
protected convertDebuggerPathToClient(debuggerPath: string): string;
private static path2uri;
private static uri2path;
private static _formatPIIRegexp;
private static formatPII;
}
}
declare namespace pxsim.util {
function injectPolyphils(): void;
class Lazy<T> {
private _func;
private _value;
private _evaluated;
constructor(_func: () => T);
get value(): T;
}
function getNormalizedParts(path: string): string[];
function normalizePath(path: string): string;
function relativePath(fromDir: string, toFile: string): string;
function pathJoin(...paths: string[]): string;
function toArray<T>(a: ArrayLike<T> | ReadonlyArray<T>): T[];
}
declare namespace pxsim {
function getWarningMessage(msg: string): DebuggerWarningMessage;
class BreakpointMap {
fileMap: {
[index: string]: [number, DebugProtocol.Breakpoint][];
};
idMap: {
[index: number]: DebugProtocol.Breakpoint;
};
constructor(breakpoints: [number, DebugProtocol.Breakpoint][]);
getById(id: number): DebugProtocol.Breakpoint;
verifyBreakpoint(path: string, breakpoint: DebugProtocol.SourceBreakpoint): [number, DebugProtocol.Breakpoint];
}
function dumpHeap(v: any, heap: Map<any>, fields?: string[], filters?: string[], includeAll?: boolean): Variables;
function injectEnvironmentGlobals(msg: DebuggerBreakpointMessage, heap: Map<any>): void;
function getBreakpointMsg(s: pxsim.StackFrame, brkId: number, userGlobals?: string[]): {
msg: DebuggerBreakpointMessage;
heap: Map<any>;
};
interface SimLaunchArgs extends DebugProtocol.LaunchRequestArguments {
projectDir: string;
}
class SimDebugSession extends protocol.DebugSession {
private static THREAD_ID;
private driver;
private lastBreak;
private state;
private projectDir;
private breakpoints;
constructor(container: HTMLElement);
runCode(js: string, parts: string[], fnArgs: Map<string>, breakpoints: BreakpointMap, board: pxsim.BoardDefinition): void;
stopSimulator(unload?: boolean): void;
protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void;
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void;
protected launchRequest(response: DebugProtocol.LaunchResponse, args: SimLaunchArgs): void;
protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void;
protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments): void;
protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void;
protected stepInRequest(response: DebugProtocol.StepInResponse, args: DebugProtocol.StepInArguments): void;
protected stepOutRequest(response: DebugProtocol.StepOutResponse, args: DebugProtocol.StepOutArguments): void;
protected pauseRequest(response: DebugProtocol.PauseResponse, args: DebugProtocol.PauseArguments): void;
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void;
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void;
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void;
protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): void;
private onDebuggerBreakpoint;
private onDebuggerWarning;
private onDebuggerResume;
private onStateChanged;
private fixBreakpoints;
}
}
declare namespace pxsim {
interface SimulatorRunMessage extends SimulatorMessage {
type: "run";
id?: string;
boardDefinition?: BoardDefinition;
frameCounter?: number;
refCountingDebug?: boolean;
options?: any;
parts?: string[];
builtinParts?: string[];
partDefinitions?: Map<PartDefinition>;
fnArgs?: any;
code: string;
mute?: boolean;
highContrast?: boolean;
light?: boolean;
cdnUrl?: string;
localizedStrings?: Map<string>;
version?: string;
clickTrigger?: boolean;
breakOnStart?: boolean;
storedState?: Map<any>;
ipc?: boolean;
dependencies?: Map<string>;
single?: boolean;
traceDisabled?: boolean;
activePlayer?: 1 | 2 | 3 | 4 | undefined;
theme?: string | pxt.Map<string>;
yieldDelay?: number;
}
interface SimulatorInstructionsMessage extends SimulatorMessage {
type: "instructions";
options: pxsim.instructions.RenderPartsOptions;
}
interface SimulatorMuteMessage extends SimulatorMessage {
type: "mute";
mute: boolean;
}
interface SimulatorStopSoundMessage extends SimulatorMessage {
type: "stopsound";
}
interface SimulatorDocMessage extends SimulatorMessage {
type: "localtoken" | "docfailed";
docType?: string;
src?: string;
localToken?: string;
}
interface SimulatorFileLoadedMessage extends SimulatorMessage {
type: "fileloaded";
name: string;
locale: string;
content?: string;
}
interface SimulatorReadyMessage extends SimulatorMessage {
type: "ready";
frameid: string;
}
interface SimulatorTopLevelCodeFinishedMessage extends SimulatorMessage {
type: "toplevelcodefinished";
}
interface SimulatorOpenDocMessage extends SimulatorMessage {
type: "opendoc";
url: string;
}
type GlobalAction = "escape" | "toggleareamenu" | "togglekeyboardcontrolshelp";
interface SimulatorActionMessage extends SimulatorMessage {
type: "action";
action: GlobalAction;
}
interface SimulatorStateMessage extends SimulatorMessage {
type: "status";
frameid?: string;
runtimeid?: string;
state: string;
}
interface SimulatorBroadcastMessage extends SimulatorMessage {
broadcast: boolean;
toParentIFrameOnly?: boolean;
srcFrameIndex?: number;
}
interface SimulatorControlMessage extends SimulatorBroadcastMessage {
type: "messagepacket";
channel: string;
data: Uint8Array;
}
interface SimulatorEventBusMessage extends SimulatorBroadcastMessage {
type: "eventbus";
broadcast: true;
id: number;
eventid: number;
value?: number;
}
interface SimulatorSerialMessage extends SimulatorMessage {
type: "serial";
id: string;
data: string;
sim?: boolean;
csvType?: undefined | "headers" | "row" | "clear";
receivedTime?: number;
}
interface SimulatorBulkSerialMessage extends SimulatorMessage {
type: "bulkserial";
id: string;
data: {
data: string;
time: number;
}[];
sim?: boolean;
}
interface SimulatorCommandMessage extends SimulatorMessage {
type: "simulator";
command: "modal" | "restart" | "reload" | "setstate" | "focus" | "blur" | "single";
stateKey?: string;
stateValue?: any;
header?: string;
body?: string;
copyable?: string;
linkButtonHref?: string;
linkButtonLabel?: string;
displayOnceId?: string;
modalContext?: string;
timestamp?: number;
}
interface SimulatorRadioPacketMessage extends SimulatorBroadcastMessage {
type: "radiopacket";
broadcast: true;
rssi: number;
serial: number;
time: number;
payload: SimulatorRadioPacketPayload;
}
interface SimulatorInfraredPacketMessage extends SimulatorBroadcastMessage {
type: "irpacket";
broadcast: true;
packet: Uint8Array;
}
interface SimulatorBLEPacketMessage extends SimulatorBroadcastMessage {
type: "blepacket";
broadcast: true;
packet: Uint8Array;
}
interface SimulatorI2CMessage extends SimulatorMessage {
type: "i2c";
data: Uint8Array;
}
interface SimulatorRadioPacketPayload {
type: number;
groupId: number;
stringData?: string;
numberData?: number;
}
interface SimulatorCustomMessage extends SimulatorMessage {
type: "custom";
content: any;
}
interface SimulatorScreenshotMessage extends SimulatorMessage {
type: "screenshot";
data: ImageData;
delay?: number;
modalContext?: string;
}
interface SimulatorAutomaticThumbnailMessage extends SimulatorMessage {
type: "thumbnail";
frames: ImageData[];
}
interface SimulatorAddExtensionsMessage extends SimulatorMessage {
type: "addextensions";
/**
* List of repositories to add
*/
extensions: string[];
}
interface SimulatorAspectRatioMessage extends SimulatorMessage {
type: "aspectratio";
value: number;
frameid: string;
}
interface SimulatorRecorderMessage extends SimulatorMessage {
type: "recorder";
action: "start" | "stop";
width?: number;
}
interface TutorialMessage extends SimulatorMessage {
type: "tutorial";
tutorial: string;
subtype: string;
}
interface ImportFileMessage extends SimulatorMessage {
type: "importfile";
filename: string;
parts: (string | ArrayBuffer)[];
}
interface TutorialStepInfo {
fullscreen?: boolean;
contentMd?: string;
headerContentMd?: string;
hintContentMd?: string;
}
interface TutorialLoadedMessage extends TutorialMessage {
subtype: "loaded";
showCategories?: boolean;
stepInfo: TutorialStepInfo[];
toolboxSubset?: {
[index: string]: number;
};
}
interface TutorialStepChangeMessage extends TutorialMessage {
subtype: "stepchange";
step: number;
}
interface TutorialFailedMessage extends TutorialMessage {
subtype: "error";
message?: string;
}
interface RenderReadyResponseMessage extends SimulatorMessage {
source: "makecode";
type: "renderready";
versions: pxt.TargetVersions;
}
interface RenderBlocksRequestMessage extends SimulatorMessage {
type: "renderblocks";
id: string;
code?: string;
options?: {
packageId?: string;
package?: string;
snippetMode?: boolean;
};
}
interface RenderBlocksResponseMessage extends SimulatorMessage {
source: "makecode";
type: "renderblocks";
id: string;
svg?: string;
width?: number;
height?: number;
css?: string;
uri?: string;
error?: string;
}
interface SetActivePlayerMessage extends SimulatorMessage {
type: "setactiveplayer";
playerNumber: 1 | 2 | 3 | 4 | undefined;
}
interface SetSimThemeMessage extends SimulatorMessage {
type: "setsimthemecolor";
part: "background-color" | "button-stroke" | "text-color" | "button-fill" | "dpad-fill";
color: string;
}
interface SetMuteButtonStateMessage extends SimulatorMessage {
type: "setmutebuttonstate";
state: "muted" | "unmuted" | "disabled";
}
namespace multiplayer {
type MessageBase = {
type: "multiplayer";
origin?: "server" | "client";
broadcast?: boolean;
};
export enum IconType {
Player = 0,
Reaction = 1
}
export type ImageMessage = MessageBase & {
content: "Image";
image?: pxsim.RefBuffer;
palette: Uint8Array;
};
export type InputMessage = MessageBase & {
content: "Button";
button: number;
clientNumber: number;
state: "Pressed" | "Released" | "Held";
};
export type AudioMessage = MessageBase & {
content: "Audio";
instruction: "playinstructions" | "muteallchannels";
soundbuf?: Uint8Array;
};
export type IconMessage = MessageBase & {
content: "Icon";
icon?: pxsim.RefBuffer;
slot: number;
iconType: IconType;
palette: Uint8Array;
};
export type ConnectionMessage = MessageBase & {
content: "Connection";
slot: number;
connected: boolean;
};
export type Message = ImageMessage | AudioMessage | InputMessage | IconMessage | ConnectionMessage;
export {};
}
function print(delay?: number): void;
namespace Embed {
let frameid: string;
function start(): void;
function stop(): void;
function run(msg: SimulatorRunMessage): void;
}
/**
* Log an event to the parent editor (allowSimTelemetry must be enabled in target)
* @param id The id of the event
* @param data Any custom values associated with this event
*/
function tickEvent(id: string, data?: Map<string | number>): void;
/**
* Log an error to the parent editor (allowSimTelemetry must be enabled in target)
* @param cat The category of the error
* @param msg The error message
* @param data Any custom values associated with this event
*/
function reportError(cat: string, msg: string, data?: Map<string>): void;
function reload(): void;
}
declare namespace pxsim.instructions {
interface RenderPartsOptions {
name: string;
boardDef: BoardDefinition;
parts: string[];
partDefinitions: Map<PartDefinition>;
fnArgs: any;
configData: pxsim.ConfigData;
print?: boolean;
}
function renderParts(container: HTMLElement, options: RenderPartsOptions): void;
function renderInstructions(msg: SimulatorInstructionsMessage): void;
}
declare namespace pxsim {
let quiet: boolean;
function check(cond: boolean, msg?: string): void;
let title: string;
function getConfig(id: number): number;
function getConfigKey(id: string): number;
function getAllConfigKeys(): string[];
function setConfigKey(key: string, id: number): void;
function setConfig(id: number, val: number): void;
function setConfigData(cfg_: Map<number>, cfgKey_: Map<number>): void;
interface ConfigData {
cfg: Map<number>;
cfgKey: Map<number>;
}
function getConfigData(): ConfigData;
function setTitle(t: string): void;
class RefObject {
id: number;
constructor();
destroy(): void;
scan(mark: (path: string, v: any) => void): void;
gcKey(): string;
gcSize(): number;
gcIsStatic(): boolean;
print(): void;
toDebugString(): string;
static toAny(o: any): any;
static fromAny(o: any): any;
static toDebugString(o: any): string;
}
class FnWrapper {
func: LabelFn;
caps: any[];
args: any[];
constructor(func: LabelFn, caps: any[], args: any[]);
}
interface VTable {
name: string;
methods: LabelFn[];
numFields: number;
toStringMethod?: LabelFn;
classNo: number;
lastSubtypeNo: number;
iface?: Map<any>;
maxBgInstances?: number;
}
class RefRecord extends RefObject {
fields: any;
vtable: VTable;
scan(mark: (path: string, v: any) => void): void;
gcKey(): string;
gcSize(): number;
destroy(): void;
print(): void;
toDebugString(): string;
toAny(): any;
static fromAny(o: any): RefRecord;
}
class RefAction extends RefObject {
fields: any[];
len: number;
func: LabelFn;
scan(mark: (path: string, v: any) => void): void;
gcKey(): string;
gcSize(): number;
isRef(idx: number): boolean;
ldclo(n: number): any;
destroy(): void;
print(): void;
}
namespace pxtcore {
function seedAddRandom(num: number): void;
function mkAction(len: number, fn: LabelFn): RefAction;
function runAction(a: RefAction, args: any[]): void;
function dumpPerfCounters(): void;
}
class RefRefLocal extends RefObject {
v: any;
scan(mark: (path: string, v: any) => void): void;
gcKey(): string;
gcSize(): number;
destroy(): void;
print(): void;
}
interface MapEntry {
key: string;
val: any;
}
class RefMap extends RefObject {
vtable: VTable;
data: MapEntry[];
scan(mark: (path: string, v: any) => void): void;
gcKey(): string;
gcSize(): number;
findIdx(key: string): number;
destroy(): void;
print(): void;
toDebugString(): string;
toAny(): any;
static fromAny(o: any): RefMap;
}
function dumpLivePointers(): void;
namespace numops {
function toString(v: any): any;
function toBoolDecr(v: any): boolean;
function toBool(v: any): boolean;
}
namespace langsupp {
function toInt(v: number): number;
function toFloat(v: number): number;
function ignore(v: any): any;
}
namespace pxtcore {
function ptrOfLiteral(v: any): any;
function debugMemLeaks(): void;
function templateHash(): number;
function programHash(): number;
function programName(): string;
function programSize(): number;
function afterProgramPage(): number;
function getConfig(key: number, defl: number): number;
function toInt(n: number): number;
function toUInt(n: number): number;
function toDouble(n: number): number;
function toFloat(n: number): number;
function fromInt(n: number): number;
function fromUInt(n: number): number;
function fromDouble(n: number): number;
function fromFloat(n: number): number;
function fromBool(n: any): boolean;
}
namespace pxtrt {
function toInt8(v: number): number;
function toInt16(v: number): number;
function toInt32(v: number): number;
function toUInt32(v: number): number;
function toUInt8(v: number): number;
function toUInt16(v: number): number;
function nullFix(v: any): any;
function nullCheck(v: any): void;
function panic(code: number): void;
function stringToBool(s: string): 0 | 1;
function ptrToBool(v: any): 0 | 1;
function emptyToNull(s: string): any;
function ldlocRef(r: RefRefLocal): any;
function stlocRef(r: RefRefLocal, v: any): void;
function mklocRef(): RefRefLocal;
function stclo(a: RefAction, idx: number, v: any): RefAction;
function runtimeWarning(msg: string): void;
function mkMap(): RefMap;
let mapKeyNames: string[];
function mapGet(map: RefMap, key: number): any;
function mapSet(map: RefMap, key: number, val: any): void;
function mapGetByString(map: RefMap, key: string): any;
function mapDeleteByString(map: RefMap, key: string): boolean;
const mapSetGeneric: typeof mapSetByString;
const mapGetGeneric: typeof mapGetByString;
function mapSetByString(map: RefMap, key: string, val: any): void;
function keysOf(v: RefMap): RefCollection;
let getGlobalsPtr: any;
let lookupMapKey: any;
}
namespace pxtcore {
function mkClassInstance(vtable: VTable): RefRecord;
function switch_eq(a: any, b: any): boolean;
let getNumGlobals: any;
let RefRecord_destroy: any;
let RefRecord_print: any;
let anyPrint: any;
let dumpDmesg: any;
let getVTable: any;
let valType: any;
let lookupPin: any;
let deleteRefObject: any;
let popThreadContext: any;
let pushThreadContext: any;
let failedCast: any;
let missingProperty: any;
let string_vt: any;
let buffer_vt: any;
let number_vt: any;
let RefAction_vtable: any;
let RefRecord_scan: any;
let RefRecord_gcsize: any;
let startPerfCounter: any;
let stopPerfCounter: any;
let string_inline_ascii_vt: any;
let string_inline_utf8_vt: any;
let string_cons_vt: any;
let string_skiplist16_vt: any;
let string_skiplist16_packed_vt: any;
function typeOf(obj: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
}
let __aeabi_dadd: any;
let __aeabi_dcmplt: any;
let __aeabi_dcmpgt: any;
let __aeabi_dsub: any;
let __aeabi_ddiv: any;
let __aeabi_dmul: any;
namespace thread {
let panic: typeof pxtrt.panic;
function pause(ms: number): void;
function runInBackground(a: RefAction): void;
function forever(a: RefAction): void;
function typeCheck(a: RefAction): void;
}
}
declare namespace pxsim {
class RefCollection extends RefObject {
private data;
constructor();
scan(mark: (path: string, v: any) => void): void;
gcKey(): string;
gcSize(): number;
toArray(): any[];
toAny(): any[];
static fromAny(arr: any[], deep?: boolean): RefCollection;
toDebugString(): string;
destroy(): void;
isValidIndex(x: number): boolean;
push(x: any): void;
pop(): any;
getLength(): number;
setLength(x: number): void;
getAt(x: number): any;
setAt(x: number, y: any): void;
insertAt(x: number, y: number): void;
removeAt(x: number): any;
indexOf(x: number, start: number): number;
print(): void;
}
namespace Array_ {
function mk(): RefCollection;
function isArray(c: any): boolean;
function length(c: RefCollection): number;
function setLength(c: RefCollection, x: number): void;
function push(c: RefCollection, x: any): void;
function pop(c: RefCollection, x: any): any;
function getAt(c: RefCollection, x: number): any;
function removeAt(c: RefCollection, x: number): any;
function insertAt(c: RefCollection, x: number, y: number): void;
function setAt(c: RefCollection, x: number, y: any): void;
function indexOf(c: RefCollection, x: any, start: number): number;
function removeElement(c: RefCollection, x: any): 0 | 1;
function typeCheck(c: RefCollection): void;
}
namespace Math_ {
const imul: (x: number, y: number) => number;
function idiv(x: number, y: number): number;
function round(n: number): number;
function roundWithPrecision(x: number, digits: number): number;
function ceil(n: number): number;
function floor(n: number): number;
function sqrt(n: number): number;
function pow(x: number, y: number): number;
function clz32(n: number): number;
function log(n: number): number;
function log10(n: number): number;
function log2(n: number): number;
function exp(n: number): number;
function sin(n: number): number;
function sinh(n: number): number;
function cos(n: number): number;
function cosh(n: number): number;
function tan(n: number): number;
function tanh(n: number): number;
function asin(n: number): number;
function asinh(n: number): number;
function acos(n: number): number;
function acosh(n: number): number;
function atan(n: number): number;
function atanh(x: number): number;
function atan2(y: number, x: number): number;
function trunc(x: number): number;
function random(): number;
function randomRange(min: number, max: number): number;
}
namespace Number_ {
function lt(x: number, y: number): boolean;
function le(x: number, y: number): boolean;
function neq(x: number, y: number): boolean;
function eq(x: number, y: number): boolean;
function eqDecr(x: number, y: number): boolean;
function gt(x: number, y: number): boolean;
function ge(x: number, y: number): boolean;
function div(x: number, y: number): number;
function mod(x: number, y: number): number;
function bnot(x: number): number;
function toString(x: number): string;
}
namespace thumb {
function adds(x: number, y: number): number;
function subs(x: number, y: number): number;
function divs(x: number, y: number): number;
function muls(x: number, y: number): number;
function ands(x: number, y: number): number;
function orrs(x: number, y: number): number;
function eors(x: number, y: number): number;
function lsls(x: number, y: number): number;
function lsrs(x: number, y: number): number;
function asrs(x: number, y: number): number;
function bnot(x: number): number;
function ignore(v: any): any;
}
namespace avr {
function adds(x: number, y: number): number;
function subs(x: number, y: number): number;
function divs(x: number, y: number): number;
function muls(x: number, y: number): number;
function ands(x: number, y: number): number;
function orrs(x: number, y: number): number;
function eors(x: number, y: number): number;
function lsls(x: number, y: number): number;
function lsrs(x: number, y: number): number;
function asrs(x: number, y: number): number;
function bnot(x: number): number;
function ignore(v: any): any;
}
namespace String_ {
function stringConv(v: any): void;
function mkEmpty(): string;
function fromCharCode(code: number): string;
function toNumber(s: string): number;
function concat(a: string, b: string): string;
function substring(s: string, i: number, j: number): string;
function equals(s1: string, s2: string): boolean;
function compare(s1: string, s2: string): 0 | 1 | -1;
function compareDecr(s1: string, s2: string): 0 | 1 | -1;
function length(s: string): number;
function substr(s: string, start: number, length?: number): string;
function charAt(s: string, i: number): string;
function charCodeAt(s: string, i: number): number;
function indexOf(s: string, searchValue: string, start?: number): number;
function lastIndexOf(s: string, searchValue: string, start?: number): number;
function includes(s: string, searchValue: string, start?: number): boolean;
function typeCheck(s: string): void;
}
namespace Boolean_ {
function toString(v: boolean): "true" | "false";
function bang(v: boolean): boolean;
}
class RefBuffer extends RefObject {
data: Uint8Array;
isStatic: boolean;
constructor(data: Uint8Array);
scan(mark: (path: string, v: any) => void): void;
gcKey(): string;
gcSize(): number;
gcIsStatic(): boolean;
print(): void;
toDebugString(): string;
}
namespace BufferMethods {
enum NumberFormat {
Int8LE = 1,
UInt8LE = 2,
Int16LE = 3,
UInt16LE = 4,
Int32LE = 5,
Int8BE = 6,
UInt8BE = 7,
Int16BE = 8,
UInt16BE = 9,
Int32BE = 10,
UInt32LE = 11,
UInt32BE = 12,
Float32LE = 13,
Float64LE = 14,
Float32BE = 15,
Float64BE = 16
}
function fmtInfo(fmt: NumberFormat): {
size: number;
signed: boolean;
swap: boolean;
isFloat: boolean;
};
function getNumber(buf: RefBuffer, fmt: NumberFormat, offset: number): number;
function setNumber(buf: RefBuffer, fmt: NumberFormat, offset: number, r: number): void;
function createBuffer(size: number): RefBuffer;
function createBufferFromHex(hex: string): RefBuffer;
function isReadOnly(buf: RefBuffer): boolean;
function getBytes(buf: RefBuffer): Uint8Array;
function getUint8(buf: RefBuffer, off: number): number;
function getByte(buf: RefBuffer, off: number): number;
function setUint8(buf: RefBuffer, off: number, v: number): void;
function setByte(buf: RefBuffer, off: number, v: number): void;
function length(buf: RefBuffer): number;
function fill(buf: RefBuffer, value: number, offset?: number, length?: number): void;
function slice(buf: RefBuffer, offset: number, length: number): RefBuffer;
function toHex(buf: RefBuffer): string;
function toString(buf: RefBuffer): string;
function shift(buf: RefBuffer, offset: number, start: number, len: number): void;
function rotate(buf: RefBuffer, offset: number, start: number, len: number): void;
function write(buf: RefBuffer, dstOffset: number, src: RefBuffer, srcOffset?: number, length?: number): void;
function typeCheck(buf: RefBuffer): void;
}
}
declare namespace pxsim.control {
function createBufferFromUTF8(str: string): RefBuffer;
}
declare namespace pxsim.localization {
function setLocalizedStrings(strs: Map<string>): void;
function lf(s: string, ...args: any[]): string;
function fmt_va(f: string, args: any[]): string;
function htmlEscape(_input: string): string;
function jsStringQuote(s: string): string;
}
declare namespace pxsim {
interface Logger {
info(...args: any[]): void;
log(...args: any[]): void;
debug(...args: any[]): void;
error(...args: any[]): void;
warn(...args: any[]): void;
setLogLevel(level: LogLevel): void;
getLogLevel(): LogLevel;
}
enum LogLevel {
Debug = 0,
Info = 1,
Log = 1,
Warning = 2,
Error = 3
}
class ConsoleLogger implements Logger {
protected logLevel: LogLevel;
constructor();
setLogLevel(level: LogLevel): void;
getLogLevel(): LogLevel;
info(...args: any[]): void;
log(...args: any[]): void;
debug(...args: any[]): void;
error(...args: any[]): void;
warn(...args: any[]): void;
protected shouldLog(level: LogLevel): boolean;
}
function info(...args: any[]): void;
function log(...args: any[]): void;
function debug(...args: any[]): void;
function error(...args: any[]): void;
function warn(...args: any[]): void;
function setLogger(impl: pxsim.Logger): void;
function setLogLevel(level: pxsim.LogLevel): void;
}
declare namespace pxsim {
export namespace U {
function containsClass(el: SVGElement | HTMLElement, classes: string): boolean;
function addClass(el: SVGElement | HTMLElement, classes: string): void;
function removeClass(el: SVGElement | HTMLElement, classes: string): void;
function remove(element: Element): void;
function removeChildren(element: Element): void;
function clear(element: Element): void;
function assert(cond: boolean, msg?: string): void;
function repeatMap<T>(n: number, fn: (index: number) => T): T[];
function userError(msg: string): Error;
function now(): number;
function perfNowUs(): number;
function nextTick(f: () => void): void;
function delay<T>(duration: number, value: T): Promise<T>;
function delay(duration: number): Promise<void>;
function throttle(func: (...args: any[]) => any, wait: number, immediate?: boolean): any;
function promiseMapAll<T, V>(values: T[], mapper: (obj: T) => Promise<V>): Promise<V[]>;
function promiseMapAllSeries<T, V>(values: T[], mapper: (obj: T) => Promise<V>): Promise<V[]>;
function promisePoolAsync<T, V>(maxConcurrent: number, inputValues: T[], handler: (input: T) => Promise<V>): Promise<V[]>;
function promiseTimeout<T>(ms: number, promise: T | Promise<T>, msg?: string): Promise<T>;
function stringToUint8Array(input: string): Uint8Array;
function uint8ArrayToString(input: ArrayLike<number>): string;
function fromUTF8(binstr: string): string;
function toUTF8(str: string, cesu8?: boolean): string;
function toUTF8Array(s: string): Uint8Array;
function fromUTF8Array(s: Uint8Array): string;
function isPxtElectron(): boolean;
function isIpcRenderer(): boolean;
function isElectron(): boolean;
function testLocalhost(url: string): boolean;
function isLocalHost(): boolean;
function isLocalHostDev(): boolean;
function unique<T>(arr: T[], f: (t: T) => string): T[];
function sanitizeCssName(name: string): string;
}
export interface Map<T> {
[index: string]: T;
}
export type LabelFn = (s: StackFrame) => StackFrame;
export type ResumeFn = (v?: any) => void;
export interface StackFrame {
fn: LabelFn;
pc: number;
overwrittenPC?: boolean;
depth: number;
r0?: any;
parent: StackFrame;
retval?: any;
lambdaArgs?: any[];
caps?: any[];
lastBrkId?: number;
callLocIdx?: number;
arg0?: any;
stage2Call?: boolean;
tryFrame?: TryFrame;
thrownValue?: any;
hasThrownValue?: boolean;
threadId?: number;
}
export interface TryFrame {
parent?: TryFrame;
handlerPC: number;
handlerFrame: StackFrame;
}
export class BreakLoopException {
}
export namespace pxtcore {
function beginTry(lbl: number): void;
function endTry(): void;
function throwValue(v: any): void;
function getThrownValue(): any;
function endFinally(): void;
}
export let runtime: Runtime;
export function getResume(): ResumeFn;
export type MessageListener = (msg: SimulatorMessage) => void;
export class BaseBoard {
id: string;
readonly bus: pxsim.EventBus;
runOptions: SimulatorRunMessage;
private readonly messageListeners;
constructor();
updateView(): void;
receiveMessage(msg: SimulatorMessage): void;
private dispatchMessage;
addMessageListener(listener: MessageListener): void;
get storedState(): Map<any>;
initAsync(msg: SimulatorRunMessage): Promise<void>;
setStoredState(k: string, value: any): void;
onDebuggerResume(): void;
screenshotAsync(width?: number): Promise<ImageData>;
kill(): void;
protected serialOutBuffer: string;
private messages;
private serialTimeout;
private lastSerialTime;
writeSerial(s: string): void;
private debouncedPostAll;
}
export class CoreBoard extends BaseBoard {
updateSubscribers: (() => void)[];
builtinParts: Map<any>;
builtinVisuals: Map<() => visuals.IBoardPart<any>>;
builtinPartVisuals: Map<(xy: visuals.Coord) => visuals.SVGElAndSize>;
constructor();
kill(): void;
}
export interface EventBusBoard {
bus: EventBus;
}
export function initBareRuntime(): void;
export type EventValueToActionArgs = (value: EventIDType) => any[];
export type EventIDType = number | string;
class EventHandler {
handler: RefAction;
flags: number;
private busy;
constructor(handler: RefAction, flags: number);
runAsync(eventValue: EventIDType, runtime: Runtime, valueToArgs?: EventValueToActionArgs): Promise<void>;
private runFiberAsync;
}
export class EventQueue {
runtime: Runtime;
private valueToArgs?;
max: number;
events: EventIDType[];
private awaiters;
private lock;
private _handlers;
private _addRemoveLog;
constructor(runtime: Runtime, valueToArgs?: EventValueToActionArgs);
push(e: EventIDType, notifyOne: boolean): Promise<void>;
private poke;
get handlers(): EventHandler[];
setHandler(a: RefAction, flags?: number): void;
addHandler(a: RefAction, flags?: number): void;
removeHandler(a: RefAction): void;
addAwaiter(awaiter: (v?: any) => void): void;
}
export let initCurrentRuntime: (msg: SimulatorRunMessage) => void;
export let handleCustomMessage: (message: pxsim.SimulatorCustomMessage) => void;
export function syntheticRefAction(f: (s: StackFrame) => any): RefAction;
export class TimeoutScheduled {
id: any;
fn: Function;
totalRuntime: number;
timestampCall: number;
constructor(id: any, fn: Function, totalRuntime: number, timestampCall: number);
}
export class PausedTimeout {
fn: Function;
timeRemaining: number;
constructor(fn: Function, timeRemaining: number);
}
export function mkVTable(src: VTable): VTable;
export function mkMapVTable(): VTable;
export function functionName(fn: LabelFn): string;
export class Runtime {
board: BaseBoard;
numGlobals: number;
errorHandler: (e: any) => void;
postError: (e: any) => void;
stateChanged: () => void;
dead: boolean;
running: boolean;
idleTimer: any;
recording: boolean;
recordingTimer: any;
recordingLastImageData: ImageData;
recordingWidth: number;
startTime: number;
startTimeUs: number;
pausedTime: number;
lastPauseTimestamp: number;
id: string;
globals: any;
environmentGloba