From 889365c56fdf38ef5ab02bcc2afc5b5968e476a6 Mon Sep 17 00:00:00 2001 From: Tim Voronov Date: Fri, 6 Jun 2025 16:38:07 -0400 Subject: [PATCH] Categorize and group opcodes; improve readability and maintainability of `opcode.go` --- pkg/vm/opcode.go | 86 +++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/pkg/vm/opcode.go b/pkg/vm/opcode.go index 1727286f..3efceb12 100644 --- a/pkg/vm/opcode.go +++ b/pkg/vm/opcode.go @@ -1,30 +1,38 @@ package vm -// Opcode represents an operation code used in virtual machine instruction sets. type Opcode byte const ( - OpReturn Opcode = iota - OpMove // Move a value from register A to register B - OpLoadNone // Set None value to a register - OpLoadBool // Set a boolean value to a register - OpLoadZero // Set a zero value to a register - OpLoadConst // Load a constant to a register or a global variable - OpLoadGlobal // Load a global variable to a register A - OpStoreGlobal // Store a value from register A to a global variable - OpLoadParam // Load a parameter to a register A - OpLoadIndex // Load a value from a list to a register (INDEX R1, R2, R3 - loads a value from a list in R2 to R1) - OpLoadIndexOptional // Load a value from a list to a register, if it exists - OpLoadKey // Load a value from a map to a register (KEY R1, R2, R3 - loads a value from a map in R2 to R1) - OpLoadKeyOptional // Load a value from a map to a register, if it exists - OpLoadProperty // Load a property (key or index) from an object (map or list) to a register - OpLoadPropertyOptional // Load a property (key or index) from an object (map or list) to a register, if it exists - + // Control Flow + OpReturn Opcode = iota OpJump OpJumpIfFalse OpJumpIfTrue OpJumpIfEmpty + // Register Operations + OpMove // Move a value from register A to register B + + // Loading Operations + OpLoadNone // Set None value to a register + OpLoadBool // Set a boolean value to a register + OpLoadZero // Set a zero value to a register + OpLoadConst // Load a constant to a register or a global variable + OpLoadParam // Load a parameter to a register A + + // Global Variable Operations + OpLoadGlobal // Load a global variable to register A + OpStoreGlobal // Store a value from register A to a global variable + + // Collection Access Operations + OpLoadIndex // Load a value from a list to a register + OpLoadIndexOptional // Load a value from a list to a register, if it exists + OpLoadKey // Load a value from a map to a register + OpLoadKeyOptional // Load a value from a map to a register, if it exists + OpLoadProperty // Load a property from an object to a register + OpLoadPropertyOptional // Load a property from an object to a register, if it exists + + // Arithmetic Operations OpAdd OpSub OpMulti @@ -33,52 +41,62 @@ const ( OpIncr OpDecr + // Type Operations OpCastBool OpNegate OpFlipPositive OpFlipNegative + // Comparison Operations OpComp OpNot OpEq OpNeq - OpIn - OpNotIn OpGt OpLt OpGte OpLte + + // Membership & Pattern Matching + OpIn + OpNotIn OpLike OpNotLike OpRegexpPositive OpRegexpNegative + // Utility Operations OpLength OpType OpClose OpSleep + // Function Operations OpCall OpProtectedCall - OpList // Load an array from a list of registers (ARR R2, R3 R5 - creates an array in R2 with elements from R3 to R5) - OpMap // Load an object from a list of registers (OBJ R2, R3 R5 - creates an object in R2 with elements from R3 to R5) - OpRange // Load a range from a list of registers (RNG R2, R3, R4 - creates a range in R2 with start from R3 and end at R4) - OpDataSet // Load a dataset to a register A + // Collection Creation + OpList // Create an array + OpMap // Create an object + OpRange // Create a range + + // Dataset Operations + OpDataSet OpDataSetCollector OpDataSetSorter OpDataSetMultiSorter - - OpStream // Subscribes to a stream (SMRCV R2, R3, R4 - subscribes to a stream in R2 with a collection from R3 and optional params from R4) - OpStreamIter // Consumes a stream (SMRD R2, R3 - consumes a stream in R2 with a collection from R3) - - OpIter // Creates an iterator (ITER R2, R3 [, R4] - creates an iterator in R2 with a collection from R3 and optional params from R4) - OpIterNext // Moves to the next element in the iterator (ITER R2, R3 - moves to the next element in the iterator in R2 with a collection from R3) - OpIterValue // Returns the current value from the iterator (ITER R2, R3 - returns the current value from the iterator in R2 with a collection from R3) - OpIterKey // Returns the current key from the iterator (ITER R2, R3 - returns the current key from the iterator in R2 with a collection from R3) - OpIterLimit - OpIterSkip - OpPush // Adds a value to a dataset OpPushKV // Adds a key-value pair to a dataset + + // Stream Operations + OpStream // Subscribes to a stream + OpStreamIter // Consumes a stream + + // Iterator Operations + OpIter // Creates an iterator + OpIterNext // Moves to the next element + OpIterValue // Returns the current value + OpIterKey // Returns the current key + OpIterLimit + OpIterSkip )