* fix runtime error not allowing to slice unaddressable array type
* simplify logic and move test
* remove dead code
---------
Signed-off-by: Anton Medvedev <[email protected]>
Co-authored-by: Anton Medvedev <[email protected]>
* allow ignoring struct member using a - in expr struct tag
* fix in operator
* simplify logic
* add regression test for #807
* fixes#807: make in operator return false for unexported struct fields
---------
Co-authored-by: Anton Medvedev <[email protected]>
* convert source to a struct and fix minor issue displaying error
* lexer: add byte and char pos
* improve parser to use string instead of []rune
* add lexer benchmarks
* make lexer work as an iterator
* make parser use the new iterator API in lexer
* allow reusing the parser
* cleanup code
* add parser benchmarks
* 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]>
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]>
* Add concat() builtin
* Use pkg deref in builtin
* Use pkg deref in checker
* Use pkg deref in types_table.go
* Use pkg deref in docgen.go
* Use pkg deref in vm
* Fix OpDeref allowing to deref pointer of interfaces
Loop over `Ptr` and `Interface` kind and get `Elem`. Also return
directly the `nil` otherwise we might are returning the pointer nil
value and not the base nil.
* Fix deref interface in Fetch
We were only de-referencing pointers, but we can have pointer of
interface or interface obfuscating pointers...
So before trying to fetch anything, just deference fully the
variable.