e576bb2002-10-11Martin Nilsson /* || 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. */
24ddc71998-03-28Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef ADD_EFUN_H #define ADD_EFUN_H #include "svalue.h" #include "hashtable.h"
cb22561995-10-11Fredrik Hübinette (Hubbe) #include "las.h" /* For OPT_SIDE_EFFECT etc. */
45ee5d1999-02-10Fredrik Hübinette (Hubbe) #include "block_alloc_h.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) typedef int (*docode_fun)(node *n);
6930181996-02-25Fredrik Hübinette (Hubbe) typedef node *(*optimize_fun)(node *n);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
c39e432001-08-02Fredrik Hübinette (Hubbe) #define CALLABLE_DYNAMIC 1
5267b71995-08-09Fredrik Hübinette (Hubbe) struct callable {
45637c2001-04-07Fredrik Hübinette (Hubbe)  PIKE_MEMORY_OBJECT_MEMBERS;
5267b71995-08-09Fredrik Hübinette (Hubbe)  c_fun function;
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *name;
48a6242003-05-31Martin Stjernholm  struct program *prog;
c39e432001-08-02Fredrik Hübinette (Hubbe)  INT16 flags; /* OPT_* */ INT16 internal_flags;
044c621999-04-14Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG INT8 may_return_void;
d9a93b2001-07-01Fredrik Hübinette (Hubbe)  long runs;
1e93882003-08-20Martin Stjernholm  struct callable *prev;
044c621999-04-14Fredrik Hübinette (Hubbe) #endif
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  optimize_fun optimize; docode_fun docode;
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  struct callable *next;
5267b71995-08-09Fredrik Hübinette (Hubbe) };
1e93882003-08-20Martin Stjernholm #ifdef PIKE_DEBUG /* We have a double-linked list in debug mode for identification * purposes. */ extern struct callable *first_callable; #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes begin here */
4ee9222000-12-13Fredrik Hübinette (Hubbe) PMOD_EXPORT struct mapping *get_builtin_constants(void);
06983f1996-09-22Fredrik Hübinette (Hubbe) void low_add_efun(struct pike_string *name, struct svalue *fun);
0929a02002-09-12Marcus Comstedt void low_add_constant(const char *name, struct svalue *fun);
7abd892004-12-30Henrik Grubbström (Grubba) void add_pike_string_constant(const char *name, const char *str, int len);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT void add_global_program(const char *name, struct program *p);
13af4a2005-04-08Henrik Grubbström (Grubba) BLOCK_ALLOC_FILL_PAGES(callable,2);
4ee9222000-12-13Fredrik Hübinette (Hubbe) PMOD_EXPORT struct callable *low_make_callable(c_fun fun,
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  struct pike_string *name,
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *type,
7e877a2003-04-02Martin Stjernholm  int flags,
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  optimize_fun optimize, docode_fun docode);
4ee9222000-12-13Fredrik Hübinette (Hubbe) PMOD_EXPORT struct callable *make_callable(c_fun fun,
0929a02002-09-12Marcus Comstedt  const char *name, const char *type,
7e877a2003-04-02Martin Stjernholm  int flags,
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  optimize_fun optimize, docode_fun docode);
5d1e952011-11-05Martin Nilsson PMOD_EXPORT void add_efun2(const char *name, c_fun fun, const char *type, int flags, optimize_fun optimize, docode_fun docode); PMOD_EXPORT void add_efun(const char *name, c_fun fun, const char *type, int flags); PMOD_EXPORT void quick_add_efun(const char *name, ptrdiff_t name_length, c_fun fun, const char *type, ptrdiff_t type_length, int flags, optimize_fun optimize, docode_fun docode);
1eb9852008-05-11Martin Stjernholm PMOD_EXPORT void visit_callable (struct callable *c, int action);
d8073b2002-01-27Martin Stjernholm void init_builtin_constants(void);
1c5b342003-03-26Martin Nilsson void exit_builtin_constants(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes end here */
5e83442008-05-11Martin Stjernholm #define visit_callable_ref(C, REF_TYPE) \ visit_ref (pass_callable (C), (REF_TYPE), \ (visit_thing_fn *) &visit_callable, NULL)
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  #include "pike_macros.h"
d17c992002-09-30Henrik Grubbström (Grubba) #define ADD_EFUN2(NAME,FUN,TYPE,OPT_FLAGS,OPTIMIZE,DOCODE) \
41be1a2002-09-30Henrik Grubbström (Grubba)  quick_add_efun(NAME,CONSTANT_STRLEN(NAME),FUN, \
d17c992002-09-30Henrik Grubbström (Grubba)  TYPE,CONSTANT_STRLEN(TYPE),OPT_FLAGS,OPTIMIZE,DOCODE)
41be1a2002-09-30Henrik Grubbström (Grubba) 
d17c992002-09-30Henrik Grubbström (Grubba) #define ADD_EFUN(NAME,FUN,TYPE,OPT_FLAGS) \ ADD_EFUN2(NAME,FUN,TYPE,OPT_FLAGS,0,0)
91aab41999-12-13Martin Stjernholm  #define ADD_EFUN_DTYPE(NAME,FUN,DTYPE,FLAGS) do { \ DTYPE_START; \ {DTYPE} \ { \ struct pike_string *_t; \ DTYPE_END(_t); \ quick_add_efun(NAME,CONSTANT_STRLEN(NAME),FUN,_t->str,_t->len,FLAGS,0,0); \ free_string(_t); \ } \ } while (0)
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif