virtual machine – Can the JVM return the content of the context in bytecode?

I am experimenting with NodeJs VM and javascript.

My goal is to reproduce the way Ethereum run smart contract in the EVM.
This is purely educative and experimental.

I am able to compile some javascript into bytecode and run it in a context. I am only testing so I created 3 javascripts.

  1. First script contains my variables declaration and functions.
  2. A setter function that set the value of a variable from step 1 code.
  3. A getter function that return the value of that variable.

These 3 scripts are compiled and run independently in the VM. Now I would like to know how I can retrieve
the bytecode from my VM context that will hold the name.

I want to be able to update the bytecode in step 1 with the variable that was set in step 2.
So next time I run the bytecode it still know about that variable value.

Just like when you call a smart contract to execute some functions. Once you are done, the state get updated.

So after my second step. The state is updated in that VM instance. How can I extract that bytecode out of there and use it as my next reference with the the variable value still present?