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

Build a program from compiled scripts #173

Open
loonwong opened this issue Jan 22, 2020 · 4 comments
Open

Build a program from compiled scripts #173

loonwong opened this issue Jan 22, 2020 · 4 comments
Labels

Comments

@loonwong
Copy link

Dear sirs,

In my application, JavaScript is divided into modules that link to the final program. Is there any way to build a program from compiled scripts? Otherwise (when changing the code of any of the modules), I have to combine the code of all the modules and recompile it. This procedure is very expensive, maybe there are some workarounds?

Thanks.

@paulbartrum
Copy link
Owner

Maybe I'm missing something, but can't you just run each compiled script against the same ScriptEngine, one after the other? There should be no need to combine scripts.

@loonwong
Copy link
Author

loonwong commented Jan 22, 2020

But the point is that one module can refer to another. Something like this:

Module1.js

function module1_function() {
   // Some code
}

Module2.js

function module2_function() { 

   module1_function(); 
   // Some code

}

Final Program

if (condition)
   module1_function();
else 
   module2_function();

and in this case, if the Module2.js code has changed, in order for these changes to take effect in the final program, I need to combine the code of both modules and the program together and compile it. But instead, it would be good to compile the code, only the modified module, and combine it with existing compiled scripts, if possible.

@paulbartrum
Copy link
Owner

paulbartrum commented Jan 22, 2020

I still don't really understand.

Here's what I'm suggesting:

  1. Create new script engine.
  2. Execute Module1.js against script engine from step 1. Script engine now contains compiled module1_function function.
  3. Execute Module2.js against script engine from step 1. The function module1_function (defined in step 2) is called.

Now you're left with a ScriptEngine with everything that was defined in Module1.js and Module2.js. If Module2.js changes you can create a new script engine and run (previously compiled) Module1 and (newly compiled) Module2 against that new script engine.

@loonwong
Copy link
Author

Yes, this is what I need, thank you very much for the detailed description of the actions. I didn't pay attention to the Execute method of the CompiledScript class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants