Hello,

I enjoy Parrot and tried to write new two opcodes -- suspend and resume.
suspend opcode is to halt interpreter and resume opcode is to restart
interpreter from where it suspended.
Please refer to attached souce and test case.

Thank you for reading.
#include "parrot/dynext.h"
VERSION = PARROT_VERSION;

op suspend() {
  PMC* interp = VTABLE_get_pmc_keyed_int(interpreter, interpreter->iglobals,
        IGLOBALS_INTERPRETER);
  VTABLE_set_pointer(interpreter, interp, CUR_OPCODE + 1);
  HALT();
}

op resume(in PMC) {
  Interp *interp = (Interp *)PMC_data($1);
  opcode_t *dest = VTABLE_get_pointer(interpreter, $1);
  size_t offset = (size_t)(dest - interpreter->code->base.data);
  runops(interp, offset);
  goto NEXT();
}

# vim: expandtab tabstop=2

Reply via email to