Skip to content

Commit

Permalink
add MVM_vm_run_bytecode() as alternative to MVM_vm_run_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
cygx committed Aug 17, 2019
1 parent 7d23bd2 commit b26638e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/moar.c
Expand Up @@ -445,6 +445,28 @@ void MVM_vm_run_file(MVMInstance *instance, const char *filename) {
MVM_interp_run(tc, toplevel_initial_invoke, cu->body.main_frame);
}

/* Loads bytecode from memory and runs it. */
void MVM_vm_run_bytecode(MVMInstance *instance, MVMuint8 *bytes, MVMuint32 size) {
/* Map the compilation unit into memory and dissect it. */
MVMThreadContext *tc = instance->main_thread;
MVMCompUnit *cu = MVM_cu_from_bytes(tc, bytes, size);

MVMROOT(tc, cu, {
/* Run deserialization frame, if there is one. Disable specialization
* during this time, so we don't waste time logging one-shot setup
* code. */
if (cu->body.deserialize_frame) {
MVMint8 spesh_enabled_orig = tc->instance->spesh_enabled;
tc->instance->spesh_enabled = 0;
MVM_interp_run(tc, toplevel_initial_invoke, cu->body.deserialize_frame);
tc->instance->spesh_enabled = spesh_enabled_orig;
}
});

/* Run the entry-point frame. */
MVM_interp_run(tc, toplevel_initial_invoke, cu->body.main_frame);
}

/* Loads bytecode from the specified file name and dumps it. */
void MVM_vm_dump_file(MVMInstance *instance, const char *filename) {
/* Map the compilation unit into memory and dissect it. */
Expand Down
1 change: 1 addition & 0 deletions src/moar.h
Expand Up @@ -221,6 +221,7 @@ MVMObject *MVM_backend_config(MVMThreadContext *tc);
/* Top level VM API functions. */
MVM_PUBLIC MVMInstance * MVM_vm_create_instance(void);
MVM_PUBLIC void MVM_vm_run_file(MVMInstance *instance, const char *filename);
MVM_PUBLIC void MVM_vm_run_bytecode(MVMInstance *instance, MVMuint8 *bytes, MVMuint32 size);
MVM_PUBLIC void MVM_vm_dump_file(MVMInstance *instance, const char *filename);
MVM_PUBLIC MVM_NO_RETURN void MVM_vm_exit(MVMInstance *instance) MVM_NO_RETURN_ATTRIBUTE;
MVM_PUBLIC void MVM_vm_destroy_instance(MVMInstance *instance);
Expand Down

0 comments on commit b26638e

Please sign in to comment.