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

Codegen plugins #51

Open
playXE opened this issue Jun 24, 2021 · 0 comments
Open

Codegen plugins #51

playXE opened this issue Jun 24, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@playXE
Copy link
Collaborator

playXE commented Jun 24, 2021

When I was implementing self-hosted builtins I added special functions prefixed with ___ that did emit raw bytecode instead of real calls to JS functions. This functionality is conditionally enabled when evaluating self-hosted builtins right now. And now I have great idea that will work like Rust's procedural macros but instead it will generate raw bytecode rather than new SWC AST. For example we could provide API like this:

runtime.register_codegen_plugin("MyOwnAddFn",  |compiler,this,call_args| 
{
   compiler.emit(call_args[0]);
   compiler.emit(call_args[1]);
   compiler.emit(OP_ADD);
});

runtime.eval("MyOwnAddFn(2,3)"); // => 5 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant