NAME ^

src/interpreter.c - Parrot Interpreter

DESCRIPTION ^

The interpreter API handles running the operations.

The predereferenced code chunk is pre-initialized with the opcode function pointers, addresses, or opnumbers of the prederef__ opcode. This opcode then calls the do_prederef() function, which then fills in the real function, address or op number.

Because the prederef__ opcode returns the same pc_prederef it was passed, the runops loop will re-execute the same location, which will then have the pointer to the real prederef opfunc and prederef args.

Pointer arithmetic is used to determine the index into the bytecode corresponding to the currect opcode. The bytecode and prederef arrays have the same number of elements because there is a one-to-one mapping.

Functions ^

static void prederef_args(NOTNULL(void **pc_prederef), PARROT_INTERP, NOTNULL(opcode_t *pc), NOTNULL(const op_info_t *opinfo))

Called from do_prederef() to deal with any arguments.

pc_prederef is the current opcode.

void do_prederef(void **pc_prederef, PARROT_INTERP, int type)

This is called from within the run cores to predereference the current opcode.

pc_prederef is the current opcode, and type is the run core type.

static void turn_ev_check(PARROT_INTERP, int on)

Turn on or off event checking for prederefed cores.

Fills in the event_checker opcode, or restores original ops in all branch locations of the opcode stream.

Note that when on is true, this is being called from the event handler thread.

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static oplib_init_f get_op_lib_init(PARROT_INTERP, int core_op, int which, NULLOK(PMC *lib))

Returns an opcode's library op_lib init function.

core_op indicates whether the opcode represents a core Parrot operation.

which is the run core type.

For dynamic oplibs core_op will be 0 and lib will be a ParrotLibrary PMC.

static void load_prederef(PARROT_INTERP, int which)

interp->op_lib = prederefed oplib.

static void init_prederef(PARROT_INTERP, int which)

Initialize: load prederef func_table, file prederef.code.

static void stop_prederef(PARROT_INTERP)

Restore the interpreter's op function tables to their initial state. Also recreate the event function pointers. This is only necessary for run-core changes, but we don't know the old run core.

void exec_init_prederef(PARROT_INTERP, void *prederef_arena)

interp->op_lib = prederefed oplib

The "normal" op_lib has a copy in the interpreter structure - but get the op_code lookup function from standard core prederef has no op_info_table

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL void *init_jit(PARROT_INTERP, NULLOK(opcode_t *pc))

Initializes JIT function for the specified opcode and returns it.

void prepare_for_run(PARROT_INTERP)

Prepares to run the interpreter's run core.

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static opcode_t *runops_jit(PARROT_INTERP, NOTNULL(opcode_t *pc))

Runs the JIT code for the specified opcode.

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static opcode_t *runops_exec(PARROT_INTERP, NOTNULL(opcode_t *pc))

Runs the native executable version of the specified opcode.

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static opcode_t *runops_cgp(PARROT_INTERP, NOTNULL(opcode_t *pc))

Runs the C goto, predereferenced core.

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static opcode_t *runops_switch(PARROT_INTERP, NOTNULL(opcode_t *pc))

Runs the switch core.

void runops_int(PARROT_INTERP, size_t offset)

Run Parrot operations of loaded code segment until an end opcode is reached. Run core is selected depending on the Interp_flags. When a restart opcode is encountered, a different core may be selected and evaluation of opcode continues.

void Parrot_setup_event_func_ptrs(PARROT_INTERP)

Setup a func_table containing pointers (or addresses) of the check_event__ opcode.

TODO: Free it at destroy. Handle run-core changes.

Dynamic Loading Functions ^

void dynop_register(PARROT_INTERP, PMC *lib_pmc)

Register a dynamic oplib.

static void dynop_register_xx(PARROT_INTERP, size_t n_old, size_t n_new, oplib_init_f init_func)

Register op_lib with other cores.

static void dynop_register_switch(size_t n_old, size_t n_new)

TODO: Not yet documented!!!

static void notify_func_table(PARROT_INTERP, NOTNULL(op_func_t *table), int on)

Tell the interpreter's running core about the new function table.

PARROT_API void disable_event_checking(PARROT_INTERP)

Restore old function table.

XXX This is only implemented for the function core at present.

PARROT_API void enable_event_checking(PARROT_INTERP)

Replace func table with one that does event checking for all opcodes.

NOTE: enable_event_checking() is called async by the event handler thread. All action done from here has to be async safe.

XXX This is only implemented for the function core at present.

SEE ALSO ^

include/parrot/interpreter.h, src/inter_cb.c, src/inter_create.c, src/inter_misc.c, src/inter_run.c.


parrot