Skip to content
This repository was archived by the owner on Jul 25, 2026. It is now read-only.

Instruction Set Architecture

johnryzon123 edited this page Mar 20, 2026 · 2 revisions

Ry2 is a high-performance Register-based VM also with direct threading. Unlike traditional stack machines that push/pop constantly, Ry2 operates directly on registers (R[p1], R[p2], R[p3]), significantly reducing memory traffic and opcode count.

Instruction Format

The Instruction is the main segment of the vm to understand your code. It consists of 4 parts, which is the OpCode, Register 1(p1), Register 2(p2), and Register 3(p3). The OpCode is the bytecode name itself it acts like an id for the vm to stop guessing on what the OpCode is. The next part of the Instruction is the Register 1, It holds the destination for the output from the vm. Then here comes the Register 2, The Register 2 is where the first source of the code is. Then the last one is Register 3, It holds the seconds source from the code.

struct Instruction {
    OpCode opcode;
    uint8_t p1;
    uint8_t p2;
    uint8_t p3;
};

OpCode Reference

Note: Not all OpCodes are referenced here, Pls contribute to the project so that I could focus on making both the Ry language and RyzOS!

Core Data Movement

  • OP_MOVE(R[p1] to R[p2]): A Register to Register Transfer
  • OP_LOAD_CONST(R[p1] to constants[p2 and p3]): Loads a 16-bit constant.
  • OP_TYPE_LOCK/OP_TYPE_UNLOCK: Ensures type safety for variables at the VM.

Control flow and Functions

  • OP_JUMP / OP_JUMP_IF_FALSE: 16-bit jumps for high-speed branching.
  • OP_CLOSURE: Captures upvalues for functional programming.
  • OP_CALL: Dispatches a function call with p2 arguments.
  • OP_FOR_EACH_NEXT: Optimized iterator instruction for the foreach loop.

Object-Oriented & Classes

  • OP_CLASS / OP_METHOD / OP_INHERIT: Full OOP support directly in the bytecode.
  • OP_GET_PROPERTY / OP_SET_PROPERTY: Setting and Getting on properties.
  • OP_DEFINE_PRIVATE_FIELD: Defines the support for private class members.

Error Handling

  • OP_ATTEMPT / OP_END_ATTEMPT: The opcode for the attempt/fail statements.
  • OP_PANIC: Triggers the visual error reporting (seen in the Readme) and also support for the panic keyword.

Clone this wiki locally