pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.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: builtin_functions.c,v 1.627 2007/03/03 21:45:14 nilsson Exp $ + || $Id: builtin_functions.c,v 1.628 2007/03/26 11:13:11 grubba Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"
pike.git/src/builtin_functions.c:2215:    if( !args || Pike_sp[-1].type != T_STRING ||    Pike_sp[-1].u.string->size_shift )    Pike_error( "__parse_pike_type requires a 8bit string as its first argument\n" );    t = parse_type( (char *)STR0(Pike_sp[-1].u.string) );    pop_stack();       push_string(type_to_string(t));    free_type(t);   }    + /*! @decl type __check_call(type arg_type, type fun_type) +  *! +  *! Check whether a function of type @[fun_type] may be called +  *! with a first argument of type @[arg_type]. +  *! +  *! @returns +  *! Returns a continuation type on success. +  *! +  *! Returns @tt{0@} (zero) on failure. +  */ + static void f___check_call(INT32 args) + { +  struct pike_type *res; +  if (args != 2) Pike_error("Bad number of arguments to __check_call().\n"); +  if (Pike_sp[-2].type != PIKE_T_TYPE) { +  Pike_error("Bad argument 1 to __check_call() expected type.\n"); +  } +  if (Pike_sp[-1].type != PIKE_T_TYPE) { +  Pike_error("Bad argument 1 to __check_call() expected type.\n"); +  } +  if (!(res = low_new_check_call(Pike_sp[-2].u.type, +  Pike_sp[-1].u.type, 0))) { +  pop_n_elems(args); +  push_undefined(); +  } else { +  pop_n_elems(args); +  push_type_value(res); +  } + } +  + /*! @decl type __get_return_type(type fun_type) +  *! +  *! Check what a function of the type @[fun_type] will +  *! return if called with no arguments. +  *! +  *! @returns +  *! Returns the type of the returned value on success +  *! +  *! Returns @tt{0@} (zero) on failure. +  */ + static void f___get_return_type(INT32 args) + { +  struct pike_type *res; +  if (args != 1) { +  Pike_error("Bad number of arguments to __get_return_type().\n"); +  } +  if (Pike_sp[-1].type != PIKE_T_TYPE) { +  Pike_error("Bad argument 1 to __get_return_type() expected type.\n"); +  } +  if (!(res = new_get_return_type(Pike_sp[-1].u.type, 0))) { +  pop_n_elems(args); +  push_undefined(); +  } else { +  pop_n_elems(args); +  push_type_value(res); +  } + } +  + /*! @decl type __get_first_arg_type(type fun_type) +  *! +  *! Check if a function of the type @[fun_type] may be called +  *! with an argument, and return the type of that argument. +  *! +  *! @returns +  *! Returns the expected type of the first argument to the function. +  *! +  *! Returns @tt{0@} (zero) if a function of the type @[fun_type] +  *! may not be called with any argument, or if it is not callable. +  */ + static void f___get_first_arg_type(INT32 args) + { +  struct pike_type *res; +  if (args != 1) { +  Pike_error("Bad number of arguments to __get_first_arg_type().\n"); +  } +  if (Pike_sp[-1].type != PIKE_T_TYPE) { +  Pike_error("Bad argument 1 to __get_first_arg_type() expected type.\n"); +  } +  if (!(res = get_first_arg_type(Pike_sp[-1].u.type, 0))) { +  pop_n_elems(args); +  push_undefined(); +  } else { +  pop_n_elems(args); +  push_type_value(res); +  } + } +    /*! @decl mapping (string:mixed) all_constants()    *!    *! Returns a mapping containing all global constants, indexed on the name    *! of the constant, and with the value of the constant as value.    *!    *! @seealso    *! @[add_constant()]    */   PMOD_EXPORT void f_all_constants(INT32 args)   {
pike.git/src/builtin_functions.c:8989:    tFunc(tStr tOr(tInt,tVoid),tStr8), OPT_TRY_OPTIMIZE);      /* function(string(8),int|void:string) */    ADD_EFUN("utf8_to_string", f_utf8_to_string,    tFunc(tStr8 tOr(tInt,tVoid),tStr), OPT_TRY_OPTIMIZE);          ADD_EFUN("__parse_pike_type", f_parse_pike_type,    tFunc(tStr8,tStr8),OPT_TRY_OPTIMIZE);    +  ADD_EFUN("__check_call", f___check_call, +  tFunc(tType(tMix) tType(tCallable), tType(tCallable)), +  OPT_TRY_OPTIMIZE); +  +  /* FIXME: Could have a stricter type. */ +  ADD_EFUN("__get_return_type", f___get_return_type, +  tFunc(tType(tCallable), tType(tMix)), +  OPT_TRY_OPTIMIZE); +  +  /* FIXME: Could have a stricter type. */ +  ADD_EFUN("__get_first_arg_type", f___get_first_arg_type, +  tFunc(tType(tCallable), tType(tMix)), +  OPT_TRY_OPTIMIZE); +    #ifdef HAVE_LOCALTIME      /* function(int:mapping(string:int)) */    ADD_EFUN("localtime",f_localtime,    tFunc(tInt,tMap(tStr,tInt)),OPT_EXTERNAL_DEPEND);   #endif   #ifdef HAVE_GMTIME      /* function(int:mapping(string:int)) */    ADD_EFUN("gmtime",f_gmtime,tFunc(tInt,tMap(tStr,tInt)),OPT_TRY_OPTIMIZE);