Skip to content

Commit

Permalink
Add arnsholt++ nqp::sethllconfig implementation.
Browse files Browse the repository at this point in the history
Also teach it a bunch of extra HLL-interop related keys.
  • Loading branch information
jnthn committed Apr 9, 2013
1 parent 716b35d commit 09d22fc
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/QAST/Operations.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2046,12 +2046,7 @@ QAST::Operations.add_core_op('bindhllsym', -> $qastcomp, $op {
$op[2]
))
});
QAST::Operations.add_core_op('sethllconfig', -> $qastcomp, $op {
# XXX Not really implemented here.
my $ops := PIRT::Ops.new();
$ops.result('0');
$ops
});
QAST::Operations.add_core_pirop_mapping('sethllconfig', 'sethllconfig', 'PsP');

# regex engine related opcodes
QAST::Operations.add_core_pirop_mapping('nfafromstatelist', 'nqp_nfa_from_statelist', 'PPP');
Expand Down
84 changes: 83 additions & 1 deletion src/ops/nqp.ops
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ static INTVAL * nqp_nfa_run(PARROT_INTERP, NFABody *nfa, STRING *target, INTVAL
return fates;
}

static PMC *get_hll_config(PARROT_INTERP, STRING *hll) {
PMC *global_context = VTABLE_get_pmc_keyed_str(interp, interp->root_namespace,
Parrot_str_new_constant(interp, "_GLOBAL_CONTEXT"));
PMC *config = VTABLE_get_pmc_keyed_str(interp,
VTABLE_get_pmc_keyed_str(interp, global_context, Parrot_str_new_constant(interp, "hllConfig")),
hll);

if (PMC_IS_NULL(config)) {
config = Parrot_pmc_new(interp, enum_class_Hash);
/* TODO: Populate with initial values. */

VTABLE_set_pmc_keyed_str(interp,
VTABLE_get_pmc_keyed_str(interp, global_context, Parrot_str_new_constant(interp, "hllConfig")),
hll,
config);
}

return config;
}

/* Constants for values the type field above may have. */
#define BIND_VAL_INT 1
#define BIND_VAL_NUM 2
Expand All @@ -313,7 +333,7 @@ Does various setup tasks for the benefit of the other dynops.
*/
inline op nqp_dynop_setup() :base_core {
if (!initialized) {
PMC *obj_sc_barrier, *st_sc_barrier;
PMC *obj_sc_barrier, *st_sc_barrier, *global_context;

/* Look up and cache some type IDs. */
stable_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "STable", 0));
Expand Down Expand Up @@ -349,6 +369,14 @@ inline op nqp_dynop_setup() :base_core {
empty_hash = Parrot_pmc_new(interp, enum_class_Hash);
Parrot_pmc_gc_register(interp, empty_hash);

/* Save the global context to the Parrot root namespace and store all the
* things we just created in it. */
global_context = Parrot_pmc_new(interp, enum_class_Hash);
VTABLE_set_pmc_keyed_str(interp, interp->root_namespace,
Parrot_str_new_constant(interp, "_GLOBAL_CONTEXT"), global_context);
VTABLE_set_pmc_keyed_str(interp, global_context,
Parrot_str_new_constant(interp, "hllConfig"), Parrot_pmc_new(interp, enum_class_Hash));

/* Mark initialized. */
initialized = 1;
}
Expand Down Expand Up @@ -2956,3 +2984,57 @@ inline op captureposprimspec(out INT, invar PMC, in INT) :base_core {
"captureposprimspec can only operate on a CallContext");
}
}

inline op sethllconfig(out PMC, in STR, invar PMC) {
PMC *config = get_hll_config(interp, $2);

if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "list"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "listType"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "list")));
}

if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_int"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_type_int"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_int")));
}
if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_num"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_type_num"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_num")));
}
if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_str"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_type_str"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_str")));
}
if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_any"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_type_any"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_type_any")));
}

if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_int"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_transform_int"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_int")));
}
if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_num"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_transform_num"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_num")));
}
if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_str"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_transform_str"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_str")));
}
if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_array"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_transform_array"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_array")));
}
if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_hash"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "foreign_transform_hash"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "foreign_transform_hash")));
}

if (VTABLE_exists_keyed_str(interp, $3, Parrot_str_new_constant(interp, "null_value"))) {
VTABLE_set_pmc_keyed_str(interp, config, Parrot_str_new_constant(interp, "null_value"),
VTABLE_get_pmc_keyed_str(interp, $3, Parrot_str_new_constant(interp, "null_value")));
}

$1 = config;
}

0 comments on commit 09d22fc

Please sign in to comment.