brokkr

Bytecode virtual machine for Valhalla.
git clone git://git.knutsen.co/brokkr
Log | Files | Refs | README | LICENSE

bytecode_spec.yaml (8011B)


# -   :byte: n
#     :name: s
#     :operands: n
#     :operand_desc: ['']
#     :desc: >-
#        ...

-   :byte: 0
    :name: EOI
    :operands: 0
    :desc: >-
        End Of Instructions! This is not a real opcode and
        only appears at the end of the instruction byte-stream
        to signal that there are no more instructions to be read.
        Essentially it's just a null-terminator.

-   :byte: 200
    :name: HALT
    :operands: 1
    :operand_desc: ['Exit Code (Integer)']
    :desc: >-
        Stops execution.

-   :byte: 1
    :name: PUSH_CONST
    :operands: 1
    :operand_desc: ['Unsigned index to constants table']
    :desc: >-
        Pushes a constant onto the stack.
        Constant is specified by a given index to the
        constant-table, containing all local constant.

-   :byte: 2
    :name: PUSH_LOCAL
    :operands: 1
    :operand_desc: ['Local variable index (Unsigned)']
    :desc: >-
       Pushes a local variable (e.g. a function param)
       onto the stack. The local variable is identified by
       an index operand, to where it is in the current symbol
       table.

-   :byte: 3
    :name: PUSH_SUPER
    :operands: 1
    :operand_desc: ['Name of super-scoped variable (String)']
    :desc: >-
       When a variable is out of the local scope, load it
       onto the stack by
       searching up the super-scope by its name, (much slower
       than `PUSH_LOCAL`).

-   :byte: 4
    :name: POP
    :operands: 0
    :desc: >-
       Pops the top element off of the stack.

-   :byte: 5
    :name: STORE_LOCAL
    :operands: 1
    :operand_desc: ['Index to store local variable in table (Unsigned)']
    :desc: >-
       Pops the top value and stores it in the local symbol table
       at a given index.

# -   :byte: 6
#     :name: STORE_SUPER
#     :operands: 1
#     :operand_desc: ['Name of super-scoped variable (String)']
#     :desc: >-
#        When a variable is out of the local scope, pop it
#        off of the stack to store it in the super-scope
#        searching up the frames for its name, (much slower
#        than `STORE_LOCAL`).

-   :byte: 6
    :name: DUP
    :operands: 0
    :desc: >-
        Duplicates what was on the top of the stack,
        by popping it off and then pushing two copies.

-   :byte: 7
    :name: DUP_N
    :operands: 1
    :operand_desc: ['The number of duplicates']
    :desc: >-
        Duplicates the top value on the stack N times.

-   :byte: 8
    :name: SWAP
    :operands: 0
    :desc: >-
        Swaps the position of the top two stack elements.

-   :byte: 9
    :name: CALL_1
    :operands: 0
    :desc: >-
        Calls function at top of stack with argument at second
        from top of stack.

-   :byte: 10
    :name: CHECK_TYPE
    :operands: 0
    :desc: >-
       Checks if second from top of stack value is a member
       of the set/type loaded from the top of the stack.

-   :byte: 11
    :name: CAST
    :operands: 2
    :operand_desc: [
        'One byte, specifies the origin type.',
        'One byte, specifies the destination type.'
    ]
    :desc: >-
       Changes the top-of-stack value to have a different
       primitive type.

-   :byte: 12
    :name: MAKE_FUNC
    :operands: 0
    :desc: >-
       Takes the top-of-stack value, referencing a code
       block, and makes it a function, with all the special
       properties that come with that.

-   :byte: 13
    :name: YIELD
    :operands: 0
    :desc: >-
       Causes the current function to yield a value
       (i.e. return).

-   :byte: 14
    :name: RAW_PRINT
    :operands: 0
    :desc: >-
       Native debug print of `TOS`.
       Should not be used unless working on the
       compiler.

-   :byte: 40
    :name: N_ADD
    :operands: 0
    :desc: >-
       Addition between two pointer-sized unsigned integers.
       Pops top two elements from the stacks and adds
       them together, pushing the result.

-   :byte: 41
    :name: I_ADD
    :operands: 0
    :desc: >-
       Addition between two pointer-sized signed integers.
       Pops top two elements from the stacks and adds
       them together, pushing the result.

-   :byte: 42
    :name: R_ADD
    :operands: 0
    :desc: >-
       Addition between two 64-bit floating-point numbers.
       Pops top two elements from the stacks and adds
       them together, pushing the result.

-   :byte: 43
    :name: U_ADD
    :operands: 0
    :desc: >-
       Addition between two values of unknown types, found out at runtime.
       Pops top two elements from the stacks and adds
       them together, pushing the result.

-   :byte: 44
    :name: CONCAT
    :operands: 0
    :desc: >-
       Works like add, but concatenates strings.

-   :byte: 45
    :name: N_SUB
    :operands: 0
    :desc: >-
       Subtraction between two pointer-sized unsigned integers.
       Pops top two elements from the stacks and subtracts
       them together, pushing the result.

-   :byte: 46
    :name: I_SUB
    :operands: 0
    :desc: >-
       Subtraction between two pointer-sized signed integers.
       Pops top two elements from the stacks and subtracts
       them together, pushing the result.

-   :byte: 47
    :name: R_SUB
    :operands: 0
    :desc: >-
       Subtraction between two 64-bit floating-point numbers.
       Pops top two elements from the stacks and subtracts
       them together, pushing the result.

-   :byte: 48
    :name: U_SUB
    :operands: 0
    :desc: >-
       Subtraction between two values of unknown types, found out at runtime.
       Pops top two elements from the stacks and subtracts
       one from the other, pushing the result.

-   :byte: 49
    :name: N_MUL
    :operands: 0
    :desc: >-
       Multiplication between two pointer-sized unsigned integers.
       Pops top two elements from the stacks and multiplies
       them together, pushing the result.

-   :byte: 50
    :name: I_MUL
    :operands: 0
    :desc: >-
       Multiplication between two pointer-sized signed integers.
       Pops top two elements from the stacks and multiplies
       them together, pushing the result.

-   :byte: 51
    :name: R_MUL
    :operands: 0
    :desc: >-
       Multiplication between two 64-bit floating-point numbers.
       Pops top two elements from the stacks and multiplies
       them together, pushing the result.

-   :byte: 52
    :name: U_MUL
    :operands: 0
    :desc: >-
       Multiplication between two values of unknown types, found out at runtime.
       Pops top two elements from the stacks and multiplies
       them together, pushing the result.

-   :byte: 53
    :name: N_DIV
    :operands: 0
    :desc: >-
       Division between two pointer-sized unsigned integers.
       Pops top two elements from the stacks and finds their
       quotient, pushing the result.

-   :byte: 54
    :name: I_DIV
    :operands: 0
    :desc: >-
       Division between two pointer-sized signed integers.
       Pops top two elements from the stacks and finds their
       quotient, pushing the result.

-   :byte: 55
    :name: R_DIV
    :operands: 0
    :desc: >-
       Division between two 64-bit floating-point numbers.
       Pops top two elements from the stacks and finds their
       quotient, pushing the result.

-   :byte: 56
    :name: U_DIV
    :operands: 0
    :desc: >-
       Division between two values of unknown types, found out at runtime.
       Pops top two elements from the stacks and finds their
       quotient, pushing the result.


-   :byte: 254
    :name: SET_LINE
    :operands: 1
    :operand_desc: ['Current line number, given directly as `u16`. Operand value is line number.']
    :desc: >-
       Sets the current line number that the subsequent
       bytecode instructions correspond to in the code
       source file.

-   :byte: 255
    :name: NOP
    :operands: 0
    :desc: >-
       <u>N</u>o <u>Op</u>eration. Does nothing.
       You shouldn't see this in the final compiled
       bytecode, it may only exists temporarily while the
       bytecode is being produced.