195 Commits
Author SHA1 Message Date
Diego Augusto MolinaandGitHub 6b6df6494c make ast.Node return *nature.Nature (#849) 2025-09-29 11:10:45 +02:00
93c6e39251 Fix #844 alternative 2: do not allow access to unexported struct fields (#846)
* add regression test

* fix #844: disallow direct access to unexported struct fields

---------

Co-authored-by: Anton Medvedev <[email protected]>
2025-09-21 20:58:24 +02:00
Diego Augusto MolinaandGitHub faf4cc4359 Issue 840: Fix get field pointer struct (#843)
* improve issue test

* fix #840: pointer to struct env not returning fields
2025-09-21 20:42:57 +02:00
a60d994e25 Improve Performance of the Type System (#824)
* export the checker and ensure no methods or fields are exported

* make Checker reusable

* add PatchAndCheck method to Checker, and reuse it in visitors

* avoid unnecessary map and consolidate structs

* make all Nature methods use pointer-receiver

* added cache for type and nature information

* optimize type and nature checks

* more aggressively cache some partial results and add cheap checks

* cache reused values

* reduce copying in Nature by breaking down optional fields

* enforce use of cache

* improve ergonomics of FromType and NatureOf

* improve struct method fetching

* make cache private to Nature

* first iteration improving struct reflect caching

* cleaned up struct fields data

* improve caching of functions data

* simplify checker code

* simplify and remove dead code

* add checker benchmarks

* address PR comments and minor improvements

* rename from SetCache to Bind

* make the benchmarks more fair

* fix benchmark option not being applied

* move Cache to be argument instead of field

* merge FuncData into Optional

* rename Optional to TypeData

* simplify struct logic

* cache builtin numeric types

---------

Co-authored-by: Anton Medvedev <[email protected]>
2025-09-18 14:38:27 +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
483e066175 Add check for non struct types to fetchField (#794)
Co-authored-by: yigitkanbalci <[email protected]>
2025-05-27 12:13:35 +02:00
Anton Medvedev e0c6fdc9b9 Code style: remove repeated helper functions 2025-03-15 16:41:40 +01:00
Anton Medvedev 6022ffd21d Add support deref in all builtins 2025-03-10 13:38:02 +01:00
Anton Medvedev 82ec7571df Correctly add OpDeref if needed
Fixes #739
2025-03-09 13:07:38 +01:00
Anton Medvedev 6c8437454d Update fuzz tests 2025-03-08 16:19:30 +01:00
Anton Medvedev 8cab964afb Improve type checker for named types 2025-03-08 15:33:37 +01:00
Anton Medvedev 3a6c36ef12 Add SequenceNode to type checker 2025-03-08 12:36:18 +01:00
Anton Medvedev 02dc5c04fc Properly check if interface is any
Fixes #744
2025-03-07 22:56:41 +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 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
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 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
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 cea9c8ae86 Add int overflow checks 2024-05-09 17:22:41 +02:00
Anton MedvedevandGitHub 68e3148c1f Vendor testify (#642) 2024-05-08 00:24:35 +02:00
Anton Medvedev c5dfe3a811 Make count() predicate optional 2024-04-13 23:38:35 +02:00
Anton MedvedevandGitHub 772eaba1ca Add predicate to sum() builtin (#592)
* Add predicate to sum() builtin

* go mod tidy
2024-04-13 15:37:02 +02:00
SergeyandGitHub 377d126756 expr.Operator passes before expr.Env caused error (#606) 2024-03-17 08:51:53 +01:00
Anton Medvedev 6f8353d205 Remove redundant operator override check 2024-02-17 19:20:53 +01:00
Nikolay MatrosovandGitHub 0ebf2c2574 feat: Operator overload from Function (#408)
* feat: rewritten Operator overload from Function

* fix: add test
2024-02-17 14:33:07 +01:00
Anton Medvedev 129e6b3669 Fix tests 2024-02-17 11:15:54 +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 c2a9f54569 Fix type checker to visit all arguments of func even in args count mismatch 2024-01-18 07:52:06 +01:00
Ganesan KaruppasamyandGitHub 9b73bb722e Remove parents field for optimization (#527) 2024-01-16 12:47:46 +01:00
Anton Medvedev 2e71b2fb71 Fix type any type propagation with patcher relationship 2024-01-16 10:27:10 +01:00
Anton MedvedevandGitHub 6c60616e35 Fix context patcher (#526) 2024-01-14 17:27:22 +01:00
Anton MedvedevandGitHub e7b1a64b58 Allow to override builtins (#522)
* Allow to override builtins

* Add :: syntax to access builtin in case of override
2024-01-13 15:56:49 +01:00
Anton Medvedev 1dca2cbdc2 Move ast.Function to builtin.Function 2023-12-29 21:04:25 +01:00
Anton MedvedevandGitHub 30be4c9f08 Remove redundant fields from CallNode and BinaryNode (#504) 2023-12-29 19:50:08 +01:00
Anton MedvedevandGitHub 8e2df3e45e Simplify ast nodes (#503)
* Move FiendIndex and MethodIndex out of ast nodes

* Remove println statement

* Add method compiler tests
2023-12-26 23:14:20 +01:00
Sergey GrebenshchikovandGitHub 9278f46c55 remove unnecessary loop (#501) 2023-12-22 10:14:08 +01:00
Sergey GrebenshchikovandGitHub 3426d4bcce Fix: checker panic on embedded pointer to struct field (#500)
* add failing test case: embedded pointer to struct

* fix(dereference embedded pointers to structs)

* add evaluation test for field access and method call on embedded pointer struct
2023-12-18 21:46:31 +01:00
Anton Medvedev dd73db72ed checker: forbid accessing custom functions from $env 2023-12-10 10:44:43 +01:00
Anton Medvedev 551d2a7e0f Use expr-lang/expr 2023-12-03 21:53:01 +01:00
Anton Medvedev 885c769c65 Fix type checker for float arguments
Fixes #474
2023-11-24 16:50:09 +01:00
Anton Medvedev 6d9b8d819f Improve type checking for $env
Fixes #462
2023-11-16 22:12:50 +01:00
Anton Medvedev c364bcffa0 Fix checker panic
Fixes #453
2023-11-16 15:49:53 +01:00
Anton Medvedev 3274bda123 Do not copy node type in ast.Patch
Fixes #468
2023-11-16 15:41:43 +01:00
Anton Medvedev 63496e6fe7 Add type checks for 42 in ["a"] as invalid 2023-09-20 14:00:15 +02:00