/* Copyright (c) 1997-2006 -*- C -*- Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany) http://www.math.tu-berlin.de/polymake, mailto:polymake@math.tu-berlin.de This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version: http://www.gnu.org/licenses/gpl.txt. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #ident "$Project: polymake $$Id: Customize.xs 6714 2006-01-11 15:24:36Z gawrilow $" #include "Ext.h" #include typedef OP* (*op_func)(pTHX); static op_func saved_op_sassign, saved_op_aassign; static SV *scalar_pkg, *array_pkg, *hash_pkg; static OP* custom_op_sassign(pTHX) { dSP; SV *var=TOPs; OP *ret=(*saved_op_sassign)(aTHX); if (!(SvFLAGS(var) & (SVs_TEMP | SVs_PADMY | SVs_GMG | SVs_SMG | SVs_RMG))) { SPAGAIN; PUSHMARK(PL_stack_sp); PUSHs(var); PUSHs(scalar_pkg); XPUSHs(var); PUTBACK; pp_tie(); } return ret; } static OP* custom_op_aassign(pTHX) { dSP; SV *var=TOPs; OP *ret=(*saved_op_aassign)(aTHX); if (!(SvFLAGS(var) & (SVs_TEMP | SVs_PADMY | SVs_GMG | SVs_SMG | SVs_RMG))) { SPAGAIN; PUSHMARK(PL_stack_sp); PUSHs(var); PUSHs(SvTYPE(var)==SVt_PVAV ? array_pkg : hash_pkg); XPUSHs(sv_2mortal(newRV(var))); PUTBACK; pp_tie(); } return ret; } MODULE = Poly::Customize PACKAGE = Poly::Customize PROTOTYPES: DISABLE void compile_start() PPCODE: { saved_op_sassign=PL_ppaddr[OP_SASSIGN]; saved_op_aassign=PL_ppaddr[OP_AASSIGN]; PL_ppaddr[OP_SASSIGN]=&custom_op_sassign; PL_ppaddr[OP_AASSIGN]=&custom_op_aassign; } void compile_end() PPCODE: { PL_ppaddr[OP_SASSIGN]=saved_op_sassign; PL_ppaddr[OP_AASSIGN]=saved_op_aassign; } BOOT: scalar_pkg=newSVpvn_share("Poly::Customize::Scalar", 23, 0); array_pkg=newSVpvn_share("Poly::Customize::Array", 22, 0); hash_pkg=newSVpvn_share("Poly::Customize::Hash", 21, 0);