mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
feat!: add Rego Virtual Machine (RVM) implementation (#495)
* feat!: add Rego Virtual Machine (RVM) implementation This commit introduces a register-based virtual machine for executing Rego policies with bytecode-style instructions. Unlike the existing tree-walking interpreter, the RVM compiles policies into instruction sequences that operate on virtual registers, offering better performance and optimization potential. Core Components: Instruction Set Architecture: - Define instruction types for data operations, control flow, and builtins - Implement instruction parameter encoding and display formatting - Add instruction parser with comprehensive test coverage Virtual Machine Engine: - Register-based execution model with program counter management - Loop execution supporting iterators, comprehensions, and quantifiers - Function call handling with argument evaluation and context management - Rule evaluation with default value resolution and virtual data support - Arithmetic and comparison operation implementations Program Representation: - Program listing builder with instruction sequencing - Rule tree construction for organizing policy rules - Binary and JSON serialization for compiled programs - Recompilation support for program modification Testing Infrastructure: - Extensive YAML test suites covering all VM features - Rust unit tests for VM execution and instruction parsing - Test suites for loops, comprehensions, builtins, and control flow BREAKING CHANGE: Introduces new VM execution path alongside interpreter Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> * docs: add detailed RVM architecture references Introduce architecture.md explaining program artifacts, serialization, and runtime subsystems. Document the full opcode catalog in instruction-set.md, including operands, parameter tables, and outcomes. Walk through execution flow, stacks, and operational guidance in vm-runtime.md, tying the runtime to the new architecture docs. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> --------- Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
6dc505c88b
commit
49bd3c22f3
@@ -0,0 +1,61 @@
|
||||
# Invalid Collection Operations Test Suite
|
||||
# Exercises error conditions for collection-specific instructions.
|
||||
|
||||
cases:
|
||||
- note: object_set_on_non_object
|
||||
description: ObjectSet on non-object register triggers error
|
||||
literals:
|
||||
- 1
|
||||
- "key"
|
||||
instructions:
|
||||
- "Load { dest: 0, literal_idx: 0 }"
|
||||
- "Load { dest: 1, literal_idx: 1 }"
|
||||
- "ObjectSet { obj: 0, key: 1, value: 1 }"
|
||||
want_error: "Register 0 does not contain an object"
|
||||
|
||||
- note: array_push_on_non_array
|
||||
description: ArrayPush on scalar register fails
|
||||
literals:
|
||||
- 1
|
||||
- 2
|
||||
instructions:
|
||||
- "Load { dest: 0, literal_idx: 0 }"
|
||||
- "Load { dest: 1, literal_idx: 1 }"
|
||||
- "ArrayPush { arr: 0, value: 1 }"
|
||||
want_error: "Register 0 does not contain an array"
|
||||
|
||||
- note: set_add_on_non_set
|
||||
description: SetAdd on scalar register fails
|
||||
literals:
|
||||
- 1
|
||||
- 2
|
||||
instructions:
|
||||
- "Load { dest: 0, literal_idx: 0 }"
|
||||
- "Load { dest: 1, literal_idx: 1 }"
|
||||
- "SetAdd { set: 0, value: 1 }"
|
||||
want_error: "Register 0 does not contain a set"
|
||||
|
||||
- note: object_create_invalid_template
|
||||
description: ObjectCreate fails when template literal is not object
|
||||
literals:
|
||||
- []
|
||||
instruction_params:
|
||||
object_create_params:
|
||||
- dest: 0
|
||||
template_literal_idx: 0
|
||||
literal_key_fields: []
|
||||
fields: []
|
||||
instructions:
|
||||
- "ObjectCreate { params_index: 0 }"
|
||||
want_error: "ObjectCreate: template is not an object"
|
||||
|
||||
- note: contains_on_scalar_returns_false
|
||||
description: Contains on scalar should return false
|
||||
literals:
|
||||
- 1
|
||||
instructions:
|
||||
- "Load { dest: 0, literal_idx: 0 }"
|
||||
- "Load { dest: 1, literal_idx: 0 }"
|
||||
- "Contains { dest: 2, collection: 0, value: 1 }"
|
||||
- "Return { value: 2 }"
|
||||
want_result: false
|
||||
Reference in New Issue
Block a user