pike.git / src / operators.c

version» Context lines:

pike.git/src/operators.c:1:   /*\   ||| This file is part of Pike. For copyright information see COPYRIGHT.   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   /**/   #include "global.h"   #include <math.h> - RCSID("$Id: operators.c,v 1.146 2002/04/20 14:56:14 jhs Exp $"); + RCSID("$Id: operators.c,v 1.147 2002/04/20 15:07:39 jhs Exp $");   #include "interpret.h"   #include "svalue.h"   #include "multiset.h"   #include "mapping.h"   #include "array.h"   #include "stralloc.h"   #include "opcodes.h"   #include "operators.h"   #include "language.h"   #include "pike_memory.h"
pike.git/src/operators.c:2009:    {    do_docode(CDR(n),DO_NOT_COPY_TOPLEVEL);    emit0(F_LSH);    return 1;    }    return 0;   }      PMOD_EXPORT void o_rsh(void)   { -  if(sp[-2].type == T_STRING) /* s[..sizeof(s)-n-1] */ +  switch(sp[-2].type)    { -  +  case T_ARRAY: /* s[..sizeof(s)-n-1] */ +  { +  struct array *a; +  if(to >= sp[-1].u.array->size-1) +  { +  to = sp[-1].u.array->size-1; +  +  if(from>to+1) from=to+1; +  } +  +  a = slice_array(sp[-1].u.array, from, to+1); +  free_array(sp[-1].u.array); +  sp[-1].u.array=a; +  break; +  } +  +  case T_STRING: /* s[..sizeof(s)-n-1] */ +  {    struct pike_string *s;    ptrdiff_t len;    int args = 2;       if(sp[-1].type != T_INT)    SIMPLE_BAD_ARG_ERROR("`>>", 2, "int");       len = sp[-1].u.integer;    if(len <= 0) /* NOP */    {
pike.git/src/operators.c:2035:    len = sp[-2].u.string->len;    len = sp[-2].u.string->len - len;       s = string_slice(sp[-2].u.string, 0, len);    free_string(sp[-2].u.string);    sp--;    sp[-1].u.string = s;    return;    }    -  if(sp[-2].type != T_INT || sp[-1].type != T_INT) +  case T_INT:    { -  int args = 2; -  if(call_lfun(LFUN_RSH, LFUN_RRSH)) -  return; -  if(sp[-2].type != T_INT) -  SIMPLE_BAD_ARG_ERROR("`>>", 1, "int|string|object"); -  SIMPLE_BAD_ARG_ERROR("`>>", 2, "int|object"); -  } -  +    #ifdef AUTO_BIGNUM    if(INT_TYPE_RSH_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer))    {    sp--;    sp[-1].u.integer = 0;    return;    }   #else /* !AUTO_BIGNUM */    if (sp[-1].u.integer > 31) {    sp--;
pike.git/src/operators.c:2066:    sp[-1].u.integer = -1;    } else {    sp[-1].u.integer = 0;    }    return;    }   #endif /* AUTO_BIGNUM */       sp--;    sp[-1].u.integer = sp[-1].u.integer >> sp->u.integer; +  return;    } -  +  } +  if(sp[-1].type != T_INT || sp[-2].type != T_INT) +  { +  int args = 2; +  if(call_lfun(LFUN_RSH, LFUN_RRSH)) +  return; +  if(sp[-2].type != T_INT) +  SIMPLE_BAD_ARG_ERROR("`>>", 1, "int|string|object"); +  SIMPLE_BAD_ARG_ERROR("`>>", 2, "int|object"); +  } + }      /*! @decl int `>>(int arg1, int arg2)    *! @decl mixed `>>(object arg1, int|object arg2)    *! @decl mixed `>>(int arg1, object arg2)    *! @decl string `>>(string arg1, int arg2)    *!    *! Right shift operator.    *!    *! If @[arg1] is an object that implements @[lfun::`>>()], that    *! function will be called with @[arg2] as the single argument.    *!    *! If @[arg2] is an object that implements @[lfun::``>>()], that    *! function will be called with @[arg1] as the single argument.    *!    *! If @[arg1] is a string, it will be truncated @[arg2] characters    *! from the right ("Hi!" >> 2 == "Hi!"[..sizeof("Hi!")-3] == "H").    *! -  *! Otherwise @[arg1] will be shifted @[arg2] bits left. +  *! Otherwise @[arg1] will be shifted @[arg2] bits right.    *!    *! @seealso    *! @[`<<()]    */   PMOD_EXPORT void f_rsh(INT32 args)   {    if(args != 2) {    /* FIXME: Not appropriate if too many args. */    SIMPLE_TOO_FEW_ARGS_ERROR("`>>", 2);    }