pike.git
/
src
/
operators.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/operators.c:1:
/* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: operators.c,v 1.
237
2008/07/
08
16
:
08
:
21
grubba
Exp $
+
|| $Id: operators.c,v 1.
238
2008/07/
11
20
:
39
:
45
mast
Exp $
*/ #include "global.h" #include <math.h> #include "interpret.h" #include "svalue.h" #include "multiset.h" #include "mapping.h" #include "array.h" #include "stralloc.h"
pike.git/src/operators.c:350:
return; case T_OBJECT: if(!sp[-1].u.object->prog) { /* Casting a destructed object should be like casting a zero. */ pop_stack(); push_constant_text("0"); } else { { struct object *o = sp[-1].u.object;
-
struct pike_string *s;
+
int f = FIND_LFUN(o->prog->inherits[sp[-1].subtype].prog, LFUN_CAST); if(f == -1) Pike_error("No cast method in object.\n"); push_constant_text("string"); apply_low(o, f, 1); stack_pop_keep_top(); } if(sp[-1].type != PIKE_T_STRING) {
pike.git/src/operators.c:395:
break; case T_ARRAY: { int i; struct array *a = sp[-1].u.array; struct pike_string *s; int shift = 0; for(i = a->size; i--; ) {
-
unsigned
INT32
val;
+
INT_TYPE
val;
if (a->item[i].type != T_INT) {
-
Pike_error("cast: Item %d is not an integer
.\n
", i);
+
Pike_error("cast: Item %d is not an integer
: %O\n
", i
, a->item + i
);
}
-
val =
(unsigned INT32)
a->item[i].u.integer;
-
if (val
>
0xff)
{
+
val = a->item[i].u.integer;
+
switch (shift) { /* Trust the compiler to strength reduce this. */
+
case 0:
+
if (
(unsigned INT32)
val
<=
0xff)
+
break;
shift = 1;
-
if
(val
>
0xffff)
{
-
shift = 2;
-
while(i--)
-
if (
a->item[i].type
!= T_INT
)
-
Pike_error("cast: Item %d is not an integer.\n", i
)
;
+
/*
FALL
THROUGH
*/
+
+
case
1:
+
if (
(unsigned
INT32
)
val
<=
0xffff
)
break;
-
}
-
while(i--) {
-
if (a->item[i].type != T_INT) {
-
Pike_error("cast: Item %d is not an integer.\n", i);
-
}
-
val = (unsigned INT32)a->item[i].u.integer;
-
if (val > 0xffff) {
+
shift = 2;
-
while(i--)
-
if (
a->item[i].type
!=
T
_
INT)
-
Pike_error("cast: Item %d is
not
an
integer
.\n", i);
+
/*
FALL
THROUGH */
+
+
case
2:
+
#if
SIZEOF_INT_TYPE
>
4
+
if (
val
<
MIN
_
INT32
||
val
>
MAX_INT32)
+
Pike_error
("cast: Item %d is
too
large:
%"PRINTPIKEINT"x
.\n",
+
i
, val
);
+
#endif
break; } }
-
break;
-
}
-
}
+
s = begin_wide_shared_string(a->size, shift); switch(shift) { default: #ifdef PIKE_DEBUG Pike_fatal("cast: Bad shift: %d.\n", shift); break; case 0: #endif for(i = a->size; i--; ) {
-
s->str[i] = a->item[i].u.integer;
+
s->str[i] =
(p_wchar0)
a->item[i].u.integer;
} break; case 1: { p_wchar1 *str1 = STR1(s); for(i = a->size; i--; ) {
-
str1[i] = a->item[i].u.integer;
+
str1[i] =
(p_wchar1)
a->item[i].u.integer;
} } break; case 2: { p_wchar2 *str2 = STR2(s); for(i = a->size; i--; ) {
-
str2[i] = a->item[i].u.integer;
+
str2[i] =
(p_wchar2)
a->item[i].u.integer;
} } break; } s = end_shared_string(s); pop_stack(); push_string(s); } return;
pike.git/src/operators.c:488:
if (sp[-1].type == T_OBJECT && !sp[-1].u.object->prog) { /* Casting a destructed object should be like casting a zero. */ pop_stack(); push_int (0); } if(sp[-1].type == T_OBJECT) { struct object *o = sp[-1].u.object;
-
struct pike_string *s;
+
int f = FIND_LFUN(o->prog->inherits[sp[-1].subtype].prog, LFUN_CAST); if(f == -1) Pike_error("No cast method in object.\n"); push_string(describe_type(type)); apply_low(o, f, 1); stack_pop_keep_top(); }else switch(run_time_type) {
pike.git/src/operators.c:1675:
sp[-1].subtype = NUMBER_NUMBER; #endif /* AUTO_BIGNUM */ break; case BIT_FLOAT: { FLOAT_ARG_TYPE sum; sum=0.0; for(e=-args; e<0; e++) sum+=sp[e].u.float_number; sp-=args-1;
-
sp[-1].u.float_number=sum;
+
sp[-1].u.float_number
=
(FLOAT_TYPE)
sum;
break; } case BIT_FLOAT|BIT_INT: { FLOAT_ARG_TYPE sum; sum=0.0; for(e=-args; e<0; e++) { if(sp[e].type==T_FLOAT) { sum+=sp[e].u.float_number; }else{ sum+=(FLOAT_ARG_TYPE)sp[e].u.integer; } } sp-=args-1; sp[-1].type=T_FLOAT;
-
sp[-1].u.float_number=sum;
+
sp[-1].u.float_number
=
(FLOAT_TYPE)
sum;
break; } #define ADD_WITH_UNDEFINED(TYPE, T_TYPEID, ADD_FUNC, PUSH_FUNC) do { \ int e; \ if (sp[-args].type == T_INT) { \ if(IS_UNDEFINED(sp-args)) \ { \ struct TYPE *x; \ \
pike.git/src/operators.c:1763:
#undef ADD_WITH_UNDEFINED #undef ADD } } static int generate_sum(node *n) { struct compilation *c = THIS_COMPILATION; node **first_arg, **second_arg, **third_arg;
-
int num_args;
+
switch(count_args(CDR(n))) { case 0: return 0; case 1: do_docode(CDR(n),0); return 1; case 2: first_arg=my_get_arg(&_CDR(n), 0);
pike.git/src/operators.c:4333:
case T_OBJECT: CALL_OPERATOR(LFUN_COMPL,1); break; case T_INT: sp[-1].u.integer = ~ sp[-1].u.integer; sp[-1].subtype = NUMBER_NUMBER; break; case T_FLOAT:
-
sp[-1].u.float_number = -1.0 - sp[-1].u.float_number;
+
sp[-1].u.float_number =
(FLOAT_TYPE)
-1.0 - sp[-1].u.float_number;
break; case T_TYPE: type_stack_mark(); if (sp[-1].u.type->type == T_NOT) { push_finished_type(sp[-1].u.type->car); } else { push_finished_type(sp[-1].u.type); push_type(T_NOT); }
pike.git/src/operators.c:5171:
{ switch (args) { case 0: case 1: case 2: PIKE_ERROR("`[]=", "Too few arguments.\n", sp, args); break; case 3: if(sp[-2].type==T_STRING) sp[-2].subtype=0; assign_lvalue (sp-3, sp-1);
-
assign
_
svalue (sp-3, sp-1);
-
pop_n_elems (
args-1
);
+
stack
_pop_n_elems
_keep_top
(
2
);
break; default: PIKE_ERROR("`[]=", "Too many arguments.\n", sp, args); } } /*! @decl mixed `->=(object arg, string index, mixed val) *! @decl mixed `->=(mapping arg, string index, mixed val) *! @decl int(0..1) `->=(multiset arg, string index, int(0..1) val) *!