pike.git/
src/
operators.c
Branch:
Tag:
Non-build tags
All tags
No tags
2016-12-31
2016-12-31 20:41:59 by Martin Nilsson <nilsson@fastmail.com>
b83b373735f2abd5edd05e0b940b715f15a984b9 (
112
lines) (+
65
/-
47
)
[
Show
|
Annotate
]
Branch:
8.1
Dedup lfun call code from cast operator code.
46:
*/ #define MAX_NUM_BUF (MAXIMUM(MAX_INT_SPRINTF_LEN,MAX_FLOAT_SPRINTF_LEN))
+
static int has_lfun( enum LFUN lfun, int arg );
+
static int call_lhs_lfun( enum LFUN lfun, int arg );
+
void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind) { switch(TYPEOF(*what))
208:
pop_stack(); push_int (0); }
-
-
else
{
+
else
{
-
struct object *o =
sp[-1].u.object
;
-
struct program *p = o
->prog
->inherits[SUBTYPEOF(sp[-1])].prog;
-
int f
=
FIND
_
LFUN(p,
LFUN_CAST
)
;
-
if(f == -1)
-
Pike_error("No cast method in object.\n")
;
+
if(
sp[-1].u.object->prog =
=
bignum
_
program
)
+
return;
+
ref_push_string(literal_int_string);
-
apply
_
low
(
o,
f,
1
);
-
stack_pop_keep_top();
-
}
+
if(!call_lhs_lfun(LFUN_CAST,2))
+
Pike
_
error
(
"No
cast
method in object <2>.\n"
);
+
stack_pop_keep_top();
/*
pop
object.
*/
if(TYPEOF(sp[-1]) != PIKE_T_INT) {
-
if(TYPEOF(sp[-1]) == T_OBJECT
&& sp[-1].u.object->prog
)
+
if(TYPEOF(sp[-1]) == T_OBJECT)
{ struct object *o = sp[-1].u.object;
-
int f = FIND_LFUN
(o->prog
->inherits[SUBTYPEOF(sp[-1])].prog,
-
LFUN__IS_TYPE)
;
-
if(
f !=
-
1
)
+
if(
o->prog
==
bignum_program
)
+
return
;
+
else
if(
o->prog
)
{ ref_push_string(literal_int_string);
-
apply
_
low
(
o
,
f, 1
)
;
-
f=
!UNSAFE_IS_ZERO(sp-1)
;
+
if( call
_
lhs_lfun
(
LFUN__IS_TYPE
,
2)
)
+
if(
!UNSAFE_IS_ZERO(sp-1)
)
+
{
pop_stack();
-
if(f)
return;
+
return;
}
-
+
pop_stack();
}
-
+
}
Pike_error("Cast failed, wanted int, got %s\n", get_name_of_type(TYPEOF(sp[-1]))); }
295:
/* Casting a destructed object should be like casting a zero. */ pop_stack(); push_constant_text("0");
-
} else
{
+
} else
{
-
struct object *o = sp[-1].u.object;
-
int f = FIND_LFUN(o->prog->inherits[SUBTYPEOF(sp[-1])].prog, LFUN_CAST);
-
if(f == -1)
-
Pike_error("No cast method in object.\n");
+
ref_push_string(literal_string_string);
-
apply
_
low
(
o,
f,
1
);
+
if(!call_lhs_lfun(LFUN_CAST,2))
+
Pike
_
error
(
"No
cast
method in object.\n"
);
stack_pop_keep_top();
-
}
+
if(TYPEOF(sp[-1]) != PIKE_T_STRING) {
312:
Pike_error("Cannot cast this object to string.\n"); if(TYPEOF(sp[-1]) == T_OBJECT && sp[-1].u.object->prog) {
-
struct object *o = sp[-1].u.object;
-
int f = FIND_LFUN(o->prog->inherits[SUBTYPEOF(sp[-1])].prog,
-
LFUN__IS_TYPE);
-
if( f != -1)
-
{
+
ref_push_string(literal_string_string);
-
apply
_
low
(
o,
f
,
1
)
;
-
f=
!UNSAFE_IS_ZERO(sp-1)
;
+
if(
call
_
lhs_lfun
(
LFUN__IS_TYPE
,
2
)
)
+
if(
!UNSAFE_IS_ZERO(sp-1)
)
+
{
pop_stack();
-
if(f)
return;
+
return;
}
-
+
pop_stack();
} Pike_error("Cast failed, wanted string, got %s\n", get_name_of_type(TYPEOF(sp[-1])));
2222:
return 0; }
+
static int has_lfun(enum LFUN lfun, int arg)
+
{
+
struct program *p;
+
+
if(TYPEOF(sp[-arg]) == T_OBJECT && (p = sp[-arg].u.object->prog))
+
return FIND_LFUN(p->inherits[SUBTYPEOF(sp[-arg])].prog, lfun);
+
return -1;
+
}
+
+
static int call_lhs_lfun( enum LFUN lfun, int arg )
+
{
+
int i = has_lfun(lfun,arg);
+
+
if(i != -1)
+
{
+
apply_low(Pike_sp[-arg].u.object, i, arg-1);
+
return 1;
+
}
+
return 0;
+
}
+
static int call_lfun(enum LFUN left, enum LFUN right) { struct object *o;