191 Commits
Author SHA1 Message Date
Diego Augusto MolinaandGitHub a23efbf4d0 fix VM not clearing memory references when reused (#813) 2025-07-05 13:46:48 +02:00
125b43e22f Fix runtime error not allowing to slice unaddressable array type (#803)
* 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]>
2025-06-30 20:21:25 +02:00
13992b0526 Ignoring fields with struct tag expr:"-" and make "in" return false for unexported fields (#806)
* 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]>
2025-06-30 20:14:08 +02:00
Diego Augusto MolinaandGitHub fefc347053 Improve parser and lexer (#811)
* 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
2025-06-30 20:08:46 +02:00
Anton MedvedevandGitHub 037ef3dc3d Add expr.MaxNodes() option (#799)
* Add expr.MaxNodes() option

* Fix error message

* Add more tests and comments
2025-06-03 17:31:46 +02:00
Anton Medvedev 31f0ab00dc Remove duplicated dereferences 2025-03-10 13:52:54 +01:00
Anton Medvedev 3d52b8e334 Fix func calls with nil types value
Fixes #688
2025-03-08 13:54:55 +01:00
Anton Medvedev 641966584f Make TestVM_ProfileOperations more robust 2025-03-08 13:49:10 +01:00
Anton Medvedev e30c388fdf Add +build comments 2025-03-07 16:44:11 +01:00
Anton Medvedev b42839dddb Remove additional run API (RunWithConfig) from VM
This API was introduced in previous PR, but we do not want to expose it.
2025-03-07 15:06:45 +01:00
9dd86858e1 feat: add node budget and memory limits (#762)
* 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]>
2025-03-07 14:09:41 +01:00
Ville VesilehtoandGitHub ac2e66320d test: add comprehensive VM opcode tests (#750)
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]>
2025-01-27 11:26:26 +01:00
Anton MedvedevandGitHub 19b2c3848f Add checks for nil before string casts in VM (#654) 2024-05-17 19:40:20 +02:00
Anton MedvedevandGitHub 696844a709 Refactor lexer (#653) 2024-05-17 18:10:26 +02:00
Anton Medvedev 71e349971e Add better error messages for index out of bounds errors 2024-05-12 11:55:15 +02:00
Anton MedvedevandGitHub 68e3148c1f Vendor testify (#642) 2024-05-08 00:24:35 +02:00
Anton Medvedev 3dc373ec9a Add spans 2024-04-13 10:08:10 +02:00
bizy db5a6defcb Add bench and tests for runtime.Equal 2024-03-05 01:31:07 +07:00
bizy 5bb64800db Compare any arrays 2024-02-28 00:30:33 +07:00
Anton Medvedev 14d3c281b2 Remove redundant checks 2024-02-21 00:07:51 +01:00
Anton Medvedev 2af0e981b2 Add more func_types 2024-02-16 23:40:23 +01:00
Anton Medvedev 8cd9257996 Sort func_types 2024-02-16 23:32:07 +01:00
Anton MedvedevandGitHub 0d43107999 Add concat() builtin (#565)
* 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
2024-02-16 22:32:35 +01:00
Anton MedvedevandGitHub b1e82de54a Refactor groupBy and sortBy (#562)
* Rearrange opcodes

* Refactor groupBy

* Fix tests

* Super opcodes for GroupBy

* Refactor sortBy builtin

* Fix sortBy bench
2024-02-15 19:53:35 +01:00
Anton Medvedev fdae534aa9 Add OpCallSafe 2024-02-12 22:15:17 +01:00
Anton Medvedev 8073b4bdb7 Add program.Locations() 2024-02-11 22:58:31 +01:00
Anton MedvedevandGitHub 84f18d7e5d Add ast tree to program (#528)
* Add pro holder

* explain
2024-01-17 20:01:34 +01:00
Anton MedvedevandGitHub 010c934215 Fix race cond in variabels (#523)
* Add race cond test

* Move variables array to vm

* Resize vars array for different programs
2024-01-13 20:41:14 +01:00
Anton MedvedevandGitHub 74e30b9ecd Add build tag: expr_debug (#521) 2024-01-13 13:14:38 +01:00
Anton MedvedevandGitHub 79bb049707 Add [generated] tags to files (#518) 2024-01-12 21:58:13 +01:00
Anton MedvedevandGitHub d903980830 Add mem grow to builtin (#505)
* Add mem grow to builtin

* Add OpValidateArgs opcode
2023-12-30 12:49:43 +01:00
Anton MedvedevandGitHub 30be4c9f08 Remove redundant fields from CallNode and BinaryNode (#504) 2023-12-29 19:50:08 +01:00
a0db9a6c19 feat: Implement Bitwise and Shift Operator Support (#496)
Co-authored-by: Ganesan Karuppasamy <[email protected]>
2023-12-25 18:25:26 +01:00
100vlxandGitHub 005b78f0ab Get source from *vm.Program (#491) 2023-12-06 11:02:19 +01:00
Anton Medvedev 551d2a7e0f Use expr-lang/expr 2023-12-03 21:53:01 +01:00
Anton Medvedev 8048a93b2d Add ast comments
Rename program.Opcodes() to program.DisassembleWriter()
2023-11-27 19:15:20 +01:00
Anton Medvedev 2cf93593f4 Hide fields in vm.Program 2023-11-27 13:52:56 +01:00
Augustin PeyrardandGitHub fe7f698b81 Fix Fetch and OpDeref (#467)
* 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.
2023-11-16 12:40:28 +01:00
Anton Medvedev 63496e6fe7 Add type checks for 42 in ["a"] as invalid 2023-09-20 14:00:15 +02:00
Anton Medvedev 4daca7fa08 Update vm.go 2023-09-06 09:42:58 +02:00
Anton Medvedev 3d460e5519 Fix negative ranges memory budget 2023-09-03 11:25:31 +02:00
Anton Medvedev 05d700f4ea Change memoryBudget type to uint
Fixes #427
2023-09-03 11:13:50 +02:00
Anton Medvedev 92dc6c69f6 Fix duration multiplication by integer 2023-08-30 17:45:26 +02:00
Anton Medvedev 76958b5d3f Fix date manipulation operations 2023-08-30 15:23:33 +02:00
Anton Medvedev 6d8d2390cf Remove countBy 2023-08-30 14:55:05 +02:00
Anton Medvedev 5023b3005d Add reduce() 2023-08-30 13:33:16 +02:00
Anton Medvedev 7f85c0551f Add countBy() 2023-08-30 12:07:16 +02:00
Anton Medvedev 32f5fde2eb Replace interface{} with any 2023-08-30 11:25:15 +02:00
Anton Medvedev 3f57b885d4 Add groupBy 2023-08-30 11:14:54 +02:00
Anton Medvedev 9a9cab2e4a Add sort builtin 2023-08-28 14:55:44 +02:00