pike.git / src / operators.c

version» Context lines:

pike.git/src/operators.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| 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.120 2001/02/07 14:58:35 grubba Exp $"); + RCSID("$Id: operators.c,v 1.121 2001/02/08 13:38:27 grubba 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:177:    *! Otherwise if any of the other arguments is an object that has    *! an @[lfun::``+()] the first such function fill be called    *! with the arguments leading up to it, and @[`+()] be called recursively    *! with the result and the rest of the srguments.    *!    *! If there are two arguments the result will be:    *! @mixed @[arg1]    *! @type string    *! @[arg2] will be converted to a string, and the result the    *! strings concatenated. -  *! @type int|float +  *! @type int +  *! @type float    *! @mixed @[arg2]    *! @type string    *! @[arg1] will be converted to string, and the result the    *! strings concatenated. -  *! @type int|float +  *! @type int +  *! @type float    *! The result will be @code{@[arg1] + @[arg2]@}, and will    *! be a float if either @[arg1] or @[arg2] is a float.    *! @endmixed    *! @type array    *! The arrays will be concatenated.    *! @type mapping    *! The mappings will be joined.    *! @type multiset    *! The multisets will be added.    *! @endmixed
pike.git/src/operators.c:1357:    *!    *! If there are more than two arguments, the result will be:    *! @code{`&(`&(@[arg1], @[arg2]), @@@[extras])@}.    *!    *! If @[arg1] is an object that has an @[lfun::`&()], that function    *! will be called with @[arg2] as the single argument.    *!    *! If @[arg2] is an object that has an @[lfun::``&()], that function    *! will be called with @[arg1] as the single argument.    *! -  *! Otherwise the result will be: +  *! Otherwise the result will be as follows:    *! @mixed @[arg1]    *! @type int    *! The result will be the bitwise and of @[arg1] and @[arg2].    *! @type array    *! @type multiset    *! @type mapping    *! The result will be the elements of @[arg1] and @[arg2] that    *! occurr in both.    *! @type type    *! @type program    *! The result will be the type intersection of @[arg1] and @[arg2].    *! @type string    *! The result will be the string where the elements of @[arg1] -  *! and @[arg2] have been pairwise anded. +  *! and @[arg2] have been pairwise bitwise anded.    *! @endmixed    *!    *! @seealso    *! @[`|()], @[lfun::`&()], @[lfun::``&()]    */   PMOD_EXPORT void f_and(INT32 args)   {    switch(args)    {    case 0: SIMPLE_TOO_FEW_ARGS_ERROR("`&", 1);
pike.git/src/operators.c:1551:    return;    }       STRING_BITOP(|,"OR")       default:    PIKE_ERROR("`|", "Bitwise or on illegal type.\n", sp, 2);    }   }    - /*! @decl mixed `|(mixed arg1, mixed ... extras) + /*! @decl mixed `|(mixed arg1) +  *! @decl mixed `|(object arg1, mixed arg2) +  *! @decl mixed `|(mixed arg1, object arg2) +  *! @decl int `|(int arg1, int arg2) +  *! @decl mapping `|(mapping arg1, mapping arg2) +  *! @decl multiset `|(multiset arg1, multiset arg2) +  *! @decl array `|(array arg1, array arg2) +  *! @decl string `|(string arg1, atring arg2) +  *! @decl type `|(program|type arg1, program|type arg2) +  *! @decl mixed `|(mixed arg1, mixed arg2, mixed ... extras)    *! -  *! Or operator. +  *! Bitwise or/join operator. +  *! +  *! If there's a single argument, that argument will be returned. +  *! +  *! If there are more than two arguments, the result will be: +  *! @code{`|(`|(@[arg1], @[arg2]), @@@[extras])@}. +  *! +  *! If @[arg1] is an object that has an @[lfun::`|()], that function +  *! will be called with @[arg2] as the single argument. +  *! +  *! If @[arg2] is an object that has an @[lfun::``|()], that function +  *! will be called with @[arg1] as the single argument. +  *! +  *! Otherwise the result will be as follows: +  *! @mixed @[arg1] +  *! @type int +  *! The result will be the binary or of @[arg1] and @[arg2]. +  *! @type mapping +  *! @type multiset +  *! The result will be the join of @[arg1] and @[arg2]. +  *! @type array +  *! The result will be the concatenation of @[arg1] and @[arg2]. +  *! @type string +  *! The result will be the pairwise bitwose or of @[arg1] and @[arg2]. +  *! @type type +  *! @type program +  *! The result will be the type join of @[arg1] and @[arg2]. +  *! @endmixed +  *! +  *! @seealso +  *! @[`&()], @[lfun::`|()], @[lfun::``|()]    */   PMOD_EXPORT void f_or(INT32 args)   {    switch(args)    {    case 0: SIMPLE_TOO_FEW_ARGS_ERROR("`|", 1);    case 1: return;    case 2: o_or(); return;    default:    if(sp[-args].type==T_OBJECT)
pike.git/src/operators.c:1734:    return;    }       STRING_BITOP(^,"XOR")       default:    PIKE_ERROR("`^", "Bitwise XOR on illegal type.\n", sp, 2);    }   }    - /*! @decl mixed `^(mixed arg1, mixed ... extras) + /*! @decl mixed `^(mixed arg1) +  *! @decl mixed `^(object arg1, mixed arg2) +  *! @decl mixed `^(mixed arg1, object arg2) +  *! @decl int `^(int arg1, int arg2) +  *! @decl mapping `^(mapping arg1, mapping arg2) +  *! @decl multiset `^(multiset arg1, multiset arg2) +  *! @decl array `^(array arg1, array arg2) +  *! @decl string `^(string arg1, atring arg2) +  *! @decl type `^(program|type arg1, program|type arg2) +  *! @decl mixed `^(mixed arg1, mixed arg2, mixed ... extras)    *! -  *! Xor operator. +  *! Exclusive or operator. +  *! +  *! If there's a single argument, that argument will be returned. +  *! +  *! If there are more than two arguments, the result will be: +  *! @code{`^(`^(@[arg1], @[arg2]), @@@[extras])@}. +  *! +  *! If @[arg1] is an object that has an @[lfun::`^()], that function +  *! will be called with @[arg2] as the single argument. +  *! +  *! If @[arg2] is an object that has an @[lfun::``^()], that function +  *! will be called with @[arg1] as the single argument. +  *! +  *! Otherwise the result will be as follows: +  *! @mixed @[arg1] +  *! @type int +  *! The result will be the bitwise xor of @[arg1] and @[arg2]. +  *! @type mapping +  *! @type multiset +  *! @type array +  *! The result will be the elements of @[arg1] and @[arg2] that +  *! only occurr in one of them. +  *! @type string +  *! The result will be the pairwise bitwise xor of @[arg1] and @[arg2]. +  *! @type type +  *! @type program +  *! The result will be the result of +  *! @code{(@[arg1]&~@[arg2])|(~@[arg1]&@[arg2])@}. +  *! @endmixed +  *! +  *! @seealso +  *! @[`&()], @[`|()], @[lfun::`^()], @[lfun::``^()]    */   PMOD_EXPORT void f_xor(INT32 args)   {    switch(args)    {    case 0: SIMPLE_TOO_FEW_ARGS_ERROR("`^", 1);    case 1: return;    case 2: o_xor(); return;    default:    if(sp[-args].type==T_OBJECT)
pike.git/src/operators.c:1794:    return;       if(sp[-2].type != T_INT)    SIMPLE_BAD_ARG_ERROR("`<<", 1, "int|object");    SIMPLE_BAD_ARG_ERROR("`<<", 2, "int|object");    }    sp--;    sp[-1].u.integer = sp[-1].u.integer << sp->u.integer;   }    - /*! @decl mixed `<<(mixed arg1, mixed arg2) + /*! @decl int `<<(int arg1, int arg2) +  *! @decl mixed `<<(object arg1, int|object arg2) +  *! @decl mixed `<<(int arg1, object arg2)    *!    *! Left 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. +  *! +  *! Otherwise @[arg1] will be shifted @[arg2] bits left. +  *! +  *! @seealso +  *! @[`>>()]    */   PMOD_EXPORT void f_lsh(INT32 args)   {    if(args != 2) {    /* FIXME: Not appropriate if too many args. */    SIMPLE_TOO_FEW_ARGS_ERROR("`<<", 2);    }    o_lsh();   }   
pike.git/src/operators.c:1843: Inside #if defined(AUTO_BIGNUM)
   sp--;    sp[-1].u.integer = 0;    return;    }   #endif /* AUTO_BIGNUM */       sp--;    sp[-1].u.integer = sp[-1].u.integer >> sp->u.integer;   }    - /*! @decl mixed `>>(mixed arg1, mixed arg2) + /*! @decl int `>>(int arg1, int arg2) +  *! @decl mixed `>>(object arg1, int|object arg2) +  *! @decl mixed `>>(int arg1, object 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. +  *! +  *! Otherwise @[arg1] will be shifted @[arg2] bits left. +  *! +  *! @seealso +  *! @[`<<()]    */   PMOD_EXPORT void f_rsh(INT32 args)   {    if(args != 2) {    /* FIXME: Not appropriate if too many args. */    SIMPLE_TOO_FEW_ARGS_ERROR("`>>", 2);    }    o_rsh();   }   
pike.git/src/operators.c:2053:       default:    do_lfun_multiply:    if(call_lfun(LFUN_MULTIPLY, LFUN_RMULTIPLY))    return;       PIKE_ERROR("`*", "Bad arguments.\n", sp, 2);    }   }    - /*! @decl mixed `*(mixed arg1, mixed ... extras) + /*! @decl mixed `*(mixed arg1) +  *! @decl mixed `*(object arg1, mixed arg2, mixed ... extras) +  *! @decl mixed `*(mixed arg1, object arg2) +  *! @decl array `*(array arg1, int arg2) +  *! @decl array `*(array arg1, float arg2) +  *! @decl string `*(string arg1, int arg2) +  *! @decl string `*(string arg1, float arg2) +  *! @decl string `*(array(string) arg1, string arg2) +  *! @decl array `*(array(array) arg1, array arg2) +  *! @decl float `*(float arg1, int|float arg2) +  *! @decl float `*(int arg1, float arg2) +  *! @decl int `*(int arg1, int arg2) +  *! @decl mixed `*(mixed arg1, mixed arg2, mixed ... extras)    *!    *! Multiplication operator. -  +  *! +  *! If there's only a single argument, that argument will be returned. +  *! +  *! If the first argument is an object that implements @[lfun::`*()], +  *! that function will be called with the rest of the arguments. +  *! +  *! If there are more than two arguments, the result will be +  *! @code{`*(`*(@[arg1], @[arg2]), @@@[extras])@}. +  *! +  *! If @[arg2] is an object that implements @[lfun::``*()], that +  *! function will be called with @[arg1] as the single argument. +  *! +  *! Otherwise the result will be as follows: +  *! @mixed @[arg1] +  *! @type array +  *! @mixed @[arg2] +  *! @type int +  *! @type float +  *! The result will be @[arg1] concatenated @[arg2] times. +  *! @type string +  *! @type array +  *! The result will be the elements of @[arg1] concatenated with +  *! @[arg2] interspersed. +  *! @endmixed +  *! @type string +  *! The result will be @[arg1] concatenated @[arg2] times. +  *! @type int +  *! @type float +  *! The result will be @code{@[arg1] * @[arg2]@}, and will be a +  *! float if either @[arg1] or @[arg2] is a float. +  *! @endmixed +  *! +  *! @note +  *! In Pike 7.0 and earlier the multiplication order was unspecified. +  *! +  *! @seealso +  *! @[`+()], @[`-()], [`/()], @[lfun::`*()], @[lfun::``*()]    */   PMOD_EXPORT void f_multiply(INT32 args)   {    switch(args)    {    case 0: SIMPLE_TOO_FEW_ARGS_ERROR("`*", 1);    case 1: return;    case 2: o_multiply(); return;    default:    if(sp[-args].type==T_OBJECT)