Commit Graph
897 Commits
Author SHA1 Message Date
Anton Medvedev e30c388fdf Add +build comments 2025-03-07 16:44:11 +01:00
45bc3f7595 refactor(conf): avoid type assertion in map case branch (#749)
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]>
2025-03-07 16:42:00 +01:00
f1b80c01df Fix print with precedence (#678)
* 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]>
2025-03-07 16:34:41 +01:00
Anton Medvedev e2f8470bd7 Add coverage.mjs comments 2025-03-07 16:24:24 +01:00
Anton Medvedev 13e0e4ac34 Exclude pro from go coverage.mjs 2025-03-07 15:56:31 +01:00
f99e1bad97 Separate patching phases for patchers that require multiple passes. (#659)
* 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]>
2025-03-07 15:27:19 +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
96320d0603 ci: add Go 1.23/1.24 testing and fix example test names (#760)
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]>
2025-03-02 09:31:59 +01:00
Ville VesilehtoandGitHub b7e7d82692 ci: pin benchstat version and update GitHub Actions (#761)
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]>
2025-03-01 22:11:57 +01:00
Anton MedvedevandGitHub 99fbd75b7f Update .gitattributes
Signed-off-by: Anton Medvedev <[email protected]>
2025-03-01 20:10:40 +01:00
Anton MedvedevandGitHub ee89ab1a10 Update .gitattributes
Signed-off-by: Anton Medvedev <[email protected]>
2025-03-01 20:05:51 +01:00
Anton MedvedevandGitHub 5a5235df33 Update .gitattributes (#759)
Signed-off-by: Anton Medvedev <[email protected]>
2025-03-01 20:05:02 +01:00
Anton MedvedevandGitHub 71dbecdc04 Update .gitattributes
Signed-off-by: Anton Medvedev <[email protected]>
2025-03-01 20:03:45 +01:00
Anton MedvedevandGitHub 31c8d9d758 Update .gitattributes
Signed-off-by: Anton Medvedev <[email protected]>
2025-03-01 20:03:27 +01:00
Anton MedvedevandGitHub b981138181 Create .gitattributes
Signed-off-by: Anton Medvedev <[email protected]>
2025-03-01 20:00:54 +01:00
5000e417f5 Add if-else conditional (#736)
Co-authored-by: Anton Medvedev <[email protected]>
2025-02-23 14:19:51 +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
Jens NeuseandGitHub 74190e1e81 add WunderGraph Cosmo to uses section in README (#748)
Signed-off-by: Jens Neuse <[email protected]>
2025-01-10 11:41:46 +01:00
Nathan BaulchandGitHub 0dd69ea8ca Fix typos (#745) 2025-01-09 13:33:28 +01:00
Nguyen Ngoc PhuongandGitHub 594f8dd300 Add FastSchema to Readme (#737) 2024-12-23 23:08:32 +01:00
6543andGitHub 95b05178bf Mention WoodpeckerCI in README (#728)
[WoodpeckerCI](https://woodpecker-ci.org) uses this lib, so mention it :)

Signed-off-by: 6543 <[email protected]>
2024-11-13 07:02:42 +01:00
Steve CosmanandGitHub 7f56d8aadf Add CM to Readme (#712)
Signed-off-by: Steve Cosman <[email protected]>
2024-09-18 12:22:56 +02:00
OlgaNovgandGitHub a99736f447 Add uniq() function (#705) 2024-09-04 16:59:48 +02:00
Anton Medvedev 49cbda7b8f Add default map value type 2024-08-28 23:00:18 +02:00
Anton Medvedev a8aece8708 Drop types.StrictMap and add types.Extra to define additional keys 2024-08-28 22:47:47 +02:00
OlgaNovgandGitHub 95c433cd06 Add flatten builtin (#684) 2024-07-15 11:19:33 +02:00
Simon WaldherrandGitHub 42eec6f21f Fix typos (#686) 2024-07-14 09:07:58 +02:00
Arik CohenandGitHub dfa34e25bc Add Tork to its list of users (#682)
Signed-off-by: Arik Cohen <[email protected]>
2024-07-04 23:49:14 +02:00
zhuliquanandGitHub b74ed56efa Fix unary node print for conditional expr (#676)
* feat: extract code for compiling equal operator

* fix: fix unary node inside condition node print
2024-06-23 21:20:41 +02:00
Anton Medvedev 0217bda141 Add any type 2024-06-14 09:32:52 +02:00
Anton Medvedev b24b1448ed Add types.Equal 2024-06-14 09:23:26 +02:00
Anton Medvedev d2777e110d Add types.Array() 2024-06-05 15:48:40 +02:00
Anton MedvedevandGitHub d0aa2e9136 Improve types pkg (#668) 2024-06-05 01:14:25 +02:00
Anton MedvedevandGitHub c953d0dde1 Refactor types table (#667) 2024-06-04 00:08:01 +02:00
Anton Medvedev de9d6dcf8a Remove Node.Kind() method 2024-06-01 14:57:15 +02:00
Anton MedvedevandGitHub fee5690347 Refactor checker to use Nature (#665)
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".
2024-06-01 00:09:22 +02:00
Anton Medvedev 1960bc8e9d Improve compilation for detached tree parts 2024-05-30 21:45:13 +02:00
Anton Medvedev cd8bf976e1 Fix check.yml 2024-05-27 12:28:18 +02:00
Anton Medvedev 9ea9a6e184 Fix coverage reporting 2024-05-27 12:25:09 +02:00
Anton MedvedevandGitHub 0308dbbbb4 Fix function calls with int64 params (#663)
Fixes #661
2024-05-27 12:05:19 +02:00
e944648160 Add Melrōse to "Who uses Expr?" section
Co-authored-by: Anton Medvedev <[email protected]>
2024-05-24 10:12:54 +02:00
Ganesan KaruppasamyandGitHub b53d7bdcfd Invoke the Deref function as needed for the function arguments. (#651) 2024-05-21 11:10:48 +02:00
Anton Medvedev c8b0171f3a Return tree on parse errors 2024-05-18 23:41:49 +02:00
Anton Medvedev 0d07afb7ae Add checker.ParseCheck func 2024-05-18 23:13:58 +02:00
Anton Medvedev 0a33193f26 Fix build for 386 and add build.yml workflow 2024-05-17 21:40:50 +02: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 Medvedev cea9c8ae86 Add int overflow checks 2024-05-09 17:22:41 +02:00