Simplifies the code by using the type switch variable binding instead of
performing an additional type assertion.
Signed-off-by: Ville Vesilehto <[email protected]>
Co-authored-by: Anton Medvedev <[email protected]>
* feat: extract code for compiling equal operator
* fix: fix unary and binary node print
consider the precedence of operators and their associative law when printing unary and binary nodes
---------
Co-authored-by: Anton Medvedev <[email protected]>
* Reset tracking of applied operator overloads before every walk of the ast tree.
* Remove limit on operator overload resolution
* Do separate patcher phase for those that require multiple passes (Currently only need for Operator overloading). This patcher phase is run after other patchers.
* Add test to track how many times a patcher is run. Used to detect if patching phases is erroneously applying the patcher multiple times.
---------
Co-authored-by: Anton Medvedev <[email protected]>
* feat: add node budget and memory limits
Implement compile-time and runtime safeguards against deeply nested expressions:
- Add MaxNodes limit to track and limit AST node count during parsing
- Move MemoryBudget from VM to Config for better configurability
- Add node creation tracking in parser to enforce node budget
- Refactor node creation to check limits before allocation
- Add RunWithConfig to VM for passing memory budget settings
- Set reasonable defaults in Config (10000 nodes, 1M memory)
- Add comprehensive tests for both node and memory limits
This prevents stack overflows from malicious or poorly written expressions
by failing fast with clear error messages during compilation or runtime.
Signed-off-by: Ville Vesilehto <[email protected]>
* Update parser.go
Signed-off-by: Anton Medvedev <[email protected]>
---------
Signed-off-by: Ville Vesilehto <[email protected]>
Signed-off-by: Anton Medvedev <[email protected]>
Co-authored-by: Anton Medvedev <[email protected]>
Expand test coverage to newer Go versions and fix compatibility issues:
- Add Go 1.23 and 1.24 to test matrix in test.yml
- Add Go 1.24 to build matrix in build.yml
- Fix example test names to match Go conventions:
* ExampleOperator_Decimal → ExampleOperator_with_decimal
* ExampleWithTimezone → ExampleTimezone
* ExampleGetUnifiedDiffCode → ExampleGetUnifiedDiffString
* ExampleGetContextDiffCode → ExampleGetContextDiffString
* ExampleGetContextDiffString → ExampleGetContextDiffString_second
These changes maintain compatibility with Go 1.18 (as specified in
go.mod) while ensuring the codebase works correctly with the latest
Go versions, which enforce stricter naming conventions for example
tests.
Signed-off-by: Ville Vesilehto <[email protected]>
Co-authored-by: Anton Medvedev <[email protected]>
Fix CI workflow compatibility issues and update dependencies:
- Pin benchstat to specific commit (884df5) compatible with Go 1.18
instead of using @latest which now requires Go 1.23+
- Add explanatory comment about benchstat version constraints
- Upgrade actions/upload-artifact from v3 to v4 in fuzz.yml
- Upgrade github/codeql-action from v2 to v3 in fuzz.yml
These changes ensure the CI pipeline remains compatible with Go 1.18
while benefiting from the latest improvements in GitHub Actions.
Signed-off-by: Ville Vesilehto <[email protected]>
Add extensive test coverage for VM opcodes including:
- Basic operations (OpLoadEnv, OpTrue, OpFalse, OpNil)
- Arithmetic operations (OpNegate, OpExponent)
- String operations (OpEqualString, OpMatches)
- Collection operations (OpIn, OpLen)
- Type operations (OpCast)
- Control flow (OpThrow)
- Function calls (OpCall0-3, OpCallN)
- Index and count manipulation (OpGetIndex, OpSetIndex)
- Profiling operations (OpProfileStart, OpProfileEnd)
Also add high-level expression tests for:
- Arithmetic expressions
- String operations
- Data structure operations
- Group and sort operations
Each test case includes detailed comments and covers both success and error cases.
These tests combined with a debugger helped me navigate the VM internals
significantly.
Signed-off-by: Ville Vesilehto <[email protected]>
This PR introduces a new concept inside Expr's type checker - Nature.
It's an abstraction other reflect.Type which carries additional information about possible type, methods and builtin function.
I was able to find and fix a few bugs in type checker and optimizer. Implementation of nature concept has proven itself. As well nature will allow to bring more feature for type checker in future.
Why Nature? I was looking for a name to replace Type. Type name already carries much information, as well can be confused with reflect.Type. Nature name should be understood as "nature of the node", same as "type of the node".