Skip to content

Instantly share code, notes, and snippets.

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 rurban/0bd64ed6643ac8851212 to your computer and use it in GitHub Desktop.
Save rurban/0bd64ed6643ac8851212 to your computer and use it in GitHub Desktop.
pcc: optimize return in pmc methods
From af38a34ef19b7ebc912d4d8e688feadb2a82e983 Mon Sep 17 00:00:00 2001
From: Reini Urban <rurban@cpanel.net>
Date: Thu, 19 Jun 2014 08:40:29 -0600
Subject: [PATCH 1/2] optimize return in pmc methods
---
lib/Parrot/Pmc2c/PCCMETHOD.pm | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git lib/Parrot/Pmc2c/PCCMETHOD.pm lib/Parrot/Pmc2c/PCCMETHOD.pm
index e7a0d65..0572ffb 100644
--- lib/Parrot/Pmc2c/PCCMETHOD.pm
+++ lib/Parrot/Pmc2c/PCCMETHOD.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2004-2012, Parrot Foundation.
+# Copyright (C) 2004-2014, Parrot Foundation.
package Parrot::Pmc2c::PCCMETHOD;
use strict;
@@ -208,9 +208,15 @@ END
my $goto_string = "goto ${method_name}_returns;";
my ( $returns_signature, $returns_varargs ) =
process_pccmethod_args( parse_p_args_string($returns), 'return' );
-
+ my $rettype;
if ($returns_signature and !$method->is_vtable) {
- $e->emit( <<"END" );
+ if ($returns_signature eq 'P') { $rettype = 'pmc' }
+ elsif ($returns_signature eq 'S') { $rettype = 'string' }
+ elsif ($returns_signature eq 'I') { $rettype = 'integer' }
+ elsif ($returns_signature eq 'P') { $rettype = 'number' }
+ else {
+ # Currently only "II" with FileHandle.tell
+ $e->emit( <<"END" );
{ /*BEGIN RETURN $returns */
Parrot_pcc_set_call_from_c_args(interp, _call_object,
"$returns_signature", $returns_varargs);
@@ -218,6 +224,16 @@ END
return;
} /*END RETURN $returns */
END
+ $matched->replace( $match, $e );
+ return 1;
+ }
+ $e->emit( <<"END" );
+ {
+ VTABLE_set_${rettype}_keyed_int(interp, _call_object, 0, $returns_varargs);
+ $wb
+ return;
+ }
+END
}
elsif ($wb) { # if ($returns_signature)
$e->emit( <<"END" );
--
2.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment