Skip to content

[FEATURE] Overloading/removing operators, functions in box.compile() #240

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

Open
repalash opened this issue Apr 14, 2025 · 3 comments
Open
Labels
feature New feature or enhancement

Comments

@repalash
Copy link

Is your feature request related to a problem? Please describe.
When using the compile to javascript feature, its not possible to change the operators defined in NATIVE_JS_OPERATORS and functions in NATIVE_JS_FUNCTIONS. This is required to compile to environments where there are no operators like - 2+3*3 -> add(2, multiply(3,3))

Describe the solution you'd like
Add parameters in the options for compile to specify the CompileTarget interface.
This will enable overriding operators and functions.
For functions, its possible to pass them but they are compiled directly to javascript so its not possible to change the behaviour like in CompileTarget

Describe alternatives you've considered
Using the compileTarget directly, but it's not exported. Also since box.compile() is the entry-point, it should be possible to override based on that.

Additional context
Also I wrote a compiler for GLSL, it's in a fork right now since required many changes, but this would make it easy to work on that and maybe get that merged easily.

@repalash repalash added the feature New feature or enhancement label Apr 14, 2025
@arnog
Copy link
Member

arnog commented Apr 14, 2025

I'm not sure I understand the point of this feature request. Is this to compile to targets other than JavaScript?

I'm aware of several implementations that compile to GLSL and Python, which is great, but none of those have been contributed back to the project. As such, I am not very motivated to work on making improvements for individual users who are not contributing to the community.

@repalash
Copy link
Author

This specific request is to allow setting operators for compiling to javascript, which are required for vector operations, since compiling an expression that adds 2 vectors results to [1,1,1]+[1,1,1] which is not valid javascript, so I was thinking of overriding operators to functions so it compiles to add([1,1,1], [1,1,1]) which can be defined for vector, matrix operation.

Other than that, another request was to provide interface to allow compiling to any target where we can pass in the CompileTarget interface which would allow more customization.

For GLSL compile, I worked on it last year, but couldn't get time to finish it with support for all statements, hope to finish it this year and contribute to the project.

Kudos on the project and the cortexjs ecosystem though, great to see it progress so much.

@repalash
Copy link
Author

It's not very big of a requirement, if you feel its not a worthwhile addition to the compile function options, please don't spend time on it and feel free to close the issue. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Development

No branches or pull requests

2 participants