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

Execute multiple scripts on the same VM? #170

Open
mdorier opened this issue Aug 22, 2024 · 0 comments
Open

Execute multiple scripts on the same VM? #170

mdorier opened this issue Aug 22, 2024 · 0 comments

Comments

@mdorier
Copy link
Contributor

mdorier commented Aug 22, 2024

As far as I understand, in Jx9 I cannot execute a second Jx9 script on an existing VM. Yet I have at least two use-cases that would make it useful:

  • Compiling/executing a large script that defines a bunch of functions, followed by compiling/executing much smaller scripts that execute these functions. In this situation the large script could be compiled at start-up and the smaller scripts would be compiled on-demand. Right now the only way to do that is to concatenate the two scripts, and re-compile the first long script every time I get a new small script to execute.
  • Statefull VMs: I know that in the context of unqlite, any state that needs to be persistent across Jx9 executions can be stored in the database, but in the context of just having an embedded Jx9 engine, it would be useful for the VM to keep its state and be able to compile and execute further scripts (think of the implementation of a jx9 REPL, as an example).

A possible API for this would be:

  • jx9_compile_more(jx9_vm* pVm, const char *zSource, int nLen, ): compiles and append additional code and makes the VM ready to execute it (i.e. if the previous code hasn't been executed, jx9_vm_exec will start by executing it, otherwise the next call to jx9_vm_exec will start executing from the new code), without touching any variable/functions/callbacks that have already been defined in the VM.
  • jx9_vm_copy(jx9_vm* pVm, jx9_vm** pNewVm); copies the state of the VM into a new VM.

Note that the same comment applies to PH7.

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

No branches or pull requests

1 participant