Permalink
Browse files

add in the prototype embedding API functions I've been playing with

  • Loading branch information...
Whiteknight committed Nov 9, 2010
1 parent 0671540 commit 687438efef1da4c0974ab7bea9dd65f3b2301d92
Showing with 104 additions and 0 deletions.
  1. +104 −0 src/embed_api.c
View
@@ -0,0 +1,104 @@
+#include "parrot/parrot.h"
+#include "parrot/api.h"
+
+#define GET_RAW_INTERP(p) ((Parrot_ParrotInterpreter_attributes)(p)->data)->interp;
+#define EMBED_API_CALLIN(p, i) \
+ jmp_buf _env; \
+ Interp * (i) = PMC_IS_NULL(p) ? NULL : GET_RAW_INTERP(p); \
+ if (!(i)) \
+ return 0; \
+ if (setjmp(_env)) { \
+ (i)->api_jmp_buf = NULL; \
+ return 0; \
+ } else { \
+ (i)->api_jmp_buf = _env;
+#define EMBED_API_CALLOUT(p, i) \
+ return 1; \
+ }
+
+PARROT_API
+PARROT_CANNOT_RETURN_NULL
+PARROT_MALLOC
+Parrot_Interp
+Parrot_api_make_interpreter(ARGIN_NULLOK(PMC *parent), INTVAL flags)
+{
+ ASSERT_ARGS(Parrot_api_make_interpreter)
+ Parrot_set_config_hash();
+ Interp * const parent_raw = PMC_IS_NULL(parent) ? NULL : GET_RAW_INTERP(parent);
+ Interp * const interp = allocate_interpreter(parent, flags);
+ return interp;
+}
+
+PARROT_API
+INTVAL
+Parrot_api_initialize_interpreter(ARGIN(PMC *interp_pmc))
+{
+ ASSERT_ARGS(Parrot_api_initialize_interpreter)
+ int stacktop;
+ if (PMC_IS_NULL(interp_pmc)
+ return;
+ Interp * const interp = GET_RAW_INTERP(interp_pmc);
+ initialize_interpreter(interp, (void*)&stacktop);
+}
+
+PARROT_API
+INTVAL
+Parrot_api_set_runcore(ARGIN(PMC *interp_pmc), Parrot_Run_core_t core, Parrot_Uint trace)
+{
+ ASSERT_ARGS(Parrot_api_set_runcore)
+ if (trace)
+ core = PARROT_SLOW_CORE;
+ EMBED_API_CALLIN(interp_pmc, interp)
+ Parrot_set_trace(interp, (Parrot_trace_flags)trace);
+ Parrot_set_run_core(interp, core);
+ EMBED_API_CALLOUT(interp_pmc, interp)
+}
+
+PARROT_API
+INTVAL
+Parrot_api_set_executable_name(ARGIN(PMC *interp_pmc), ARGIN(Parrot_String) name)
+{
+ ASSERT_ARGS(Parrot_api_set_executable_name)
+ EMBED_API_CALLIN(interp_pmc, interp)
+ PMC * const name_pmc = Parrot_pmc_new(interp, enum_class_String);
+ VTABLE_set_string_native(interp, name_pmc, name);
+ VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
+ name_pmc);
+ EMBED_API_CALLOUT(interp_pmc, interp)
+}
+
+PARROT_API
+void
+Parrot_api_destroy_interpreter(ARGIN(PMC *interp_pmc))
+{
+ ASSERT_ARGS(Parrot_api_destroy_interpreter)
+ Interp * const interp = GET_RAW_PMC(interp_pmc);
+ Parrot_destroy(interp);
+}
+
+/*
+
+=item C<int Parrot_api_load_bytecode_file(PARROT_INTERP, const char *filename)>
+
+Load a bytecode file into the interpreter by name. Returns C<0> on failure,
+Success otherwise. Writes error information to the interpreter's error file
+stream.
+
+=cut
+
+*/
+
+PARROT_API
+INTVAL
+Parrot_api_load_bytecode_file(ARGMOD(PMC *interp_pmc), ARGIN(const char *filename), ARGOUT(INTVAL *result))
+{
+ ASSERT_ARGS(Parrot_api_load_bytecode_file)
+ EMBED_API_CALLIN(interp_pmc, interp);
+ *result = 0;
+ PackFile * const pf = Parrot_pbc_read(interp, filename, 0);
+ if (!pf)
+ return 1;
+ Parrot_pbc_load(interp, pf);
+ *result = 1;
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}

0 comments on commit 687438e

Please sign in to comment.