Skip to content

Execute multiple scripts on the same VM? #170

Open
@mdorier

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions