From f5cf4afc842954ecae7a665f6997c912b930833c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Quelin?= Date: Tue, 15 Jan 2008 19:44:35 +0100 Subject: [PATCH] LBVXS::_invert() moved to XS --- XS.xs | 40 +++++++++++++++++++++++++++++++++++++++ lib/Language/Befunge/Vector/XS.pm | 1 - 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/XS.xs b/XS.xs index a6979cc..6c6256a 100644 --- a/XS.xs +++ b/XS.xs @@ -345,6 +345,46 @@ _substract( v1, v2, variant ) RETVAL +# +# my $vec = $v1->_invert; +# my $vec = -$v1; +# +# Subtract $v1 from the origin. Effectively, gives the inverse of the +# original vector. The new vector is the same distance from the origin, +# in the opposite direction. +# +SV* +_invert( v1, v2, variant ) + SV* v1; + SV* v2; + SV* variant; + INIT: + IV dim, i, val; + SV* self; + AV* my_array; + AV* v1_array; + HV* stash; + CODE: + /* fetch the underlying array of the object */ + v1_array = (AV*)SvRV(v1); + dim = av_len(v1_array); + + /* create the new array and populate it */ + my_array = newAV(); + for ( i=0 ; i<=dim; i++ ) { + val = SvIV( *av_fetch(v1_array, i, 0) ); + av_push( my_array, newSViv(-val) ); + } + + /* return a blessed reference to the AV */ + self = newRV_noinc( (SV*)my_array ); + stash = SvSTASH( (SV*)v1_array ); + sv_bless( (SV*)self, stash ); + RETVAL = self; + OUTPUT: + RETVAL + + #- inplace math ops diff --git a/lib/Language/Befunge/Vector/XS.pm b/lib/Language/Befunge/Vector/XS.pm index d615f25..0b0a3d3 100644 --- a/lib/Language/Befunge/Vector/XS.pm +++ b/lib/Language/Befunge/Vector/XS.pm @@ -37,7 +37,6 @@ sub as_string { #sub copy { my $vec = shift; return bless [@$vec], ref $vec; } sub bounds_check {$_[0]} -sub _invert {$_[0]} 1; __END__ -- 2.11.4.GIT