Skip to content
This repository
Newer
Older
100644 127 lines (115 sloc) 3.804 kb
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
1 #include "parrot/parrot.h"
2 #include "parrot/api.h"
3
4 #define GET_RAW_INTERP(p) ((Parrot_ParrotInterpreter_attributes)(p)->data)->interp;
5 #define EMBED_API_CALLIN(p, i) \
6 jmp_buf _env; \
7 Interp * (i) = PMC_IS_NULL(p) ? NULL : GET_RAW_INTERP(p); \
d67e5d41 » Whiteknight
2010-11-09 borrow some code from the old PARROT_CALLIN_START macro set, and ensu…
8 void *_oldtop = (i)->lo_var_ptr; \
9 if (_oldtop) {} else (1)->lo_var_ptr = &oldtop \
9afb8d61 » Whiteknight
2010-11-09 rearrange some bad code to be slightly less bad
10 PARROT_ASSERT(i); \
11 PARROT_ASSERT((i)->lo_val_ptr); \
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
12 if (setjmp(_env)) { \
13 (i)->api_jmp_buf = NULL; \
14 return 0; \
15 } else { \
8499c816 » Whiteknight
2010-11-09 add some brackets in my macros to make things a little safer
16 (i)->api_jmp_buf = _env; \
17 {
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
18 #define EMBED_API_CALLOUT(p, i) \
8499c816 » Whiteknight
2010-11-09 add some brackets in my macros to make things a little safer
19 } \
100d17b7 » Whiteknight
2010-11-09 remove some unnecessary lines
20 if (!_oldtop) {\
21 PARROT_ASSERT((i)->lo_var_ptr == &oldtop);\
22 (i)->lo_var_ptr = NULL;\
23 }\
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
24 return 1; \
25 }
26
27 PARROT_API
28 PARROT_CANNOT_RETURN_NULL
29 PARROT_MALLOC
30 INTVAL
f2252b40 » Whiteknight
2010-11-09 remove the two-stage initialization dance. We can now initialize an i…
31 Parrot_api_make_interpreter(ARGIN_NULLOK(PMC *parent), INTVAL flags, ARGIN_NULLOK(Parrot_Init_Args *args), ARGOUT(PMC **interp))
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
32 {
f2252b40 » Whiteknight
2010-11-09 remove the two-stage initialization dance. We can now initialize an i…
33 ASSERT_ARGS(Parrot_api_make_interpreter)
4a128d50 » Whiteknight
2010-11-09 lots of little changes
34 int alt_stacktop;
f2252b40 » Whiteknight
2010-11-09 remove the two-stage initialization dance. We can now initialize an i…
35 void *stacktop_ptr = &alt_stacktop;
36 Parrot_set_config_hash();
37 {
38 Parrot_Interp * const parent_raw = PMC_IS_NULL(parent) ? NULL : GET_RAW_INTERP(parent);
39 Parrot_Interp * const interp_raw = allocate_interpreter(parent_raw, flags);
40 if (args) {
41 if (args->stack_top)
42 stacktop_ptr = args->stacktop;
43 if (args->gc_system)
44 interp->gc_sys->sys_type = args->gc_system;
45 if (args->gc_threshold)
46 interp->gc_threshold = args->gc_threshold;
47 if (args->hash_seed)
48 interp->hash_seed = args->hash_seed;
49 }
50 }
51 initialize_interpreter(interp_raw, stacktop);
4a128d50 » Whiteknight
2010-11-09 lots of little changes
52 *interp_pmc = VTABLE_get_pmc_keyed_int(interp, iglobals, (INTVAL)IGLOBALS_INTERPRETER);
f2252b40 » Whiteknight
2010-11-09 remove the two-stage initialization dance. We can now initialize an i…
53 return !PMC_IS_NULL(*interp);
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
54 }
55
56 PARROT_API
57 INTVAL
58 Parrot_api_set_runcore(ARGIN(PMC *interp_pmc), Parrot_Run_core_t core, Parrot_Uint trace)
59 {
60 ASSERT_ARGS(Parrot_api_set_runcore)
61 if (trace)
62 core = PARROT_SLOW_CORE;
63 EMBED_API_CALLIN(interp_pmc, interp)
64 Parrot_set_trace(interp, (Parrot_trace_flags)trace);
65 Parrot_set_run_core(interp, core);
66 EMBED_API_CALLOUT(interp_pmc, interp)
67 }
68
69 PARROT_API
70 INTVAL
71 Parrot_api_set_executable_name(ARGIN(PMC *interp_pmc), ARGIN(Parrot_String) name)
72 {
73 ASSERT_ARGS(Parrot_api_set_executable_name)
4a128d50 » Whiteknight
2010-11-09 lots of little changes
74 EMBED_API_CALLIN(interp_pmc, interp);
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
75 PMC * const name_pmc = Parrot_pmc_new(interp, enum_class_String);
76 VTABLE_set_string_native(interp, name_pmc, name);
77 VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
78 name_pmc);
4a128d50 » Whiteknight
2010-11-09 lots of little changes
79 EMBED_API_CALLOUT(interp_pmc, interp);
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
80 }
81
82 PARROT_API
83 void
84 Parrot_api_destroy_interpreter(ARGIN(PMC *interp_pmc))
85 {
86 ASSERT_ARGS(Parrot_api_destroy_interpreter)
4a128d50 » Whiteknight
2010-11-09 lots of little changes
87 EMBED_API_CALLIN(interp_pmc, interp);
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
88 Parrot_destroy(interp);
4a128d50 » Whiteknight
2010-11-09 lots of little changes
89 EMBED_API_CALLOUT(interp_pmc, interp);
90 }
91
92 PARROT_API
93 void
94 Parrot_api_exit_interpreter(ARGIN(PMC *interp_pmc))
95 {
96 ASSERT_ARGS(Parrot_api_exit_interpreter)
97 EMBED_API_CALLIN(interp_pmc, interp);
98 Parrot_exit(interp);
99 EMBED_API_CALLOUT(interp_pmc, interp);
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
100 }
101
102 /*
103
104 =item C<int Parrot_api_load_bytecode_file(PARROT_INTERP, const char *filename)>
105
106 Load a bytecode file into the interpreter by name. Returns C<0> on failure,
107 Success otherwise. Writes error information to the interpreter's error file
108 stream.
109
110 =cut
111
112 */
113
114 PARROT_API
115 INTVAL
4a128d50 » Whiteknight
2010-11-09 lots of little changes
116 Parrot_api_load_bytecode_file(ARGMOD(PMC *interp_pmc), ARGIN(const char *filename), ARGOUT(PMC *)
687438ef » Whiteknight
2010-11-08 add in the prototype embedding API functions I've been playing with
117 {
118 ASSERT_ARGS(Parrot_api_load_bytecode_file)
119 EMBED_API_CALLIN(interp_pmc, interp);
120 *result = 0;
121 PackFile * const pf = Parrot_pbc_read(interp, filename, 0);
122 if (!pf)
123 return 1;
124 Parrot_pbc_load(interp, pf);
125 *result = 1;
126 EMBED_API_CALLOUT(interp_pmc, interp);
127 }
4a128d50 » Whiteknight
2010-11-09 lots of little changes
128
Something went wrong with that request. Please try again.