import { InstrArgResolver, Op, BuiltInString, BuiltInObject, FunctionFlag } from "./format";
import { SrcLocation } from "@devicescript/interop";
export interface TopOpWriter extends InstrArgResolver {
    addString(s: string): number;
    addBuffer(s: Uint8Array): number;
    addFloat(f: number): number;
    writer: OpWriter;
    hasErrors: boolean;
    isLibrary: boolean;
    onCall(): void;
}
export declare class Label {
    name: string;
    uses: number[];
    offset: number;
    constructor(name: string);
}
export declare class Value {
    op: number;
    flags: number;
    args: Value[];
    numValue: number;
    strValue: string;
    _userdata: {};
    _cachedValue: CachedValue;
    constructor();
    get maxstack(): number;
    get usesState(): boolean;
    get hasParent(): boolean;
    get isLiteral(): boolean;
    get isMemRef(): boolean;
    adopt(): void;
    ignore(): void;
    assumeStateless(): void;
    _set(src: Value): void;
    get staticIdx(): number;
    toString(): string;
    clone(): Value;
}
export declare class CachedValue {
    parent: OpWriter;
    index: number;
    numRefs: number;
    _longTerm: boolean;
    constructor(parent: OpWriter, index: number);
    get packedIndex(): number;
    get isCached(): boolean;
    emit(): Value;
    store(v: Value): void;
    finalEmit(): Value;
    _decr(): void;
    free(): void;
}
export declare function literal(v: number | boolean): Value;
export declare function nonEmittable(): Value;
export declare enum VariableKind {
    Global = 0,
    ThisParam = 1,
    Parameter = 2,
    Cached = 3,
    Local = 4
}
export declare function packVarIndex(vk: VariableKind, idx: number): number;
export declare class OpWriter {
    prog: TopOpWriter;
    name: string;
    private binary;
    private binPtr;
    private labels;
    private bufferAllocated;
    pendingStatefulValues: Value[];
    localOffsets: number[];
    cachedValues: CachedValue[];
    funFlags: FunctionFlag;
    top: Label;
    ret: Label;
    desc: Uint8Array;
    offsetInFuncs: number;
    offsetInImg: number;
    private locStack;
    srcmap: number[];
    private nameIdx;
    private lastReturnLocation;
    private closureRefs;
    constructor(prog: TopOpWriter, name: string);
    assertCurrent(): void;
    serialize(): Uint8Array;
    get size(): number;
    finalizeDesc(off: number): void;
    _forceFinStmt(): void;
    private recordLocation;
    locPush(pos: SrcLocation): void;
    locPop(): void;
    private allocTmpLocals;
    allocTmpLocal(): CachedValue;
    needsCache(v: Value): boolean;
    cacheValue(v: Value, longTerm?: boolean): CachedValue;
    stmtEnd(): void;
    freeBuf(): void;
    emitString(s: string | Uint8Array): Value;
    getAssembly(): string;
    mkLabel(name: string): Label;
    _setLabelOffset(l: Label, off: number): void;
    emitLabel(l: Label): void;
    emitIfAndPop(reg: Value, thenBody: () => void, elseBody?: () => void): void;
    emitJumpIfTrue(label: Label, cond: Value): void;
    emitJumpIfFalse(label: Label, cond: Value): void;
    emitJump(label: Label): void;
    emitJumpIfRetValNullish(label: Label): void;
    emitTry(label: Label): void;
    emitEndTry(label: Label): void;
    emitThrowJmp(label: Label, level: number): void;
    private _emitJump;
    private oops;
    assertNoTemps(really?: boolean): void;
    patchLabels(numLocals: number, numargs: number, tryDepth: number): (v: number) => number;
    numSlots(): number;
    private spillValue;
    private spillAllStateful;
    emitMemRef(op: Op, idx: number): Value;
    emitExpr(op: Op, ...args: Value[]): Value;
    location(): number;
    private writeByte;
    private writeInt;
    private saveLocalIdx;
    private writeArgs;
    private writeValue;
    makeFunctionsStatic(isStatic: (fnidx: number) => boolean): void;
    emitStmt(op: Op, ...args: Value[]): void;
    justHadReturn(): boolean;
    emitCall(fn: Value, ...args: Value[]): void;
    emitBuiltInObject(obj: BuiltInObject): Value;
    emitIndex(obj: Value, field: Value): Value;
    builtInMember(obj: Value, name: BuiltInString): Value;
    staticBuiltIn(obj: BuiltInObject, name: BuiltInString): Value;
    dsMember(name: BuiltInString): Value;
    mathMember(name: BuiltInString): Value;
    objectMember(name: BuiltInString): Value;
}
export declare class SectionWriter {
    size: number;
    offset: number;
    currSize: number;
    data: Uint8Array[];
    desc: Uint8Array;
    constructor(size?: number);
    finalize(off: number): void;
    align(): void;
    append(buf: Uint8Array): void;
}
export declare class DelayedCodeSection {
    name: string;
    parent: OpWriter;
    startLabel: Label;
    returnLabel: Label;
    body: ((wr: OpWriter) => void)[];
    constructor(name: string, parent: OpWriter);
    empty(): boolean;
    emit(f: (wr: OpWriter) => void): void;
    callHere(): void;
    finalizeRaw(): void;
    finalize(): void;
}
export declare function bufferFmt(mem: jdspec.PacketMember): number;
//# sourceMappingURL=opwriter.d.ts.map