cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
07513e1996-10-04Fredrik Hübinette (Hubbe) #include "global.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "constants.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "program.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "pike_types.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "stralloc.h" #include "memory.h" #include "interpret.h"
244ce61997-01-26Fredrik Hübinette (Hubbe) #include "mapping.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
c3c7031996-12-04Fredrik Hübinette (Hubbe) static INT32 num_callable=0;
244ce61997-01-26Fredrik Hübinette (Hubbe) static struct mapping *builtin_constants = 0;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
244ce61997-01-26Fredrik Hübinette (Hubbe) struct mapping *get_builtin_constants()
5267b71995-08-09Fredrik Hübinette (Hubbe) {
244ce61997-01-26Fredrik Hübinette (Hubbe)  if(!builtin_constants) builtin_constants=allocate_mapping(20);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
244ce61997-01-26Fredrik Hübinette (Hubbe)  return builtin_constants;
5267b71995-08-09Fredrik Hübinette (Hubbe) }
06983f1996-09-22Fredrik Hübinette (Hubbe) void low_add_efun(struct pike_string *name, struct svalue *fun)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
244ce61997-01-26Fredrik Hübinette (Hubbe)  struct svalue s;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
244ce61997-01-26Fredrik Hübinette (Hubbe)  if(!builtin_constants) builtin_constants=allocate_mapping(20);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
244ce61997-01-26Fredrik Hübinette (Hubbe)  s.type=T_STRING; s.subtype=0; s.u.string=name;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
244ce61997-01-26Fredrik Hübinette (Hubbe)  if(fun) { mapping_insert(builtin_constants, &s, fun); }else{ map_delete(builtin_constants, &s);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
cecf511997-02-06Fredrik Hübinette (Hubbe) void low_add_constant(char *name, struct svalue *fun) { struct pike_string *p; p=make_shared_string(name); low_add_efun(p, fun); free_string(p); } void add_global_program(char *name, struct program *p) { struct svalue s; s.type=T_PROGRAM; s.subtype=0; s.u.program=p; low_add_constant(name, &s); }
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) struct callable *make_callable(c_fun fun, char *name, char *type, INT16 flags, optimize_fun optimize, docode_fun docode)
5267b71995-08-09Fredrik Hübinette (Hubbe) { struct callable *f; f=ALLOC_STRUCT(callable);
c3c7031996-12-04Fredrik Hübinette (Hubbe)  num_callable++;
5267b71995-08-09Fredrik Hübinette (Hubbe)  f->refs=1; f->function=fun; f->name=make_shared_string(name); f->type=parse_type(type); f->flags=flags;
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  f->docode=docode; f->optimize=optimize;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return f; } void really_free_callable(struct callable *fun) { free_string(fun->type); free_string(fun->name); free((char *)fun);
c3c7031996-12-04Fredrik Hübinette (Hubbe)  num_callable--;
5267b71995-08-09Fredrik Hübinette (Hubbe) }
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) void add_efun2(char *name, c_fun fun, char *type, INT16 flags, optimize_fun optimize, docode_fun docode)
5267b71995-08-09Fredrik Hübinette (Hubbe) { struct svalue s;
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *n;
5267b71995-08-09Fredrik Hübinette (Hubbe)  n=make_shared_string(name); s.type=T_FUNCTION;
bdb5091996-09-25Fredrik Hübinette (Hubbe)  s.subtype=FUNCTION_BUILTIN;
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  s.u.efun=make_callable(fun, name, type, flags, optimize, docode);
5267b71995-08-09Fredrik Hübinette (Hubbe)  low_add_efun(n, &s); free_svalue(&s); free_string(n); }
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) void add_efun(char *name, c_fun fun, char *type, INT16 flags) { add_efun2(name,fun,type,flags,0,0); }
5267b71995-08-09Fredrik Hübinette (Hubbe) void cleanup_added_efuns() {
244ce61997-01-26Fredrik Hübinette (Hubbe)  if(builtin_constants)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
244ce61997-01-26Fredrik Hübinette (Hubbe)  free_mapping(builtin_constants); builtin_constants=0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
c3c7031996-12-04Fredrik Hübinette (Hubbe) void count_memory_in_callables(INT32 *num_, INT32 *size_) { *num_=num_callable; *size_=num_callable*sizeof(struct callable); }