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.201 2004/11/27 22:48:11 mast Exp $
+ || $Id: operators.c,v 1.202 2004/12/18 19:04:04 grubba 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:218:
if(!sp[-1].u.object->prog) {
/* Casting a destructed object should be like casting a zero. */
pop_stack();
push_int (0);
}
else {
{
struct object *o = sp[-1].u.object;
struct pike_string *s;
- int f = FIND_LFUN(o->prog,LFUN_CAST);
+ struct program *p = o->prog->inherits[sp[-1].subtype].prog;
+ int f = FIND_LFUN(p, LFUN_CAST);
if(f == -1)
Pike_error("No cast method in object.\n");
REF_MAKE_CONST_STRING(s, "int");
push_string(s);
apply_low(o, f, 1);
stack_pop_keep_top();
}
if(sp[-1].type != PIKE_T_INT)
{
if(sp[-1].type == T_OBJECT && sp[-1].u.object->prog)
{
- int f=FIND_LFUN(sp[-1].u.object->prog, LFUN__IS_TYPE);
+ struct object *o = sp[-1].u.object;
+ int f = FIND_LFUN(o->prog->inherits[sp[-1].subtype].prog,
+ LFUN__IS_TYPE);
if( f != -1)
{
struct pike_string *s;
REF_MAKE_CONST_STRING(s, "int");
push_string(s);
- apply_low(sp[-2].u.object, f, 1);
+ apply_low(o, f, 1);
f=!UNSAFE_IS_ZERO(sp-1);
pop_stack();
if(f) return;
}
}
Pike_error("Cast failed, wanted int, got %s\n",
get_name_of_type(sp[-1].type));
}
}
pike.git/src/operators.c:334:
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,LFUN_CAST);
+ 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)
{
if(sp[-1].type == T_OBJECT && sp[-1].u.object->prog)
{
- int f=FIND_LFUN(sp[-1].u.object->prog, LFUN__IS_TYPE);
+ struct object *o = sp[-1].u.object;
+ int f = FIND_LFUN(o->prog->inherits[sp[-1].subtype].prog,
+ LFUN__IS_TYPE);
if( f != -1)
{
struct pike_string *s;
REF_MAKE_CONST_STRING(s, "string");
push_string(s);
- apply_low(sp[-2].u.object, f, 1);
+ apply_low(o, f, 1);
f=!UNSAFE_IS_ZERO(sp-1);
pop_stack();
if(f) return;
}
}
Pike_error("Cast failed, wanted string, got %s\n",
get_name_of_type(sp[-1].type));
}
}
return;
pike.git/src/operators.c:469:
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,LFUN_CAST);
+ 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)
{
default:
pike.git/src/operators.c:620:
case T_FUNCTION:
if (Pike_sp[-1].subtype == FUNCTION_BUILTIN) {
Pike_error("Cannot cast builtin functions to object.\n");
} else if (Pike_sp[-1].u.object->prog == pike_trampoline_program) {
ref_push_object(((struct pike_trampoline *)
(Pike_sp[-1].u.object->storage))->
frame->current_object);
stack_pop_keep_top();
} else {
Pike_sp[-1].type = T_OBJECT;
+ Pike_sp[-1].subtype = 0;
}
break;
default:
Pike_error("Cannot cast %s to object.\n",get_name_of_type(sp[-1].type));
}
break;
case T_PROGRAM:
switch(sp[-1].type)
pike.git/src/operators.c:671:
default:
Pike_error("Cannot cast %s to a program.\n",get_name_of_type(sp[-1].type));
}
}
}
if(run_time_type != sp[-1].type)
{
if(sp[-1].type == T_OBJECT && sp[-1].u.object->prog)
{
- int f=FIND_LFUN(sp[-1].u.object->prog, LFUN__IS_TYPE);
+ struct object *o = sp[-1].u.object;
+ int f = FIND_LFUN(o->prog->inherits[sp[-1].subtype].prog, LFUN__IS_TYPE);
if( f != -1)
{
push_text(get_name_of_type(run_time_type));
- apply_low(sp[-2].u.object, f, 1);
+ apply_low(o, f, 1);
f=!UNSAFE_IS_ZERO(sp-1);
pop_stack();
if(f) goto emulated_type_ok;
}
}
Pike_error("Cast failed, wanted %s, got %s\n",
get_name_of_type(run_time_type),
get_name_of_type(sp[-1].type));
}
pike.git/src/operators.c:1059:
*/
COMPARISON(f_ge,"`>=",is_ge)
#define CALL_OPERATOR(OP, args) do { \
struct object *o_ = sp[-args].u.object; \
int i; \
if(!o_->prog) \
bad_arg_error(lfun_names[OP], sp-args, args, 1, "object", sp-args, \
"Called in destructed object.\n"); \
- if((i = FIND_LFUN(o_->prog,OP)) == -1) \
+ if((i = FIND_LFUN(o_->prog->inherits[sp[-args].subtype].prog, \
+ OP)) == -1) \
bad_arg_error(lfun_names[OP], sp-args, args, 1, "object", sp-args, \
"Operator not in object.\n"); \
apply_low(o_, i, args-1); \
stack_pop_keep_top(); \
} while (0)
/*! @decl mixed `+(mixed arg)
*! @decl mixed `+(object arg, mixed ... more)
*! @decl int `+(int arg, int ... more)
*! @decl float `+(float|int arg, float|int ... more)
pike.git/src/operators.c:1158:
switch(types)
{
default:
if(!args)
{
SIMPLE_TOO_FEW_ARGS_ERROR("`+", 1);
}else{
if(types & BIT_OBJECT)
{
+ struct object *o;
+ struct program *p;
+ int i;
+
if (args == 1)
return;
if(sp[-args].type == T_OBJECT && sp[-args].u.object->prog)
{
/* The first argument is an object. */
- int i;
- if(sp[-args].u.object->refs==1 &&
- (i = FIND_LFUN(sp[-args].u.object->prog,LFUN_ADD_EQ)) != -1)
+ o = sp[-args].u.object;
+ p = o->prog->inherits[sp[-args].subtype].prog;
+ if(o->refs==1 &&
+ (i = FIND_LFUN(p, LFUN_ADD_EQ)) != -1)
{
- apply_low(sp[-args].u.object, i, args-1);
+ apply_low(o, i, args-1);
stack_pop_keep_top();
return;
}
- if((i = FIND_LFUN(sp[-args].u.object->prog,LFUN_ADD)) != -1)
+ if((i = FIND_LFUN(p, LFUN_ADD)) != -1)
{
- apply_low(sp[-args].u.object, i, args-1);
+ apply_low(o, i, args-1);
free_svalue(sp-2);
sp[-2]=sp[-1];
sp--;
dmalloc_touch_svalue(sp);
return;
}
}
for(e=1;e<args;e++)
{
- int i;
+
if(sp[e-args].type == T_OBJECT &&
- sp[e-args].u.object->prog &&
- (i = FIND_LFUN(sp[e-args].u.object->prog,LFUN_RADD)) != -1)
+ (p = (o = sp[e-args].u.object)->prog) &&
+ (i = FIND_LFUN(p->inherits[sp[e-args].subtype].prog,
+ LFUN_RADD)) != -1)
{
/* There's an object with a lfun::``+() at argument @[e]. */
if (e == args-1) {
/* The object is the last argument. */
- struct object *o = Pike_sp[-1].u.object;
+
ONERROR err;
Pike_sp--;
SET_ONERROR(err, do_free_object, o);
apply_low(o, i, e);
CALL_AND_UNSET_ONERROR(err);
return;
} else {
/* Rotate the stack, so that the @[e] first elements come last.
*/
struct svalue *tmp;
pike.git/src/operators.c:1229:
* -args object with lfun::``+()
* ...
* ... other arguments
* ...
* -e first argument.
* ...
* -1 last argument before the object.
*/
#ifdef PIKE_DEBUG
if (Pike_sp[-args].type != T_OBJECT ||
- !Pike_sp[-args].u.object->prog ||
- FIND_LFUN(Pike_sp[-args].u.object->prog, LFUN_RADD) != i) {
+ Pike_sp[-args].u.object != o ||
+ !o->prog) {
Pike_fatal("`+() Lost track of object.\n");
}
#endif /* PIKE_DEBUG */
- apply_low(Pike_sp[-args].u.object, i, e);
+ apply_low(o, i, e);
args -= e;
/* Replace the object with the result. */
assign_svalue(Pike_sp-(args+1), Pike_sp-1);
pop_stack();
goto tail_recurse;
}
}
}
}
}
pike.git/src/operators.c:1873: Inside #if defined(AUTO_BIGNUM)
stack_swap();
f_cast();
return 1;
}
#endif
return 0;
}
static int call_lfun(int left, int right)
{
+ struct object *o;
+ struct program *p;
int i;
-
+
if(sp[-2].type == T_OBJECT &&
- sp[-2].u.object->prog &&
- (i = FIND_LFUN(sp[-2].u.object->prog,left)) != -1)
+ (p = (o = sp[-2].u.object)->prog) &&
+ (i = FIND_LFUN(p->inherits[sp[-2].subtype].prog, left)) != -1)
{
- apply_low(sp[-2].u.object, i, 1);
+ apply_low(o, i, 1);
free_svalue(sp-2);
sp[-2]=sp[-1];
sp--;
dmalloc_touch_svalue(sp);
return 1;
}
if(sp[-1].type == T_OBJECT &&
- sp[-1].u.object->prog &&
- (i = FIND_LFUN(sp[-1].u.object->prog,right)) != -1)
+ (p = (o = sp[-1].u.object)->prog) &&
+ (i = FIND_LFUN(p->inherits[sp[-1].subtype].prog, right)) != -1)
{
push_svalue(sp-2);
- apply_low(sp[-2].u.object, i, 1);
+ apply_low(o, i, 1);
free_svalue(sp-3);
sp[-3]=sp[-1];
sp--;
dmalloc_touch_svalue(sp);
pop_stack();
return 1;
}
return 0;
}
pike.git/src/operators.c:4322:
switch (ind->type) {
case T_OBJECT: {
struct object *o = ind->u.object;
int f;
if (!o->prog)
bad_arg_error (range_func_name (bound_types),
ind, sp - ind, 1, "object", ind,
"Cannot call `[..] in destructed object.\n");
- if ((f = FIND_LFUN (o->prog, LFUN_RANGE)) != -1) {
+ if ((f = FIND_LFUN(o->prog->inherits[ind->subtype].prog,
+ LFUN_RANGE)) != -1) {
struct svalue h;
if (!(bound_types & RANGE_HIGH_OPEN)) {
move_svalue (&h, high);
sp = high;
}
if (bound_types & RANGE_LOW_FROM_BEG)
push_int (INDEX_FROM_BEG);
else if (bound_types & RANGE_LOW_OPEN) {
push_int (0);
pike.git/src/operators.c:4556:
} while (0)
switch (ind->type) {
case T_OBJECT: {
struct object *o = ind->u.object;
int f;
if (!o->prog)
SIMPLE_ARG_ERROR ("predef::`[..]", 1,
"Cannot call `[..] in destructed object.\n");
- if ((f = FIND_LFUN (o->prog, LFUN_RANGE)) != -1) {
+ if ((f = FIND_LFUN(o->prog->inherits[ind->subtype].prog,
+ LFUN_RANGE)) != -1) {
apply_low (o, f, 4);
stack_pop_keep_top();
}
else {
int bound_types;
CALC_BOUND_TYPES (bound_types);
switch (call_old_range_lfun (bound_types, o, ind + 1, ind + 3)) {
case 1:
SIMPLE_ARG_ERROR ("predef::`[..]", 1,