Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement nqp::captureposprimspec.

  • Loading branch information...
commit b0b360312ec993dfe37ec59608818e87e0ca1a24 1 parent 1e657f9
@jnthn jnthn authored
Showing with 44 additions and 0 deletions.
  1. +44 −0 src/ops/nqp.ops
View
44 src/ops/nqp.ops
@@ -282,6 +282,12 @@ static INTVAL * nqp_nfa_run(PARROT_INTERP, NFABody *nfa, STRING *target, INTVAL
return fates;
}
+/* Constants for values the type field above may have. */
+#define BIND_VAL_INT 1
+#define BIND_VAL_NUM 2
+#define BIND_VAL_STR 3
+#define BIND_VAL_OBJ 4
+
END_OPS_PREAMBLE
/*
@@ -2833,3 +2839,41 @@ inline op nqp_fresh_stub(out PMC, invar PMC) :base_core {
"nqp_fresh_sub can only operate on a Parrot Sub");
}
}
+
+/*
+
+=item captureposprimspec
+
+Takes a CallContext in $2 and an index in $3, and returns the primitive
+type specification for the specified positional argument (is it an object
+or one of the native types).
+
+=cut
+
+*/
+inline op captureposprimspec(out INT, invar PMC, in INT) :base_core {
+ PMC *cc = $2;
+ if (cc->vtable->base_type == enum_class_CallContext) {
+ INTVAL i = $3;
+ struct Pcc_cell * pc_positionals;
+ GETATTR_CallContext_positionals(interp, cc, pc_positionals);
+ switch (pc_positionals[i].type) {
+ case BIND_VAL_INT:
+ $1 = STORAGE_SPEC_BP_INT;
+ break;
+ case BIND_VAL_NUM:
+ $1 = STORAGE_SPEC_BP_NUM;
+ break;
+ case BIND_VAL_STR:
+ $1 = STORAGE_SPEC_BP_STR;
+ break;
+ default:
+ $1 = STORAGE_SPEC_BP_NONE;
+ break;
+ }
+ }
+ else {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "captureposprimspec can only operate on a CallContext");
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.