-
Notifications
You must be signed in to change notification settings - Fork 0
Instruction Set Architecture
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.
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;
};
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!
- 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.
- 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
p2arguments. -
OP_FOR_EACH_NEXT: Optimized iterator instruction for the
foreachloop.
-
OP_CLASS / OP_METHOD / OP_INHERIT: Full
OOPsupport 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.
-
OP_ATTEMPT / OP_END_ATTEMPT: The opcode for the
attempt/failstatements. -
OP_PANIC: Triggers the visual error reporting (seen in the Readme) and also support for the
panickeyword.
©2026 Johnryzon - Ry is licensed with MIT