C0 Runtime

C0RT (C0 Runtime Instance)

A C0RT is an abstract class defined in ./src/types.d.ts that contains following interface:

declare abstract class C0VM_RT {
    abstract step_forward(UIHooks: ReactUIHook): boolean;
     /**
     * @deprecated This method "restart" is a legacy from the original
     * vanilla HTML frontend. It should not be used anymore in the React
     * frontend.
     */
    abstract restart(): void;
    abstract debug(): any;
}

The actual C0VM state, heap allocator and all things are encapsulated into this Runtime instance.

When the function step_forward is called, the C0VM will execute a single bytecode instruction from the .bc0 string given in constructor and returns a boolean value.

  • If result is true, the VM can continue "step forward".

  • If result is false, the VM either have executed all the commands in bytecode or have met a breakpoint.

C0VM_RuntimeState

Defined in ./src/vm_core/exec/state.ts, the state C0VM_RuntimeState is defined as follow:

export default class C0VM_RuntimeState implements C0VM_RT{
    public raw_code: string;
    public code: C0ByteCode;
    public state: VM_State;
    public allocator: C0HeapAllocator;
    public heap_size: undefined | number

    constructor(rawByteCode: string, heapSize?: number);
    public step_forward(UIHooks: ReactUIHook): boolean;
    public restart(): never;
    public clone(): C0VM_RuntimeState;
    public debug(): any;
}

constructor method

Receives a raw byte code and initialize the virtual machine. The PC will be set to the first byte in main function.

step_forward method

Execute a step in virtual machine, that is, execute a single bytecode instruction at the position PC points to.

restart method

This method is deprecated as it is an "anti-pattern" in current react framework. This method is here just to comply with C0RT interface and should never be used.

clone method

Return a shallow copy of the state itself.

The clone method in this class is to deal with the immutability requirement of React. Calling this function will return a shallow copy of original C0VM state.

debug method

Returns a reference to the heap memory if DEBUG option is set to true.

Last updated