Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flecs script expression refactor #1461

Merged
merged 83 commits into from
Dec 15, 2024
Merged

Flecs script expression refactor #1461

merged 83 commits into from
Dec 15, 2024

Conversation

SanderMertens
Copy link
Owner

@SanderMertens SanderMertens commented Dec 7, 2024

This PR reimplements the expression part of Flecs script. The PR:

  • changes the parser from directly executing when parsing the string to generating an AST
  • adds support for user-defined functions and methods
  • adds support for for loops
  • adds support for using interpolated strings in scripts
  • adds support for using strings as entity names (for names with special characters, dynamic names)
  • adds support for global const variables (variables that can be reused across scripts)
  • adds support for calling scripts with a user-defined list of variables
  • adds a FLECS_SCRIPT_MATH addon with math functions (disabled by default)
  • adds more builtin functions (entity.has, pair, doc_uuid, doc_brief, doc_detail, doc_link, doc_color)
  • implements constant folding (resolve expressions at parse time where possible)
  • improves detection and reporting of errors in templates
  • division by zero detection (throws an error and prevents code from crashing)

This PR fixes the following bugs/has the following improvements:

  • observer events can now be infinitely nested without asserting/causing stack overflows
  • fix issue with using ecs_entity_desc_t::set while deferring is suspended
  • fix illegal memory access in ecs_add_path_w_sep
  • fix leaks in builds that define FLECS_USE_OS_ALLOC
  • fix issue where code was accessing world->flags on stage object
  • fix issue in REST API with reporting errors that contain formatting (%) characters
  • fix invalid write in flecs_path_append
  • fix bug in handling of name lookups with multiple consecutive separators
  • fix bug when creating an entity with an id >UINT32_MAX with ecs_entity_init
  • improve cycle detection in observer code (prevents stack overflow, throws assert)
  • fix memory leak in cursor string conversions
  • fix access to uninitialized ecs_cmd_t::id field
  • improves leak detection reports which now include the leaked type in most cases

The PR introduces a number of breaking changes. More details here: #466 (comment)

@SanderMertens SanderMertens force-pushed the expr_parser branch 5 times, most recently from 1c01e96 to eecdb75 Compare December 11, 2024 18:21
- Fix invalid write in flecs_path_append
- Correctly handle name lookups with multiple consecutive separators
- Correctly handle attempts to create entities with ids > UINT32_MAX
- Improve cycle detection in observer code/prevent stack overflows
@SanderMertens SanderMertens force-pushed the expr_parser branch 2 times, most recently from e675782 to 87b636e Compare December 15, 2024 19:30
- String entity names
- String interpolation
- For loops
- Updated section on types
- Added C examples on how to define functions/methods
@SanderMertens SanderMertens force-pushed the expr_parser branch 4 times, most recently from faba5dd to fa8f5bc Compare December 15, 2024 21:47
@SanderMertens SanderMertens merged commit 1f4c816 into master Dec 15, 2024
144 checks passed
@SanderMertens SanderMertens deleted the expr_parser branch December 15, 2024 23:57
pfeodrippe added a commit to pfeodrippe/flecs that referenced this pull request Dec 21, 2024
…rtens#1461 Flecs script expression refactor`

Adding a test only here \o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant