| parrotcode: Parrot embedding system | |
| Contents | Documentation |

embed.pod - Parrot embedding system

#include "parrot/embed.h"
int main(int argc, char *argv[]) {
Parrot_Interp interp;
Parrot_PackFile pf;
char *bcfile="program.pbc";
argc--; argv++; /* skip the program name */
interp=Parrot_new(0);
Parrot_init(interp);
if(PARROT_JIT_CAPABLE) {
Parrot_set_run_core(interp, PARROT_JIT_CORE); /* activate JIT */
}
pf=Parrot_readbc(interp, bcfile);
Parrot_loadbc(interp, pf);
Parrot_runcode(interp, argc, argv); /* argc and argv as seen by the bytecode file */
Parrot_destroy(interp);
return 0;
}


Parrot's embedding system is designed with one guiding principle in mind: encapsulation. Users of Parrot shouldn't have to know what the insides of a Parrot_Interp structure look like or how to load a packfile. They should just know a few functions and constants. The embedding system is designed to do just that.

Parrot_InterpParrot_PackFileParrot_Interp_flagParrot_Interp_flag_valNULL.Parrot_IntParrot_UIntParrot_FloatParrot_Opcode
interpreter core setting is done by a call of Parrot_set_run_core() like:
Parrot_set_run_core(interp, PARROT_JIT_CORE);
See /include/parrot/interpreter.h for a list of available cores beside PARROT_PREDEREF_CORE, PARROT_JIT_CORE.
PARROT_PREDEREF_COREPARROT_JIT_COREInterpreter flags setting is done by a call of Parrot_set_flag() like>:
Parrot_set_flag(interp, PARROT_TRACE_FLAG, NULL);
See /include/parrot/interpreter.h for an up to date list.
PARROT_DEBUG_FLAGPARROT_TRACE_FLAGPARROT_BOUNDS_FLAGPARROT_PROFILE_FLAGPARROT_THR_TYPE_1, PARROT_THR_TYPE_2, PARROT_THR_TYPE_3PARROT_THR_TYPE_1, threads runs without sharing variables and do not communicate, With PARROT_THR_TYPE_2, threads shares no variables and communicate by sending messages. With PARROT_THR_TYPE_3, threads share variables. See t/pmc/threads.t for examples.Other constants:
PARROT_VERSIONPARROT_MAJOR_VERSIONPARROT_MINOR_VERSIONPARROT_PATCH_VERSIONPARROT_CONFIG_DATEPARROT_JIT_CAPABLEPARROT_ARCHNAMEPARROT_CPU_ARCHPARROT_OS_NAME
Parrot_Interp Parrot_new(Parrot_Interp parent)parent is NULL for the main interpreter that will be destroyed last.void Parrot_init(Parrot_Interp)void Parrot_setflag(Parrot_Interp, Parrot_Interp_flag, Parrot_Interp_flag_val)Parrot_PackFile Parrot_readbc(Parrot_Interp, char *filename)void Parrot_loadbc(Parrot_Interp, Parrot_PackFile)void Parrot_runcode(Parrot_Interp, int argc, char *argv[])argc and argv are the parameters the bytecode should receive.Parrot_destroy(Parrot_Interp)
embed.c and embed.h for the implementation.
src/test_main.c for Parrot's use of the embedding system.
|
|
|