Skip to content

Instantly share code, notes, and snippets.

@ZYROz
Created August 5, 2014 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZYROz/0139e9287165407ed437 to your computer and use it in GitHub Desktop.
Save ZYROz/0139e9287165407ed437 to your computer and use it in GitHub Desktop.
Debug
diff --git a/lib/Parrot/Pmc2c/Method.pm b/lib/Parrot/Pmc2c/Method.pm
index edd5f75..a99a5da 100644
--- a/lib/Parrot/Pmc2c/Method.pm
+++ b/lib/Parrot/Pmc2c/Method.pm
@@ -337,9 +337,10 @@ sub decl {
}
my $interp = $self->interp_unused ? 'SHIM_INTERP' : 'PARROT_INTERP';
my $pmcarg = $self->pmc_unused ? 'SHIM(PMC *_self)' : 'ARGMOD(PMC *_self)';
+ my $static = $pmcname eq 'CallContext' ? "" : "static";
return <<"EOC";
-static $decs $ret${newl}Parrot_${pmcname}_$meth($interp, $pmcarg$args)$semi
+$static $decs $ret${newl}Parrot_${pmcname}_$meth($interp, $pmcarg$args)$semi
EOC
}
diff --git a/lib/Parrot/Pmc2c/PMC.pm b/lib/Parrot/Pmc2c/PMC.pm
index 2f452b9..0a16f55 100644
--- a/lib/Parrot/Pmc2c/PMC.pm
+++ b/lib/Parrot/Pmc2c/PMC.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2004-2013, Parrot Foundation.
+# Copyright (C) 2004-2014, Parrot Foundation.
=head1 NAME
@@ -521,7 +521,7 @@ sub generate_c_file {
$c->emit( $self->preamble );
- $c->emit( $self->hdecls );
+ $c->emit( $self->hdecls ) unless $self->name eq 'CallContext';
$c->emit( $self->{ro}->hdecls ) if ( $self->{ro} );
$self->gen_methods;
@@ -589,6 +589,10 @@ EOH
$self->gen_attributes;
+ if ($name eq 'CallContext') {
+ $h->emit( $self->hdecls );
+ }
+
if ($self->is_dynamic) {
$h->emit(<<"EOH");
@@ -1743,6 +1747,19 @@ sub generate_accessor {
/* Generated macro accessors for '$attrname' attribute of $pmcname PMC. */
#define GETATTR_${pmcname}_${attrname}(interp, pmc, dest) \\
+EOA
+ # Nobody derives from CallContext, the arg is always proper, and we need the speed
+ if ($pmcname eq "CallContext") {
+ $decl .= <<"EOA";
+ (dest) = PARROT_CALLCONTEXT(pmc)->${attrname}
+
+#define SETATTR_${pmcname}_${attrname}(interp, pmc, value) \\
+ PARROT_CALLCONTEXT(pmc)->${attrname} = (value)
+EOA
+ }
+
+ else {
+ $decl .= <<"EOA";
do { \\
if (!PObj_is_object_TEST(pmc)) { \\
(dest) = ((Parrot_${pmcname}_attributes *)PMC_data(pmc))->$attrname; \\
@@ -1750,112 +1767,114 @@ sub generate_accessor {
else { \\
EOA
- if ($isfuncptr == 1) {
- $decl .= <<"EOA";
+ if ($isfuncptr == 1) {
+ $decl .= <<"EOA";
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, \\
"Attributes of type '$origtype' cannot be " \\
"subclassed from a high-level PMC."); \\
EOA
- }
- elsif ($attrtype eq "INTVAL") {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype eq "INTVAL") {
+ $decl .= <<"EOA";
PMC * const attr_value = VTABLE_get_attr_str(interp, \\
pmc, Parrot_str_new_constant(interp, "$attrname")); \\
(dest) = (PMC_IS_NULL(attr_value) ? (INTVAL) 0: VTABLE_get_integer(interp, attr_value)); \\
EOA
- }
- elsif ($attrtype eq "FLOATVAL") {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype eq "FLOATVAL") {
+ $decl .= <<"EOA";
PMC * const attr_value = VTABLE_get_attr_str(interp, \\
pmc, Parrot_str_new_constant(interp, "$attrname")); \\
(dest) = (PMC_IS_NULL(attr_value) ? (FLOATVAL) 0.0: VTABLE_get_number(interp, attr_value)); \\
EOA
- }
- elsif ($attrtype =~ $isptrtostring) {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype =~ $isptrtostring) {
+ $decl .= <<"EOA";
PMC * const attr_value = VTABLE_get_attr_str(interp, \\
pmc, Parrot_str_new_constant(interp, "$attrname")); \\
(dest) = (PMC_IS_NULL(attr_value) ? (STRING *)NULL : VTABLE_get_string(interp, attr_value)); \\
EOA
- }
- elsif ($attrtype =~ $isptrtopmc) {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype =~ $isptrtopmc) {
+ $decl .= <<"EOA";
(dest) = VTABLE_get_attr_str(interp, \\
pmc, Parrot_str_new_constant(interp, "$attrname")); \\
EOA
- }
+ }
- else {
- $inherit = 0;
- $decl .= <<"EOA";
+ else {
+ $inherit = 0;
+ $decl .= <<"EOA";
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, \\
"Attributes of type '$attrtype' cannot be " \\
"subclassed from a high-level PMC."); \\
EOA
- }
+ }
- $decl .= <<"EOA";
+ $decl .= <<"EOA";
} \\
} while (0)
+EOA
+ $decl .= <<"EOA";
#define SETATTR_${pmcname}_${attrname}(interp, pmc, value) \\
do { \\
if (PObj_is_object_TEST(pmc)) { \\
EOA
- if ($isfuncptr == 1) {
- $decl .= <<"EOA";
+ if ($isfuncptr == 1) {
+ $decl .= <<"EOA";
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, \\
"Attributes of type '$origtype' cannot be " \\
"subclassed from a high-level PMC."); \\
EOA
- }
- elsif ($attrtype eq "INTVAL") {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype eq "INTVAL") {
+ $decl .= <<"EOA";
PMC * const attr_value = Parrot_pmc_new_init_int(interp, enum_class_Integer, value); \\
VTABLE_set_attr_str(interp, pmc, \\
Parrot_str_new_constant(interp, "$attrname"), attr_value); \\
EOA
- }
- elsif ($attrtype eq "FLOATVAL") {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype eq "FLOATVAL") {
+ $decl .= <<"EOA";
PMC * const attr_value = Parrot_pmc_new(interp, enum_class_Float); \\
VTABLE_set_number_native(interp, attr_value, value); \\
VTABLE_set_attr_str(interp, pmc, \\
Parrot_str_new_constant(interp, "$attrname"), attr_value); \\
EOA
- }
- elsif ($attrtype =~ $isptrtostring) {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype =~ $isptrtostring) {
+ $decl .= <<"EOA";
PMC * const attr_value = Parrot_pmc_new(interp, enum_class_String); \\
VTABLE_set_string_native(interp, attr_value, value); \\
VTABLE_set_attr_str(interp, pmc, \\
Parrot_str_new_constant(interp, "$attrname"), attr_value); \\
EOA
- }
- elsif ($attrtype =~ $isptrtopmc) {
- $decl .= <<"EOA";
+ }
+ elsif ($attrtype =~ $isptrtopmc) {
+ $decl .= <<"EOA";
VTABLE_set_attr_str(interp, pmc, \\
Parrot_str_new_constant(interp, "$attrname"), value); \\
EOA
- }
+ }
- else {
- $decl .= <<"EOA";
+ else {
+ $decl .= <<"EOA";
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, \\
"Attributes of type '$attrtype' cannot be " \\
"subclassed from a high-level PMC."); \\
EOA
- }
+ }
- $decl .= <<"EOA";
+ $decl .= <<"EOA";
} \\
else \\
((Parrot_${pmcname}_attributes *)PMC_data(pmc))->$attrname = (value); \\
} while (0)
EOA
-
+ }
#my $assertion = ($attrtype =~ $isptrtopmc and not $isfuncptr)
# ? 'PARROT_ASSERT_INTERP((PMC *)(value), interp);'
# : '';
diff --git a/src/call/args.c b/src/call/args.c
index 3fde796..905ed03 100644
--- a/src/call/args.c
+++ b/src/call/args.c
@@ -438,7 +438,7 @@ extract_named_arg_from_op(PARROT_INTERP, ARGMOD(PMC *call_object), ARGIN(STRING
{
ASSERT_ARGS(extract_named_arg_from_op)
PMC * const ctx = CURRENT_CONTEXT(interp);
- const INTVAL arg_flags = VTABLE_get_integer_keyed_int(interp, raw_sig, arg_index);
+ const INTVAL arg_flags = Parrot_CallContext_get_integer_keyed_int(interp, raw_sig, arg_index);
const int constant = 0 != PARROT_ARG_CONSTANT_ISSET(arg_flags);
const INTVAL raw_index = raw_args[arg_index + 2];
@@ -487,11 +487,11 @@ dissect_aggregate_arg(PARROT_INTERP, ARGMOD(PMC *call_object), ARGIN(PMC *aggreg
{
ASSERT_ARGS(dissect_aggregate_arg)
if (VTABLE_does(interp, aggregate, CONST_STRING(interp, "array"))) {
- const INTVAL elements = VTABLE_elements(interp, aggregate);
+ const INTVAL elements = Parrot_CallContext_elements(interp, aggregate);
INTVAL index;
for (index = 0; index < elements; ++index) {
Parrot_CallContext_push_pmc(interp, call_object,
- VTABLE_get_pmc_keyed_int(interp, aggregate, index));
+ Parrot_CallContext_get_pmc_keyed_int(interp, aggregate, index));
}
}
else if (VTABLE_does(interp, aggregate, CONST_STRING(interp, "hash"))) {
@@ -607,22 +607,22 @@ set_call_from_varargs(PARROT_INTERP,
EXCEPTION_INVALID_OPERATION,
"Dispatch: only the first argument can be an invocant");
else {
- VTABLE_push_pmc(interp, signature, pmc_arg);
+ Parrot_CallContext_push_pmc(interp, signature, pmc_arg);
++i; /* skip 'i' */
}
}
else
- VTABLE_push_pmc(interp, signature, pmc_arg);
+ Parrot_CallContext_push_pmc(interp, signature, pmc_arg);
break;
}
case 'S':
- VTABLE_push_string(interp, signature, va_arg(*args, STRING *));
+ Parrot_CallContext_push_string(interp, signature, va_arg(*args, STRING *));
break;
case 'I':
- VTABLE_push_integer(interp, signature, va_arg(*args, INTVAL));
+ Parrot_CallContext_push_integer(interp, signature, va_arg(*args, INTVAL));
break;
case 'N':
- VTABLE_push_float(interp, signature, va_arg(*args, FLOATVAL));
+ Parrot_CallContext_push_float(interp, signature, va_arg(*args, FLOATVAL));
break;
case '-':
return;
@@ -656,7 +656,7 @@ Parrot_pcc_set_call_from_varargs(PARROT_INTERP,
{
ASSERT_ARGS(Parrot_pcc_set_call_from_varargs)
PARROT_ASSERT(PMCNULL != signature);
- VTABLE_morph(interp, signature, PMCNULL);
+ Parrot_CallContext_morph(interp, signature, PMCNULL);
set_call_from_varargs(interp, signature, sig, args);
}
@@ -888,7 +888,7 @@ fill_params(PARROT_INTERP, ARGMOD_NULLOK(PMC *call_object),
num_positionals);
for (j = 0; arg_index < positional_args; ++arg_index)
- VTABLE_set_pmc_keyed_int(interp, collect_positional, j++,
+ Parrot_CallContext_set_pmc_keyed_int(interp, collect_positional, j++,
Parrot_CallContext_get_pmc_keyed_int(interp, call_object, arg_index));
*accessor->pmc(interp, arg_info, param_index) = collect_positional;
@@ -1066,7 +1066,7 @@ fill_params(PARROT_INTERP, ARGMOD_NULLOK(PMC *call_object),
if ((named_used_list == NULL)
|| !Parrot_hash_exists(interp, named_used_list, name)) {
- VTABLE_set_pmc_keyed_str(interp, collect_named, name,
+ Parrot_CallContext_set_pmc_keyed_str(interp, collect_named, name,
Parrot_CallContext_get_pmc_keyed_str(interp, call_object, name));
/* Mark the name as used, cannot be filled again. */
@@ -1495,7 +1495,7 @@ parse_signature_string(PARROT_INTERP, ARGIN(const char *signature),
/* Starting a new argument, so store the previous argument,
* if there was one. */
if (set) {
- VTABLE_set_integer_keyed_int(interp, current_array, count++, flags);
+ Parrot_CallContext_set_integer_keyed_int(interp, current_array, count++, flags);
set = 0;
}
@@ -1534,7 +1534,7 @@ parse_signature_string(PARROT_INTERP, ARGIN(const char *signature),
/* Store the final argument, if there was one. */
if (set)
- VTABLE_set_integer_keyed_int(interp, current_array, count, flags);
+ Parrot_CallContext_set_integer_keyed_int(interp, current_array, count, flags);
}
/*
diff --git a/src/call/pcc.c b/src/call/pcc.c
index 4727034..2ba68f6 100644
--- a/src/call/pcc.c
+++ b/src/call/pcc.c
@@ -164,7 +164,7 @@ Parrot_pcc_add_invocant(PARROT_INTERP, ARGIN(PMC *call_obj), ARGIN(PMC *pmc))
ASSERT_ARGS(Parrot_pcc_add_invocant)
PMC *arg_flags = PARROT_CALLCONTEXT(call_obj)->arg_flags;
VTABLE_unshift_integer(interp, arg_flags, PARROT_ARG_PMC | PARROT_ARG_INVOCANT);
- VTABLE_unshift_pmc(interp, call_obj, pmc);
+ Parrot_CallContext_unshift_pmc(interp, call_obj, pmc);
}
/*
@@ -206,7 +206,7 @@ Parrot_pcc_invoke_method_from_c_args(PARROT_INTERP, ARGIN(PMC* pmc),
/* inlined version of pcc_add_invocant */
arg_flags = PARROT_CALLCONTEXT(call_obj)->arg_flags;
VTABLE_unshift_integer(interp, arg_flags, PARROT_ARG_PMC | PARROT_ARG_INVOCANT);
- VTABLE_unshift_pmc(interp, call_obj, pmc);
+ Parrot_CallContext_unshift_pmc(interp, call_obj, pmc);
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), call_obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment