mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
49bd3c22f3
* 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>
77 lines
2.1 KiB
YAML
77 lines
2.1 KiB
YAML
# CallRule Test Suite
|
|
# Validates rule caching, partial structures, defaults, and inconsistencies.
|
|
|
|
cases:
|
|
- note: call_rule_basic_cache
|
|
description: CallRule caches results after first evaluation
|
|
literals:
|
|
- {}
|
|
- 1
|
|
rule_infos:
|
|
- rule_type: Complete
|
|
definitions:
|
|
- [3]
|
|
rule_tree:
|
|
data:
|
|
test:
|
|
allow: 0
|
|
instructions:
|
|
- "CallRule { dest: 0, rule_index: 0 }"
|
|
- "CallRule { dest: 2, rule_index: 0 }"
|
|
- "Return { value: 2 }"
|
|
- "RuleInit { result_reg: 1, rule_index: 0 }"
|
|
- "Load { dest: 1, literal_idx: 1 }"
|
|
- "RuleReturn {}"
|
|
want_result: 1
|
|
|
|
- note: call_rule_partial_object_default
|
|
description: Partial object rule returns object even when no fields defined
|
|
literals:
|
|
- {}
|
|
rule_infos:
|
|
- rule_type: PartialObject
|
|
definitions:
|
|
- [2]
|
|
instructions:
|
|
- "CallRule { dest: 0, rule_index: 0 }"
|
|
- "Return { value: 0 }"
|
|
- "RuleInit { result_reg: 1, rule_index: 0 }"
|
|
- "RuleReturn {}"
|
|
want_result: {}
|
|
|
|
- note: call_rule_default_literal
|
|
description: Default literal used when complete rule returns undefined
|
|
literals:
|
|
- "default"
|
|
rule_infos:
|
|
- rule_type: Complete
|
|
definitions:
|
|
- [2]
|
|
default_literal_index: 0
|
|
instructions:
|
|
- "CallRule { dest: 0, rule_index: 0 }"
|
|
- "Return { value: 0 }"
|
|
- "RuleInit { result_reg: 1, rule_index: 0 }"
|
|
- "RuleReturn {}"
|
|
want_result: "default"
|
|
|
|
- note: call_rule_inconsistency
|
|
description: Complete rule with inconsistent results returns undefined
|
|
literals:
|
|
- 1
|
|
- 2
|
|
rule_infos:
|
|
- rule_type: Complete
|
|
definitions:
|
|
- [2, 5]
|
|
instructions:
|
|
- "CallRule { dest: 0, rule_index: 0 }"
|
|
- "Return { value: 0 }"
|
|
- "RuleInit { result_reg: 1, rule_index: 0 }"
|
|
- "Load { dest: 1, literal_idx: 0 }"
|
|
- "RuleReturn {}"
|
|
- "RuleInit { result_reg: 1, rule_index: 0 }"
|
|
- "Load { dest: 1, literal_idx: 1 }"
|
|
- "RuleReturn {}"
|
|
want_result: "#undefined"
|