Main Page | Class List | Directories | File List | Class Members | File Members

program.h

Go to the documentation of this file.
00001 /*
00002 || This file is part of Pike. For copyright information see COPYRIGHT.
00003 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
00004 || for more information.
00005 || $Id: program.h,v 1.218 2005/03/15 09:59:28 grubba Exp $
00006 */
00007 
00008 #ifndef PROGRAM_H
00009 #define PROGRAM_H
00010 
00011 #include <stdarg.h>
00012 #include "global.h"
00013 #include "pike_macros.h"
00014 #include "pike_error.h"
00015 #include "svalue.h"
00016 #include "dmalloc.h"
00017 #include "time_stuff.h"
00018 #include "program_id.h"
00019 #include "pike_rusage.h"
00020 #include "block_alloc_h.h"
00021 
00022 /* Needed to support dynamic loading on NT */
00023 PMOD_PROTO extern struct program_state * Pike_compiler;
00024 
00025 /* Compilation flags */
00026 #define COMPILATION_CHECK_FINAL         0x01
00027         /* This flag is set when resolve functions should force the lookup so
00028          * that we don't get a placeholder back. Used for inherits. */
00029 #define COMPILATION_FORCE_RESOLVE       0x02
00030 
00031 /* #define FORCE_RESOLVE_DEBUG */
00032 /* Helper macros for force_resolve */
00033 #ifdef FORCE_RESOLVE_DEBUG
00034 #define DO_IF_FRD(X)  X
00035 #else /* !FORCE_RESOLVE_DEBUG */
00036 #define DO_IF_FRD(X)
00037 #endif /* FORCE_RESOLVE_DEBUG */
00038 #define SET_FORCE_RESOLVE(OLD) do {                                     \
00039     int tmp_ = (OLD) = Pike_compiler->flags;                            \
00040     Pike_compiler->flags |= COMPILATION_FORCE_RESOLVE;                  \
00041     DO_IF_FRD(fprintf(stderr,                                           \
00042                       "Force resolve on. Flags:0x%04x (0x%04x)\n",      \
00043                       Pike_compiler->flags, tmp_));                     \
00044   } while(0)
00045 #define UNSET_FORCE_RESOLVE(OLD) do {                                   \
00046     int tmp_ = (Pike_compiler->flags & ~COMPILATION_FORCE_RESOLVE) |    \
00047       ((OLD) & COMPILATION_FORCE_RESOLVE);                              \
00048     DO_IF_FRD(fprintf(stderr,                                           \
00049                       "Force resolve unset. Flags:0x%04x (0x%04x)\n",   \
00050                       tmp_, Pike_compiler->flags));                     \
00051     Pike_compiler->flags = tmp_;                                        \
00052   } while(0)
00053 
00054 extern struct pike_string *this_program_string;
00055 
00056 #define LFUN___INIT 0
00057 #define LFUN_CREATE 1
00058 #define LFUN_DESTROY 2
00059 #define LFUN_ADD 3
00060 #define LFUN_SUBTRACT 4
00061 #define LFUN_AND 5
00062 #define LFUN_OR 6
00063 #define LFUN_XOR 7
00064 #define LFUN_LSH 8
00065 #define LFUN_RSH 9
00066 #define LFUN_MULTIPLY 10
00067 #define LFUN_DIVIDE 11
00068 #define LFUN_MOD 12
00069 #define LFUN_COMPL 13
00070 #define LFUN_EQ 14
00071 #define LFUN_LT 15
00072 #define LFUN_GT 16
00073 #define LFUN___HASH 17
00074 #define LFUN_CAST 18
00075 #define LFUN_NOT 19
00076 #define LFUN_INDEX 20
00077 #define LFUN_ASSIGN_INDEX 21
00078 #define LFUN_ARROW 22
00079 #define LFUN_ASSIGN_ARROW 23
00080 #define LFUN__SIZEOF 24
00081 #define LFUN__INDICES 25
00082 #define LFUN__VALUES 26
00083 #define LFUN_CALL 27
00084 #define LFUN_RADD 28
00085 #define LFUN_RSUBTRACT 29
00086 #define LFUN_RAND 30
00087 #define LFUN_ROR 31
00088 #define LFUN_RXOR 32
00089 #define LFUN_RLSH 33
00090 #define LFUN_RRSH 34
00091 #define LFUN_RMULTIPLY 35
00092 #define LFUN_RDIVIDE 36
00093 #define LFUN_RMOD 37
00094 #define LFUN_ADD_EQ 38
00095 #define LFUN__IS_TYPE 39
00096 #define LFUN__SPRINTF 40
00097 #define LFUN__EQUAL 41
00098 #define LFUN__M_DELETE 42
00099 #define LFUN__GET_ITERATOR 43
00100 #define LFUN_RANGE 44
00101 
00102 #define NUM_LFUNS 45
00103 
00104 /* NOTE: After this point there are only fake lfuns.
00105  *       ie use low_find_lfun(), and NOT FIND_LFUN()!
00106  */
00107 #define LFUN__SEARCH 45
00108 
00109 extern const char *const lfun_names[];
00110 
00111 extern struct pike_string *lfun_strings[];
00112 
00113 #ifndef STRUCT_NODE_S_DECLARED
00114 #define STRUCT_NODE_S_DECLARED
00115 struct node_s;
00116 typedef struct node_s node;
00117 #endif
00118 
00119 #ifndef STRUCT_OBJECT_DECLARED
00120 #define STRUCT_OBJECT_DECLARED
00121 struct object;
00122 #endif
00123 
00124 #define STRUCT
00125 #include "compilation.h"
00126 
00127 #define EXTERN
00128 #include "compilation.h"
00129 
00130 /* Byte-code method identification. */
00131 #define PIKE_BYTECODE_PORTABLE  -1      /* Only used by the codec. */
00132 #define PIKE_BYTECODE_DEFAULT   0
00133 #define PIKE_BYTECODE_GOTO      1
00134 #define PIKE_BYTECODE_SPARC     2
00135 #define PIKE_BYTECODE_IA32      3
00136 #define PIKE_BYTECODE_PPC32     4
00137 
00138 #if PIKE_BYTECODE_METHOD == PIKE_BYTECODE_IA32
00139 #define PIKE_OPCODE_T unsigned INT8
00140 #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_SPARC
00141 #define PIKE_OPCODE_T unsigned INT32
00142 #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_PPC32
00143 #define PIKE_OPCODE_T unsigned INT32
00144 #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_GOTO
00145 #define PIKE_OPCODE_T void *
00146 #define PIKE_INSTR_T void *
00147 #else
00148 #define PIKE_OPCODE_T unsigned INT8
00149 #endif
00150 
00151 #ifndef PIKE_INSTR_T
00152 /* The type for an opcode instruction identifier (not packed). In all
00153  * cases but PIKE_BYTECODE_GOTO, this is n - F_OFFSET where n is the
00154  * number in the Pike_opcodes enum. */
00155 #define PIKE_INSTR_T unsigned int
00156 #endif
00157 
00158 /* I need:
00159  * a) one type that can point to a callable function.
00160  *    (C function, or object->fun)
00161  * This can for instance be an svalue.
00162  *
00163  * b) one type that once the object/program is known can point
00164  *    to the C/PIKE function body.
00165  *
00166  * c) A number of flags to send to 'add_simul_efun' to specify side effects
00167  *    and such.
00168  */
00169 
00170 
00171 /*
00172  * Max program dimensions:
00173  * 2^16 functions + global variables
00174  * 2^16 inherits
00175  * 2^16 arguments to pike functions
00176  * 2^32 efuns
00177  * 2^8 local variables (and arguments)
00178  */
00179 
00180 union idptr
00181 {
00182   /* C function pointer. */
00183   void (*c_fun)(INT32);
00184 
00185   /* For variables: Offset of the variable in the storage pointed to
00186    * by inherit.storage_offset in the struct inherit that corresponds
00187    * to the identifier. See LOW_GET_GLOBAL and GET_GLOBAL. The stored
00188    * variable may be either a normal or a short svalue, depending on
00189    * identifier.run_time_type.
00190    *
00191    * For constants: Offset of the struct program_constant in
00192    * program.constants in the program pointed to by prog in the struct
00193    * inherit that corresponds to the identifier.
00194    *
00195    * For pike functions: Offset to the start of the function in
00196    * program.program in the program pointed to by prog in the struct
00197    * inherit that corresponds to the identifier. Or -1 if a prototype.
00198    */
00199   ptrdiff_t offset;
00200 };
00201 
00202 #define IDENTIFIER_VARIABLE 0
00203 #define IDENTIFIER_PIKE_FUNCTION 1
00204 #define IDENTIFIER_C_FUNCTION 2
00205 #define IDENTIFIER_FUNCTION 3
00206 #define IDENTIFIER_CONSTANT 4
00207 #define IDENTIFIER_TYPE_MASK 7
00208 
00209 #define IDENTIFIER_VARARGS 8    /* Used for functions only. */
00210 #define IDENTIFIER_NO_THIS_REF 8 /* Used for variables only: Don't count refs to self. */
00211 #define IDENTIFIER_HAS_BODY 16  /* Function has a body (set already in pass 1). */
00212 #define IDENTIFIER_SCOPED 32   /* This is used for local functions only */
00213 #define IDENTIFIER_SCOPE_USED 64 /* contains scoped local functions */
00214 #define IDENTIFIER_ALIAS 128   /* This identifier is an alias. */
00215 
00216 #define IDENTIFIER_IS_FUNCTION(X) ((X) & IDENTIFIER_FUNCTION)
00217 #define IDENTIFIER_IS_PIKE_FUNCTION(X) ((X) & IDENTIFIER_PIKE_FUNCTION)
00218 #define IDENTIFIER_IS_C_FUNCTION(X) ((X) & IDENTIFIER_C_FUNCTION)
00219 #define IDENTIFIER_IS_CONSTANT(X) ((X) & IDENTIFIER_CONSTANT)
00220 #define IDENTIFIER_IS_VARIABLE(X) (!((X) & IDENTIFIER_TYPE_MASK))
00221 #define IDENTIFIER_IS_ALIAS(X)  ((X) & IDENTIFIER_ALIAS)
00222 
00223 #define IDENTIFIER_MASK 255
00224 
00225 /*
00226  * Every constant, class, function and variable
00227  * gets exactly one of these.
00228  */
00229 struct identifier
00230 {
00231   struct pike_string *name;
00232   struct pike_type *type;
00233   unsigned INT8 identifier_flags;       /* IDENTIFIER_??? */
00234   unsigned INT8 run_time_type;          /* PIKE_T_??? */
00235   unsigned INT16 opt_flags;             /* OPT_??? */
00236 #ifdef PROFILING
00237   unsigned INT32 num_calls;             /* Total number of calls. */
00238   cpu_time_t total_time;                /* Total time with children. */
00239   cpu_time_t self_time;                 /* Total time excluding children. */
00240 #endif /* PROFILING */
00241   union idptr func;
00242 };
00243 
00244 /*
00245  * This is used to store constants, both
00246  * inline constants and those defined explicitly with 
00247  * the constant keyword.
00248  */
00249 struct program_constant
00250 {
00251   struct svalue sval;   /* Value. */
00252   ptrdiff_t offset;     /* Offset in identifiers to initialization function. */
00253 };
00254 
00255 /*
00256  * in the bytecode, a function starts with:
00257  * char num_args
00258  * char num_locals
00259  * char code[]
00260  */
00261 
00262 #define ID_STATIC          0x01 /* Symbol is not visible by indexing */
00263 #define ID_PRIVATE         0x02 /* Symbol is not visible by inherit */
00264 #define ID_NOMASK          0x04 /* Symbol may not be overloaded */
00265 #define ID_PUBLIC          0x08 /* Anti private */
00266 #define ID_PROTECTED       0x10 /* Not currently used at all */
00267 #define ID_INLINE          0x20 /* Same as local */
00268 #define ID_HIDDEN          0x40 /* Symbols that are private and inherited one step later */
00269 #define ID_INHERITED       0x80 /* Symbol is inherited */
00270 #define ID_OPTIONAL       0x100 /* Symbol is not required by the interface */
00271 #define ID_EXTERN         0x200 /* Symbol is defined later */
00272 #define ID_VARIANT        0x400 /* Function is overloaded by argument. */
00273 #define ID_ALIAS          0x800 /* Variable is an overloaded alias. */
00274 
00275 #define ID_MODIFIER_MASK 0x0fff
00276 
00277 #define ID_STRICT_TYPES  0x8000 /* #pragma strict_types */
00278 #define ID_SAVE_PARENT  0x10000 /* #pragma save_parent */
00279 #define ID_DONT_SAVE_PARENT 0x20000 /* #pragma dont_save_parent */
00280 
00281 
00282 /*
00283  * All identifiers in this program
00284  * and all identifiers in inherited programs
00285  * need to have a 'struct reference' in this
00286  * program. When we overload a function, we simply
00287  * change the reference to point to the new 'struct identifier'.
00288  *
00289  * When an identifier is represented as an integer, it's typically the
00290  * offset of the corresponding struct reference in
00291  * program.identifier_references.
00292  */
00293 struct reference
00294 {
00295   /* Offset of the struct inherit in program.inherits for the program
00296    * that the struct identifier is in. See INHERIT_FROM_PTR and
00297    * INHERIT_FROM_INT. */
00298   unsigned INT16 inherit_offset;
00299 
00300   /* Offset of the struct identifier in program.identifiers in the
00301    * program pointed to by the struct inherit through inherit_offset
00302    * above. See ID_FROM_PTR and ID_FROM_INT. */
00303   unsigned INT16 identifier_offset;
00304 
00305   /* ID_* flags - static, private etc.. */
00306   INT16 id_flags;
00307 };
00308 
00309 /* Magic value used as identifier reference integer to refer to this. */
00310 #define IDREF_MAGIC_THIS -1
00311 
00312 /* Magic values in inherit.parent_offset; see below. */
00313 #define OBJECT_PARENT -18
00314 #define INHERIT_PARENT -17
00315 
00316 /*
00317  * Each program has an array of these,
00318  * the first entry points to itself, the
00319  * rest are from inherited programs.
00320  * Note that when a program is inherited,
00321  * all 'struct inherit' from that program are
00322  * copied, so the whole tree of inherits is
00323  * represented.
00324  */
00325 struct inherit
00326 {
00327   /* The depth of the inherited program in this program. I.e. the
00328    * number of times the program has been inherited, directly or
00329    * indirectly.
00330    *
00331    * Note that the struct inherit for the program that directly
00332    * inherited the program represented by this struct inherit can be
00333    * found by going backwards in program.inherits from this struct
00334    * until one is found with an inherit_level less than this one. */
00335   INT16 inherit_level;
00336 
00337   /* All the identifier references in the inherited program has been
00338    * copied to this program with the first one at this offset. */
00339   INT16 identifier_level;
00340 
00341   /* The index of the identifier reference in the parent program for
00342    * the identifier from which this inherit was done. -1 if there's no
00343    * such thing. It's always -1 in the inherit struct for the top
00344    * level program. */
00345   INT16 parent_identifier;
00346 
00347   /* Describes how to find the parent object for the external
00348    * identifier references associated with this inherit:
00349    *
00350    * OBJECT_PARENT: Follow the object parent, providing
00351    *   PROGRAM_USES_PARENT is set in the program containing this
00352    *   inherit. See PARENT_INFO. This is used for external references
00353    *   in the top level program (i.e. the one containing the inherit
00354    *   table).
00355    *
00356    * INHERIT_PARENT: Follow the parent pointer in this inherit. This
00357    *   is used when finished programs with parent objects are
00358    *   inherited.
00359    *
00360    * A non-negative integer: The parent is found by following this
00361    *   number of parent pointers in the program that directly
00362    *   inherited the program in this inherit, i.e. in the closest
00363    *   lower level inherit. This is used when a program is inherited
00364    *   whose parent is still being compiled, so it's parent object is
00365    *   fake. That implies that that program also contains the current
00366    *   program on some level, and that level is stored here. An
00367    *   example:
00368    *
00369    *     class A {
00370    *       class B {}
00371    *       class C {
00372    *         class D {
00373    *           inherit B;
00374    *         }
00375    *       }
00376    *     }
00377    *
00378    *   The parent program of B is A, which is still being compiled
00379    *   when B is inherited in D, so it has a fake object. A is also
00380    *   the parent of D, but two levels out, and hence 2 is stored in
00381    *   parent_offset.
00382    *
00383    *   Note that parent_offset can be 0:
00384    *
00385    *     class A {
00386    *       class B {}
00387    *       inherit B;
00388    *     }
00389    */
00390   INT16 parent_offset;
00391 
00392   /* The offset of the first entry in prog->identifier_references that
00393    * comes from the program in this inherit. prog is in this case the
00394    * program that directly inherited it, and not the top level
00395    * program. I.e. for inherits on level 1, this is always the same as
00396    * identifier_level.
00397    *
00398    * Are both really necessary? /mast */
00399   size_t identifier_ref_offset;
00400 
00401   /* Offset in object->storage to the start of the storage for the
00402    * variables from the program in this inherit. */
00403   ptrdiff_t storage_offset;
00404 
00405   /* The parent object for the program in this inherit, or NULL if
00406    * there isn't any. */
00407   struct object *parent;
00408 
00409   /* The program for this inherit. */
00410   struct program *prog;
00411 
00412   /* The name of the inherit, if there is any. For nested inherits,
00413    * this can be a string on the form "A::B::C". */
00414   struct pike_string *name;
00415 };
00416 
00417 
00418 /*
00419  * Storage struct for a trampoline object
00420  * (not a part of the program type)
00421  */
00422 struct pike_trampoline
00423 {
00424   struct pike_frame *frame;
00425   INT32 func;
00426 };
00427 
00428 
00429 
00430 /* program parts have been realloced into one block */
00431 #define PROGRAM_OPTIMIZED 1
00432 
00433 /* program has gone through pass 1 of compiler, prototypes etc. will
00434  * not change from now on
00435  */
00436 #define PROGRAM_FIXED 2
00437 
00438 /* Program is done and can be cloned */
00439 #define PROGRAM_FINISHED 4
00440 
00441 /* Program has gone through first compiler pass */
00442 #define PROGRAM_PASS_1_DONE 8
00443 
00444 /* Program will be destructed as soon at it runs out of references.
00445  * Normally only used for mutex lock keys and similar
00446  */
00447 #define PROGRAM_DESTRUCT_IMMEDIATE 0x10
00448 
00449 /* Self explanatory, automatically detected */
00450 #define PROGRAM_HAS_C_METHODS 0x20
00451 
00452 /* Objects created from this program are constant and shareable */
00453 #define PROGRAM_CONSTANT 0x40
00454 
00455 /* Objects have pointers to the parent object. Use LOW_PARENT_INFO or
00456  * PARENT_INFO to extract it. */
00457 #define PROGRAM_USES_PARENT 0x80
00458 
00459 /* Objects should not be destructed even when they only have weak
00460  * references left. */
00461 #define PROGRAM_NO_WEAK_FREE 0x100
00462 
00463 /* Objects should not be destructed by f_destruct(). */
00464 #define PROGRAM_NO_EXPLICIT_DESTRUCT 0x200
00465 
00466 /* Program is in an inconsistant state */
00467 #define PROGRAM_AVOID_CHECK 0x400
00468 
00469 /* Program has not yet been used for compilation */
00470 #define PROGRAM_VIRGIN 0x800
00471 
00472 /* Don't allow the program to be inherited or cloned if there's no
00473  * parent object. Only set if PROGRAM_USES_PARENT is. */
00474 #define PROGRAM_NEEDS_PARENT 0x1000
00475 
00476 /* Indicates that the class is a facet or product_class. */
00477 #define PROGRAM_IS_FACET_CLASS 0x1
00478 #define PROGRAM_IS_PRODUCT_CLASS 0x2
00479 
00480 /* Using define instead of enum allows for ifdefs - Hubbe */
00481 #define PROG_EVENT_INIT 0
00482 #define PROG_EVENT_EXIT 1
00483 #define PROG_EVENT_GC_RECURSE 2
00484 #define PROG_EVENT_GC_CHECK 3
00485 #define NUM_PROG_EVENTS 4
00486 
00487 /* These macros should only be used if (p->flags & PROGRAM_USES_PARENT)
00488  * is true
00489  */
00490 #define LOW_PARENT_INFO(O,P) ((struct parent_info *)(PIKE_OBJ_STORAGE((O)) + (P)->parent_info_storage))
00491 #define PARENT_INFO(O) LOW_PARENT_INFO( (O), (O)->prog)
00492 
00493 /*
00494  * Objects which needs to access their parent
00495  * have to allocate one of these structs in
00496  * the object data area.
00497  * The parent_info_storage member of the program
00498  * struct tells us where in the object to find this
00499  * data.
00500  */
00501 struct parent_info
00502 {
00503   struct object *parent;
00504   INT16 parent_identifier;
00505 };
00506 
00507 struct program
00508 {
00509   PIKE_MEMORY_OBJECT_MEMBERS; /* Must be first */
00510 
00511   INT32 id;             /* used to identify program in caches */
00512   /* storage_needed - storage needed in object struct
00513    * the first inherit[0].storage_offset bytes are not used and are
00514    * subtracted when inheriting.
00515    */
00516   ptrdiff_t storage_needed; /* storage needed in the object struct */
00517   ptrdiff_t xstorage; /* Non-inherited storage */
00518   ptrdiff_t parent_info_storage;
00519 
00520   INT16 flags;          /* PROGRAM_* */
00521   unsigned INT8 alignment_needed;
00522   struct timeval timestamp;
00523 
00524   struct program *next;
00525   struct program *prev;
00526   struct program *parent;
00527   
00528   node *(*optimize)(node *n);
00529 
00530   void (*event_handler)(int);
00531 #ifdef PIKE_DEBUG
00532   unsigned INT32 checksum;
00533 #endif
00534 #ifdef PROFILING
00535   unsigned INT32 num_clones;
00536 #endif /* PROFILING */
00537 
00538   size_t total_size;
00539 
00540 #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) TYPE * NAME ;
00541 #include "program_areas.h"
00542 
00543 #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) NUMTYPE PIKE_CONCAT(num_,NAME) ;
00544 #include "program_areas.h"
00545   
00546   INT16 lfuns[NUM_LFUNS];
00547 
00548   /* Facet related stuff */
00549   INT16 facet_class;   /* PROGRAM_IS_X_CLASS (X=FACET/PRODUCT) */
00550   INT32 facet_index;   /* Index to the facet this facet class belongs to */
00551   struct object *facet_group;
00552 };
00553 
00554 #if 0
00555 static INLINE int CHECK_IDREF_RANGE (int x, const struct program *p)
00556 {
00557   if (x < 0 || x >= p->num_identifier_references)
00558     debug_fatal ("Identifier reference index %d out of range 0..%d\n", x,
00559                  p->num_identifier_references - 1);
00560   return x;
00561 }
00562 #else
00563 #define CHECK_IDREF_RANGE(X, P) (X)
00564 #endif
00565 
00566 #define PTR_FROM_INT(P, X)      ((P)->identifier_references + \
00567                                  CHECK_IDREF_RANGE((X), (P)))
00568 
00569 #define INHERIT_FROM_PTR(P,X) (dmalloc_touch(struct program *,(P))->inherits + (X)->inherit_offset)
00570 #define PROG_FROM_PTR(P,X) (dmalloc_touch(struct program *,INHERIT_FROM_PTR(P,X)->prog))
00571 #define ID_FROM_PTR(P,X) (PROG_FROM_PTR(P,X)->identifiers+(X)->identifier_offset)
00572 #define INHERIT_FROM_INT(P,X) INHERIT_FROM_PTR(P, PTR_FROM_INT(P, X))
00573 #define PROG_FROM_INT(P,X) PROG_FROM_PTR(P, PTR_FROM_INT(P, X))
00574 #define ID_FROM_INT(P,X) ID_FROM_PTR(P, PTR_FROM_INT(P, X))
00575 
00576 #define FIND_LFUN(P,N) ( dmalloc_touch(struct program *,(P))->flags & PROGRAM_FIXED?((P)->lfuns[(N)]):low_find_lfun((P), (N)) )
00577 #define QUICK_FIND_LFUN(P,N) (dmalloc_touch(struct program *,(P))->lfuns[N])
00578 
00579 #ifdef DO_PIKE_CLEANUP
00580 extern int gc_external_refs_zapped;
00581 void gc_check_zapped (void *a, TYPE_T type, const char *file, int line);
00582 #endif
00583 
00584 #define free_program(p) do{                                             \
00585     struct program *_=(p);                                              \
00586     debug_malloc_touch(_);                                              \
00587     DO_IF_DEBUG (                                                       \
00588       DO_IF_PIKE_CLEANUP (                                              \
00589         if (gc_external_refs_zapped)                                    \
00590           gc_check_zapped (_, PIKE_T_PROGRAM, __FILE__, __LINE__)));    \
00591     if(!sub_ref(_))                                                     \
00592       really_free_program(_);                                           \
00593   }while(0)
00594 
00595 BLOCK_ALLOC_FILL_PAGES(program, n/a);
00596 
00597 
00598 extern struct object *error_handler;
00599 extern struct object *compat_handler;
00600 
00601 extern struct program *first_program;
00602 extern struct program *null_program;
00603 extern struct program *pike_trampoline_program;
00604 extern struct program *gc_internal_program;
00605 extern struct program *placeholder_program;
00606 extern struct object *placeholder_object;
00607 
00608 extern int compilation_depth;
00609 
00610 /* Flags for identifier finding... */
00611 #define SEE_STATIC 1
00612 #define SEE_PRIVATE 2
00613 
00614 
00615 #define COMPILER_IN_CATCH 1
00616 
00617 #define ADD_STORAGE(X) low_add_storage(sizeof(X), ALIGNOF(X),0)
00618 
00619 #define STORAGE_NEEDED(X) ((X)->storage_needed - (X)->inherits[0].storage_offset)
00620 
00621 #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) void PIKE_CONCAT(add_to_,NAME(ARGTYPE ARG));
00622 #include "program_areas.h"
00623 
00624 typedef int supporter_callback (void *, int);
00625 struct Supporter
00626 {
00627 #ifdef PIKE_DEBUG
00628   int magic;
00629 #endif
00630   struct Supporter *previous;
00631   struct Supporter *depends_on;
00632   struct Supporter *dependants;
00633   struct Supporter *next_dependant;
00634   supporter_callback *fun;
00635   void *data;
00636   struct program *prog;
00637 };
00638 
00639 
00640 
00641 /* Prototypes begin here */
00642 void ins_int(INT32 i, void (*func)(char tmp));
00643 void ins_short(int i, void (*func)(char tmp));
00644 void add_relocated_int_to_program(INT32 i);
00645 void use_module(struct svalue *s);
00646 void unuse_modules(INT32 howmany);
00647 node *find_module_identifier(struct pike_string *ident,
00648                              int see_inherit);
00649 node *resolve_identifier(struct pike_string *ident);
00650 node *program_magic_identifier (struct program_state *state,
00651                                 int state_depth, int inherit_num,
00652                                 struct pike_string *ident,
00653                                 int colon_colon_ref);
00654 struct program *parent_compilation(int level);
00655 struct program *id_to_program(INT32 id);
00656 void optimize_program(struct program *p);
00657 void fsort_program_identifier_index(unsigned short *start,
00658                                     unsigned short *end,
00659                                     struct program *p);
00660 struct pike_string *find_program_name(struct program *p, INT32 *line);
00661 int override_identifier (struct reference *ref, struct pike_string *name);
00662 void fixate_program(void);
00663 struct program *low_allocate_program(void);
00664 void low_start_new_program(struct program *p,
00665                            int pass,
00666                            struct pike_string *name,
00667                            int flags,
00668                            int *idp);
00669 PMOD_EXPORT void debug_start_new_program(int line, const char *file);
00670 void dump_program_desc(struct program *p);
00671 int sizeof_variable(int run_time_type);
00672 void dump_program_tables (struct program *p, int indent);
00673 void check_program(struct program *p);
00674 struct program *end_first_pass(int finish);
00675 PMOD_EXPORT struct program *debug_end_program(void);
00676 PMOD_EXPORT size_t low_add_storage(size_t size, size_t alignment,
00677                                    ptrdiff_t modulo_orig);
00678 PMOD_EXPORT void set_init_callback(void (*init_callback)(struct object *));
00679 PMOD_EXPORT void set_exit_callback(void (*exit_callback)(struct object *));
00680 PMOD_EXPORT void set_gc_recurse_callback(void (*m)(struct object *));
00681 PMOD_EXPORT void set_gc_check_callback(void (*m)(struct object *));
00682 void pike_set_prog_event_callback(void (*cb)(int));
00683 void pike_set_prog_optimize_callback(node *(*opt)(node *));
00684 int really_low_reference_inherited_identifier(struct program_state *q,
00685                                               int e,
00686                                               int i);
00687 int low_reference_inherited_identifier(struct program_state *q,
00688                                        int e,
00689                                        struct pike_string *name,
00690                                        int flags);
00691 int find_inherit(struct program *p, struct pike_string *name);
00692 node *reference_inherited_identifier(struct pike_string *super_name,
00693                                      struct pike_string *function_name);
00694 void rename_last_inherit(struct pike_string *n);
00695 void low_inherit(struct program *p,
00696                  struct object *parent,
00697                  int parent_identifier,
00698                  int parent_offset,
00699                  INT32 flags,
00700                  struct pike_string *name);
00701 PMOD_EXPORT void do_inherit(struct svalue *s,
00702                 INT32 flags,
00703                 struct pike_string *name);
00704 void compiler_do_inherit(node *n, INT32 flags, struct pike_string *name);
00705 int call_handle_inherit(struct pike_string *s);
00706 void simple_do_inherit(struct pike_string *s,
00707                        INT32 flags,
00708                        struct pike_string *name);
00709 int isidentifier(struct pike_string *s);
00710 int low_define_variable(struct pike_string *name,
00711                         struct pike_type *type,
00712                         INT32 flags,
00713                         size_t offset,
00714                         INT32 run_time_type);
00715 PMOD_EXPORT int map_variable(const char *name,
00716                  const char *type,
00717                  INT32 flags,
00718                  size_t offset,
00719                  INT32 run_time_type);
00720 PMOD_EXPORT int quick_map_variable(const char *name,
00721                        int name_length,
00722                        size_t offset,
00723                        const char *type,
00724                        int type_length,
00725                        INT32 run_time_type,
00726                        INT32 flags);
00727 int define_variable(struct pike_string *name,
00728                     struct pike_type *type,
00729                     INT32 flags);
00730 PMOD_EXPORT int simple_add_variable(const char *name,
00731                         const char *type,
00732                         INT32 flags);
00733 PMOD_EXPORT int add_constant(struct pike_string *name,
00734                  struct svalue *c,
00735                  INT32 flags);
00736 PMOD_EXPORT int simple_add_constant(const char *name,
00737                         struct svalue *c,
00738                         INT32 flags);
00739 PMOD_EXPORT int add_integer_constant(const char *name,
00740                                      INT_ARG_TYPE i,
00741                                      INT32 flags);
00742 PMOD_EXPORT int quick_add_integer_constant(const char *name,
00743                                            int name_length,
00744                                            INT_ARG_TYPE i,
00745                                            INT32 flags);
00746 PMOD_EXPORT int add_float_constant(const char *name,
00747                                    FLOAT_ARG_TYPE f,
00748                                    INT32 flags);
00749 PMOD_EXPORT int quick_add_float_constant(const char *name,
00750                                          int name_length,
00751                                          FLOAT_ARG_TYPE f,
00752                                          INT32 flags);
00753 PMOD_EXPORT int add_string_constant(const char *name,
00754                                     const char *str,
00755                                     INT32 flags);
00756 PMOD_EXPORT int add_program_constant(const char *name,
00757                          struct program *p,
00758                          INT32 flags);
00759 PMOD_EXPORT int add_object_constant(const char *name,
00760                         struct object *o,
00761                         INT32 flags);
00762 PMOD_EXPORT int add_function_constant(const char *name, void (*cfun)(INT32), const char * type, int flags);
00763 PMOD_EXPORT int debug_end_class(const char *name, ptrdiff_t namelen, INT32 flags);
00764 INT32 define_function(struct pike_string *name,
00765                       struct pike_type *type,
00766                       unsigned flags,
00767                       unsigned function_flags,
00768                       union idptr *func,
00769                       unsigned opt_flags);
00770 int really_low_find_shared_string_identifier(struct pike_string *name,
00771                                              struct program *prog,
00772                                              int flags);
00773 int low_find_lfun(struct program *p, ptrdiff_t lfun);
00774 int lfun_lookup_id(struct pike_string *lfun_name);
00775 int low_find_shared_string_identifier(struct pike_string *name,
00776                                       struct program *prog);
00777 struct ff_hash;
00778 int find_shared_string_identifier(struct pike_string *name,
00779                                   struct program *prog);
00780 PMOD_EXPORT int find_identifier(const char *name,struct program *prog);
00781 int store_prog_string(struct pike_string *str);
00782 int store_constant(struct svalue *foo,
00783                    int equal,
00784                    struct pike_string *constant_name);
00785 struct array *program_indices(struct program *p);
00786 struct array *program_values(struct program *p);
00787 void program_index_no_free(struct svalue *to, struct program *p,
00788                            struct svalue *ind);
00789 int get_small_number(char **q);
00790 void ext_store_program_line (struct program *prog, INT32 line, struct pike_string *file);
00791 void start_line_numbering(void);
00792 void store_linenumber(INT32 current_line, struct pike_string *current_file);
00793 PMOD_EXPORT struct pike_string *low_get_program_line(struct program *prog,
00794                                                      INT32 *linep);
00795 PMOD_EXPORT struct pike_string *get_program_line(struct program *prog,
00796                                                  INT32 *linep);
00797 PMOD_EXPORT char *low_get_program_line_plain (struct program *prog, INT32 *linep,
00798                                               int malloced);
00799 PMOD_EXPORT struct pike_string *low_get_line(PIKE_OPCODE_T *pc,
00800                                              struct program *prog, INT32 *linep);
00801 PMOD_EXPORT char *low_get_line_plain (PIKE_OPCODE_T *pc, struct program *prog,
00802                                       INT32 *linep, int malloced);
00803 PMOD_EXPORT struct pike_string *get_line(PIKE_OPCODE_T *pc,
00804                                          struct program *prog, INT32 *linep);
00805 PMOD_EXPORT struct pike_string *low_get_function_line (struct object *o,
00806                                                        int fun, INT32 *linep);
00807 void va_yyerror(const char *fmt, va_list args);
00808 void my_yyerror(const char *fmt,...);
00809 struct pike_string *format_exception_for_error_msg (struct svalue *thrown);
00810 void handle_compile_exception (const char *yyerror_fmt, ...);
00811 struct supporter_marker;
00812 void verify_supporters(void);
00813 void init_supporter(struct Supporter *s,
00814                     supporter_callback *fun,
00815                     void *data);
00816 int unlink_current_supporter(struct Supporter *c);
00817 int call_dependants(struct Supporter *s, int finish);
00818 int report_compiler_dependency(struct program *p);
00819 struct compilation;
00820 void run_pass2(struct compilation *c);
00821 struct program *compile(struct pike_string *aprog,
00822                         struct object *ahandler,
00823                         int amajor, int aminor,
00824                         struct program *atarget,
00825                         struct object *aplaceholder);
00826 PMOD_EXPORT int pike_add_function2(const char *name, void (*cfun)(INT32),
00827                                    const char *type, unsigned flags,
00828                                    unsigned opt_flags);
00829 PMOD_EXPORT int quick_add_function(const char *name,
00830                                    int name_length,
00831                                    void (*cfun)(INT32),
00832                                    const char *type,
00833                                    int type_length,
00834                                    unsigned flags,
00835                                    unsigned opt_flags);
00836 void check_all_programs(void);
00837 void placeholder_index(INT32 args);
00838 void init_program(void);
00839 void cleanup_program(void);
00840 void gc_mark_program_as_referenced(struct program *p);
00841 void real_gc_cycle_check_program(struct program *p, int weak);
00842 unsigned gc_touch_all_programs(void);
00843 void gc_check_all_programs(void);
00844 void gc_mark_all_programs(void);
00845 void gc_cycle_check_all_programs(void);
00846 void gc_zap_ext_weak_refs_in_programs(void);
00847 size_t gc_free_all_unreferenced_programs(void);
00848 void push_compiler_frame(int lexical_scope);
00849 void low_pop_local_variables(int level);
00850 void pop_local_variables(int level);
00851 void pop_compiler_frame(void);
00852 ptrdiff_t low_get_storage(struct program *o, struct program *p);
00853 PMOD_EXPORT char *get_storage(struct object *o, struct program *p);
00854 struct program *low_program_from_function(struct program *p,
00855                                           INT32 i);
00856 PMOD_EXPORT struct program *program_from_function(const struct svalue *f);
00857 PMOD_EXPORT struct program *program_from_svalue(const struct svalue *s);
00858 struct find_child_cache_s;
00859 int find_child(struct program *parent, struct program *child);
00860 void yywarning(char *fmt, ...);
00861 struct implements_cache_s;
00862 PMOD_EXPORT int implements(struct program *a, struct program *b);
00863 PMOD_EXPORT int is_compatible(struct program *a, struct program *b);
00864 void yyexplain_not_compatible(struct program *a, struct program *b, int flags);
00865 void yyexplain_not_implements(struct program *a, struct program *b, int flags);
00866 PMOD_EXPORT void *parent_storage(int depth);
00867 PMOD_EXPORT void change_compiler_compatibility(int major, int minor);
00868 void make_program_executable(struct program *p);
00869 /* Prototypes end here */
00870 
00871 void really_free_program(struct program *);
00872 void count_memory_in_programs(INT32*,INT32*);
00873 
00874 #ifndef PIKE_USE_MACHINE_CODE
00875 #define make_program_executable(X)
00876 #endif
00877 
00878 #define ADD_FUNCTION(NAME, FUNC, TYPE, FLAGS) \
00879   quick_add_function(NAME, CONSTANT_STRLEN(NAME), FUNC, TYPE,\
00880                      CONSTANT_STRLEN(TYPE), FLAGS, \
00881                      OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND)
00882 
00883 #define ADD_PROTOTYPE(NAME, TYPE, FLAGS) \
00884   ADD_FUNCTION(NAME, 0, TYPE, FLAGS)
00885 
00886 #define ADD_FUNCTION2(NAME, FUNC, TYPE, FLAGS, OPT_FLAGS) \
00887   quick_add_function(NAME, CONSTANT_STRLEN(NAME), FUNC, TYPE,\
00888                      CONSTANT_STRLEN(TYPE), FLAGS, OPT_FLAGS)
00889 
00890 #define ADD_PROTOTYPE2(NAME, TYPE, FLAGS, OPT_FLAGS) \
00891   ADD_FUNCTION2(NAME, 0, TYPE, FLAGS, OPT_FLAGS)
00892 
00893 #define ADD_INT_CONSTANT(NAME, CONST, FLAGS) \
00894   quick_add_integer_constant(NAME, CONSTANT_STRLEN(NAME), CONST, FLAGS)
00895 
00896 #define ADD_FLOAT_CONSTANT(NAME, CONST, FLAGS) \
00897   quick_add_float_constant(NAME, CONSTANT_STRLEN(NAME), CONST, FLAGS)
00898 
00899 #define PIKE_MAP_VARIABLE(NAME, OFFSET, TYPE, RTTYPE, FLAGS) \
00900   quick_map_variable(NAME, CONSTANT_STRLEN(NAME), OFFSET, \
00901                      TYPE, CONSTANT_STRLEN(TYPE), RTTYPE, FLAGS)
00902 
00903 #define MAP_VARIABLE(NAME, TYPE, FLAGS, OFFSET, RTYPE) \
00904   PIKE_MAP_VARIABLE(NAME, OFFSET, TYPE, RTYPE, FLAGS)
00905 
00906 #define ADD_FUNCTION_DTYPE(NAME,FUN,DTYPE,FLAGS) do {           \
00907   DTYPE_START;                                                  \
00908   {DTYPE}                                                       \
00909   {                                                             \
00910     struct pike_string *_t;                                     \
00911     DTYPE_END(_t);                                              \
00912     quick_add_function(NAME, CONSTANT_STRLEN(NAME), FUN,        \
00913                         _t->str, _t->len, FLAGS,                \
00914                        OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND);    \
00915     free_string(_t);                                            \
00916   }                                                             \
00917 } while (0)
00918 
00919 #define pike_add_function(NAME, CFUN, TYPE, FLAGS)      \
00920   pike_add_function2(NAME, CFUN, TYPE, FLAGS,           \
00921                      OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND)
00922 
00923 #ifndef NO_PIKE_SHORTHAND
00924 #define add_function pike_add_function
00925 #endif
00926 
00927 #define ADD_INHERIT(PROGRAM, FLAGS) \
00928   low_inherit((PROGRAM), 0, 0, 0, (FLAGS), 0)
00929 
00930 #define START_NEW_PROGRAM_ID(ID) do { \
00931     start_new_program();  \
00932     Pike_compiler->new_program->id=PIKE_CONCAT3(PROG_,ID,_ID); \
00933   }while(0)
00934 
00935 #ifdef DEBUG_MALLOC
00936 #define end_program() ((struct program *)debug_malloc_pass(debug_end_program()))
00937 #define end_class(NAME, FLAGS) (debug_malloc_touch(Pike_compiler->new_program), debug_end_class(NAME, CONSTANT_STRLEN(NAME), FLAGS))
00938 #else
00939 #define end_class(NAME,FLAGS) debug_end_class(NAME, CONSTANT_STRLEN(NAME), FLAGS)
00940 #define end_program debug_end_program
00941 #endif
00942 
00943 
00944 #define start_new_program() debug_start_new_program(__LINE__,__FILE__)
00945 
00946 #define gc_cycle_check_program(X, WEAK) \
00947   gc_cycle_enqueue((gc_cycle_check_cb *) real_gc_cycle_check_program, (X), (WEAK))
00948 
00949 /* This can be used for backwards compatibility
00950  *  (if added to program.h in Pike 0.6 and Pike 7.0
00951  * -Hubbe
00952  */
00953 #define Pike_new_program Pike_compiler->new_program
00954 
00955 
00956 /* Return true if compat version is equal or less than MAJOR.MINOR */
00957 #define TEST_COMPAT(MAJOR,MINOR) \
00958   (Pike_compiler->compat_major < (MAJOR) ||  \
00959     (Pike_compiler->compat_major == (MAJOR) && \
00960      Pike_compiler->compat_minor <= (MINOR)))
00961 
00962 #endif /* PROGRAM_H */
00963 
00964 /* Kludge... */
00965 #ifndef LAS_H
00966 /* FIXME: Needed for the OPT_??? macros.
00967  * Maybe they should be moved here, since las.h includes this file anyway?
00968  */
00969 #include "las.h"
00970 #endif /* !LAS_H */

Generated on Fri Jul 22 23:44:26 2005 for Pike by  doxygen 1.3.9.1