pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:1:
/* -*- c -*- || 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: builtin.cmod,v 1.
101
2002
/
12/
01
18
:
58
:
20
mast
Exp $
+
|| $Id: builtin.cmod,v 1.
102
2003
/
01
/
08
13
:
59
:
24
grubba
Exp $
*/ #include "global.h" #include "interpret.h" #include "svalue.h" #include "opcodes.h" #include "pike_macros.h" #include "object.h" #include "program.h" #include "array.h"
pike.git/src/builtin.cmod:37:
*! *! Debug function for showing the symbol table of a program. */ PIKEFUN array(array(int|string)) _describe_program(mixed x) efun; { struct program *p; struct array *res; int i;
-
if (!(p = program_from_svalue(Pike_sp - args)))
{
-
Pike
_
error
("_describe_program
():
Bad argument
1
(expected
program
).\n
");
-
}
+
if (!(p = program_from_svalue(Pike_sp - args)))
+
SIMPLE
_
BAD_ARG_ERROR
("_describe_program
",
1
,
"
program");
for (i=0; i < (int)p->num_identifier_references;i++) { struct reference *ref = p->identifier_references + i; struct identifier *id = ID_FROM_PTR(p, ref); struct inherit *inh = INHERIT_FROM_PTR(p, ref); push_int(ref->id_flags); ref_push_string(id->name); push_int(id->identifier_flags); if (id->identifier_flags & IDENTIFIER_C_FUNCTION) { push_int(-2);
pike.git/src/builtin.cmod:151:
if(Pike_sp[-1].type == T_STRING) { stack_swap(); pop_stack(); return; } Pike_error("Non-string returned from _sprintf()\n"); } } if(x->type != T_INT)
-
Pike
_
error
("
Bad
argument
1
to int2char.\n
");
+
SIMPLE
_
BAD_ARG_ERROR
("
int2char",
1
,
"
int"
);
c=x->u.integer; if(c>=0 && c<256) { struct pike_string *s; s=begin_shared_string(1); s->str[0]=c; RETURN end_shared_string(s); }else{
pike.git/src/builtin.cmod:204:
if(Pike_sp[-1].type == T_STRING) { stack_swap(); pop_stack(); return; } Pike_error("Non-string returned from _sprintf()\n"); } } if(x->type != T_INT)
-
Pike
_
error
("
Bad
argument
1
to int2hex.\n
");
+
SIMPLE
_
BAD_ARG_ERROR
("
int2hex",
1
,
"
int"
);
c=x->u.integer; len=1; if(c<0) { len++; n=(-c)&((unsigned int)(-1)); }else{ n=c; }
pike.git/src/builtin.cmod:677:
*! @seealso *! @[function_object()] */ PIKEFUN string function_name(program|function func) efun; optflags OPT_TRY_OPTIMIZE; { switch(func->type) { default:
-
bad
_
arg
_
error
("function_name",
Pike_sp-args, args,
1,
-
"function|program"
, Pike_sp-args,
-
"Bad argument.\n"
);
+
SIMPLE
_
BAD
_
ARG_ERROR
("function_name", 1, "function|program");
return; /* NOTREACHED */ case PIKE_T_PROGRAM: { struct program *p=func->u.program; if(p->parent) { int e; p=p->parent;
pike.git/src/builtin.cmod:731:
REF_RETURN ID_FROM_INT(t->frame->current_object->prog, t->func)->name; } REF_RETURN ID_FROM_INT(func->u.object->prog, func->subtype)->name; } pop_n_elems(args); push_int(0); }
-
/*! @decl object function_object(function
|program
f)
+
/*! @decl object function_object(function f)
*!
-
*! Return the object the function @[f] is in.
+
*!
Return the object the function @[f] is in.
*!
-
*! If @[f] is a global function defined in the runtime @tt{0@} (zero)
-
*! will be returned.
+
*!
If @[f] is a global function defined in the runtime @tt{0@} (zero)
+
*!
will be returned.
*!
-
+
*! Zero will also be returned if @[f] is a constant in the
+
*! parent class. In that case @[function_program()] can be
+
*! used to get the parent program.
+
*!
*! @seealso
-
*! @[function_name()]
+
*!
@[function_name()]
, @[function_program()]
*/
-
PIKEFUN object|program function_object(
object
|program
|function
func)
+
PIKEFUN object|program function_object(
function
|program func)
efun; optflags OPT_TRY_OPTIMIZE;
-
type function(function
|object
:object)
|function(program:program)
;
+
type function(function:object);
{ switch(func->type) { case PIKE_T_PROGRAM:
-
{
-
struct program *p;
-
if(!(p=func->u.program->parent))
break;
-
add_ref(p);
-
free_program(func->u.program);
-
func->u.program=p;
-
return;
-
}
+
break;
case PIKE_T_FUNCTION: if(func->subtype == FUNCTION_BUILTIN) break; if(func->u.object->prog == pike_trampoline_program) { struct object *o; o=((struct pike_trampoline *)func->u.object->storage)->frame->current_object; add_ref(o); pop_n_elems(args); push_object(o);
pike.git/src/builtin.cmod:780:
return; default: SIMPLE_BAD_ARG_ERROR("function_object",1,"function"); } pop_n_elems(args); push_int(0); }
+
/*! @decl program function_program(function|program f)
+
*!
+
*! Return the program the function @[f] is in.
+
*!
+
*! If @[f] is a global function defined in the runtime @tt{0@} (zero)
+
*! will be returned.
+
*!
+
*! @seealso
+
*! @[function_name()], @[function_object()]
+
*/
+
PIKEFUN program function_program(program|function func)
+
efun;
+
optflags OPT_TRY_OPTIMIZE;
+
{
+
switch(func->type)
+
{
+
case PIKE_T_PROGRAM:
+
{
+
struct program *p;
+
if(!(p=func->u.program->parent)) break;
+
add_ref(p);
+
free_program(func->u.program);
+
func->u.program=p;
+
return;
+
}
-
+
case PIKE_T_FUNCTION:
+
{
+
struct program *p;
+
if(func->subtype == FUNCTION_BUILTIN) break;
+
p = func->u.object->prog;
+
if(p == pike_trampoline_program)
+
{
+
p = ((struct pike_trampoline *)func->u.object->storage)->
+
frame->current_object->prog;
+
}
+
if (p) {
+
ref_push_program(p);
+
stack_pop_n_elems_keep_top(args);
+
return;
+
}
+
}
+
break;
-
+
default:
+
SIMPLE_BAD_ARG_ERROR("function_program", 1, "function");
+
}
+
pop_n_elems(args);
+
push_int(0);
+
}
+
+
+
/*! @decl int random(int max) *! *! This function returns a random number in the range 0 - @[max]-1. *! *! @seealso *! @[random_seed()] */ PIKEFUN mixed random(object o)