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. \*/
5580691996-06-21Fredrik Hübinette (Hubbe) #ifndef PROGRAM_H #define PROGRAM_H
5267b71995-08-09Fredrik Hübinette (Hubbe)  #include <stdarg.h>
afa6941997-01-28Fredrik Hübinette (Hubbe) #include "global.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "types.h"
16a4b01997-06-25Fredrik Hübinette (Hubbe) #include "svalue.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
5580691996-06-21Fredrik Hübinette (Hubbe) #define LFUN___INIT 0 #define LFUN_CREATE 1 #define LFUN_DESTROY 2 #define LFUN_ADD 3 #define LFUN_SUBTRACT 4 #define LFUN_AND 5 #define LFUN_OR 6 #define LFUN_XOR 7 #define LFUN_LSH 8 #define LFUN_RSH 9 #define LFUN_MULTIPLY 10 #define LFUN_DIVIDE 11 #define LFUN_MOD 12 #define LFUN_COMPL 13 #define LFUN_EQ 14 #define LFUN_LT 15 #define LFUN_GT 16 #define LFUN___HASH 17 #define LFUN_CAST 18 #define LFUN_NOT 19
774b061996-08-03Fredrik Hübinette (Hubbe) #define LFUN_INDEX 20 #define LFUN_ASSIGN_INDEX 21
dffa011997-01-15Fredrik Hübinette (Hubbe) #define LFUN_ARROW 22 #define LFUN_ASSIGN_ARROW 23
0683be1997-01-26Fredrik Hübinette (Hubbe) #define LFUN__SIZEOF 24 #define LFUN__INDICES 25 #define LFUN__VALUES 26 #define LFUN_CALL 27
5580691996-06-21Fredrik Hübinette (Hubbe) 
0683be1997-01-26Fredrik Hübinette (Hubbe) #define NUM_LFUNS 28
5580691996-06-21Fredrik Hübinette (Hubbe)  extern char *lfun_names[];
dfa5b31996-12-05Fredrik Hübinette (Hubbe) #ifndef STRUCT_SVALUE_DECLARED #define STRUCT_SVALUE_DECLARED
5267b71995-08-09Fredrik Hübinette (Hubbe) struct svalue;
dfa5b31996-12-05Fredrik Hübinette (Hubbe) #endif #ifndef STRUCT_OBJECT_DECLARED #define STRUCT_OBJECT_DECLARED
5267b71995-08-09Fredrik Hübinette (Hubbe) struct object;
dfa5b31996-12-05Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  /* I need: * a) one type that can point to a callable function. * (C function, or object->fun) * This can for instance be an svalue. * * b) one type that once the object/program is known can point
06983f1996-09-22Fredrik Hübinette (Hubbe)  * to the C/PIKE function body.
5267b71995-08-09Fredrik Hübinette (Hubbe)  * * c) A number of flags to send to 'add_simul_efun' to specify side effects * and such. */ /* * Max program dimensions:
5580691996-06-21Fredrik Hübinette (Hubbe)  * 2^16 functions + global variables
5267b71995-08-09Fredrik Hübinette (Hubbe)  * 2^16 inherits
06983f1996-09-22Fredrik Hübinette (Hubbe)  * 2^16 arguments to pike functions
5580691996-06-21Fredrik Hübinette (Hubbe)  * 2^32 efuns
5267b71995-08-09Fredrik Hübinette (Hubbe)  * 2^8 local variables (and arguments) */ union idptr { void (*c_fun)(INT32); INT32 offset; };
06983f1996-09-22Fredrik Hübinette (Hubbe) #define IDENTIFIER_PIKE_FUNCTION 1
5267b71995-08-09Fredrik Hübinette (Hubbe) #define IDENTIFIER_C_FUNCTION 2 #define IDENTIFIER_FUNCTION 3 #define IDENTIFIER_VARARGS 4
d2c6081996-11-07Fredrik Hübinette (Hubbe) #define IDENTIFIER_CONSTANT 8 #define IDENTIFIER_IS_FUNCTION(X) ((X) & IDENTIFIER_FUNCTION) #define IDENTIFIER_IS_CONSTANT(X) ((X) & IDENTIFIER_CONSTANT) #define IDENTIFIER_IS_VARIABLE(X) (!((X) & (IDENTIFIER_FUNCTION | IDENTIFIER_CONSTANT)))
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct identifier {
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *name; struct pike_string *type;
5267b71995-08-09Fredrik Hübinette (Hubbe)  unsigned INT16 flags; /* IDENTIFIER_??? */ unsigned INT16 run_time_type; union idptr func; }; /* * in the bytecode, a function starts with: * char num_args * char num_locals * char code[] */ #define ID_STATIC 0x01 #define ID_PRIVATE 0x02 #define ID_NOMASK 0x04 #define ID_PUBLIC 0x08 #define ID_PROTECTED 0x10 #define ID_VARARGS 0x20 #define ID_INLINE 0x40 #define ID_HIDDEN 0x80 /* needed? */ #define ID_INHERITED 0x100 struct reference {
cb22561995-10-11Fredrik Hübinette (Hubbe)  unsigned INT16 inherit_offset; unsigned INT16 identifier_offset;
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT16 flags; /* static, private etc.. */ }; struct inherit { struct program *prog;
16a4b01997-06-25Fredrik Hübinette (Hubbe)  struct pike_string *name;
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT16 inherit_level; /* really needed? */ INT16 identifier_level; INT32 storage_offset; };
16a4b01997-06-25Fredrik Hübinette (Hubbe) /* program parts have been realloced into one block */ #define PROGRAM_OPTIMIZED 1 /* program has gone through pass 1 of compiler, prototypes etc. will * not change from now on */ #define PROGRAM_FIXED 2 /* Program is done and can be cloned */ #define PROGRAM_FINISHED 4 /* Program has gone trouh first compiler pass */ #define PROGRAM_PASS_1_DONE 8
5267b71995-08-09Fredrik Hübinette (Hubbe) struct program { INT32 refs; INT32 id; /* used to identify program in caches */
16a4b01997-06-25Fredrik Hübinette (Hubbe)  INT32 flags;
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT32 storage_needed; /* storage needed in the object struct */ struct program *next; struct program *prev;
16a4b01997-06-25Fredrik Hübinette (Hubbe) 
06983f1996-09-22Fredrik Hübinette (Hubbe)  void (*init)(struct object *); void (*exit)(struct object *);
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifdef DEBUG unsigned INT32 checksum; #endif SIZE_T total_size;
16a4b01997-06-25Fredrik Hübinette (Hubbe)  #define FOO(NUMTYPE,TYPE,NAME) TYPE * NAME ; #include "program_areas.h" #define FOO(NUMTYPE,TYPE,NAME) NUMTYPE num_##NAME ; #include "program_areas.h"
5580691996-06-21Fredrik Hübinette (Hubbe)  INT16 lfuns[NUM_LFUNS];
5267b71995-08-09Fredrik Hübinette (Hubbe) }; #define INHERIT_FROM_PTR(P,X) ((P)->inherits + (X)->inherit_offset) #define PROG_FROM_PTR(P,X) (INHERIT_FROM_PTR(P,X)->prog) #define ID_FROM_PTR(P,X) (PROG_FROM_PTR(P,X)->identifiers+(X)->identifier_offset) #define INHERIT_FROM_INT(P,X) INHERIT_FROM_PTR(P,(P)->identifier_references+(X)) #define PROG_FROM_INT(P,X) PROG_FROM_PTR(P,(P)->identifier_references+(X)) #define ID_FROM_INT(P,X) ID_FROM_PTR(P,(P)->identifier_references+(X))
16a4b01997-06-25Fredrik Hübinette (Hubbe) #define FIND_LFUN(P,N) ((P)->flags & PROGRAM_FIXED?(P)->lfuns[(N)]:find_identifier(lfun_names[(N)],(P)))
5267b71995-08-09Fredrik Hübinette (Hubbe) #define free_program(p) do{ struct program *_=(p); if(!--_->refs) really_free_program(_); }while(0) extern struct object fake_object;
16a4b01997-06-25Fredrik Hübinette (Hubbe) extern struct program *new_program; extern int compiler_pass; #define FOO(NUMTYPE,TYPE,NAME) void add_to_##NAME(TYPE ARG); #include "program_areas.h"
5267b71995-08-09Fredrik Hübinette (Hubbe)  /* Prototypes begin here */
16a4b01997-06-25Fredrik Hübinette (Hubbe) void ins_int(INT32 i, void (*func)(char tmp)); void ins_short(INT16 i, void (*func)(char tmp));
591c0c1997-01-19Fredrik Hübinette (Hubbe) void use_module(struct svalue *s); int find_module_identifier(struct pike_string *ident);
b8cda21997-01-21Fredrik Hübinette (Hubbe) struct program *id_to_program(INT32 id);
16a4b01997-06-25Fredrik Hübinette (Hubbe) void optimize_program(struct program *p); void fixate_program(void); void low_start_new_program(struct program *p, struct pike_string *name, int flags); void start_new_program(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) void really_free_program(struct program *p);
5683de1995-11-06Fredrik Hübinette (Hubbe) void dump_program_desc(struct program *p);
624d091996-02-24Fredrik Hübinette (Hubbe) void check_program(struct program *p);
16a4b01997-06-25Fredrik Hübinette (Hubbe) struct program *end_first_pass(int finish); struct program *end_program(void);
5267b71995-08-09Fredrik Hübinette (Hubbe) SIZE_T add_storage(SIZE_T size);
06983f1996-09-22Fredrik Hübinette (Hubbe) void set_init_callback(void (*init)(struct object *)); void set_exit_callback(void (*exit)(struct object *));
16a4b01997-06-25Fredrik Hübinette (Hubbe) int low_reference_inherited_identifier(int e, struct pike_string *name);
06983f1996-09-22Fredrik Hübinette (Hubbe) int reference_inherited_identifier(struct pike_string *super_name, struct pike_string *function_name); void rename_last_inherit(struct pike_string *n); void do_inherit(struct program *p,INT32 flags, struct pike_string *name); void simple_do_inherit(struct pike_string *s, INT32 flags,struct pike_string *name); int isidentifier(struct pike_string *s); int define_variable(struct pike_string *name, struct pike_string *type,
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT32 flags);
190fb01997-05-10Fredrik Hübinette (Hubbe) int simple_add_variable(char *name, char *type, INT32 flags);
d2c6081996-11-07Fredrik Hübinette (Hubbe) int add_constant(struct pike_string *name, struct svalue *c, INT32 flags);
5c0a101997-02-06Fredrik Hübinette (Hubbe) int simple_add_constant(char *name, struct svalue *c, INT32 flags);
e43ca21996-11-15Fredrik Hübinette (Hubbe) int add_integer_constant(char *name, INT32 i, INT32 flags);
5c0a101997-02-06Fredrik Hübinette (Hubbe) int add_float_constant(char *name, double f, INT32 flags); int add_string_constant(char *name, char *str, INT32 flags); int add_program_constant(char *name, struct program *p, INT32 flags);
c152401997-02-10Fredrik Hübinette (Hubbe) int add_function_constant(char *name, void (*cfun)(INT32), char * type, INT16 flags); int end_class(char *name, INT32 flags);
06983f1996-09-22Fredrik Hübinette (Hubbe) INT32 define_function(struct pike_string *name, struct pike_string *type,
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT16 flags, INT8 function_flags, union idptr *func); struct ff_hash;
06983f1996-09-22Fredrik Hübinette (Hubbe) int find_shared_string_identifier(struct pike_string *name,
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct program *prog); int find_identifier(char *name,struct program *prog);
06983f1996-09-22Fredrik Hübinette (Hubbe) int store_prog_string(struct pike_string *str);
5683de1995-11-06Fredrik Hübinette (Hubbe) int store_constant(struct svalue *foo, int equal);
5267b71995-08-09Fredrik Hübinette (Hubbe) void start_line_numbering(void);
06983f1996-09-22Fredrik Hübinette (Hubbe) void store_linenumber(INT32 current_line, struct pike_string *current_file);
5267b71995-08-09Fredrik Hübinette (Hubbe) char *get_line(unsigned char *pc,struct program *prog,INT32 *linep);
190fb01997-05-10Fredrik Hübinette (Hubbe) void my_yyerror(char *fmt,...) ATTRIBUTE((format(printf,1,2)));
16a4b01997-06-25Fredrik Hübinette (Hubbe) struct program *compile(struct pike_string *prog);
5267b71995-08-09Fredrik Hübinette (Hubbe) void add_function(char *name,void (*cfun)(INT32),char *type,INT16 flags);
16a4b01997-06-25Fredrik Hübinette (Hubbe) void check_all_programs(void); void cleanup_program(void);
c94c371996-03-28Fredrik Hübinette (Hubbe) void gc_mark_program_as_referenced(struct program *p);
16a4b01997-06-25Fredrik Hübinette (Hubbe) void gc_check_all_programs(void); void gc_mark_all_programs(void); void gc_free_all_unreferenced_programs(void);
c3c7031996-12-04Fredrik Hübinette (Hubbe) void count_memory_in_programs(INT32 *num_, INT32 *size_);
16a4b01997-06-25Fredrik Hübinette (Hubbe) void push_compiler_frame(void); void pop_local_variables(int level); void pop_compiler_frame(void);
cff0d71997-03-23Fredrik Hübinette (Hubbe) char *get_storage(struct object *o, struct program *p);
16a4b01997-06-25Fredrik Hübinette (Hubbe) struct program *low_program_from_function(struct program *p, INT32 i); struct program *program_from_function(struct svalue *f); struct find_child_cache_s; int find_child(struct program *parent, struct program *child);
190fb01997-05-10Fredrik Hübinette (Hubbe) void yywarning(char *fmt, ...) ATTRIBUTE((format(printf,1,2)));
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes end here */ #endif