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) 
5580691996-06-21Fredrik Hübinette (Hubbe) #ifndef PROGRAM_H #define PROGRAM_H
5267b71995-08-09Fredrik Hübinette (Hubbe) 
afa6941997-01-28Fredrik Hübinette (Hubbe) #include "global.h"
90e9781999-01-31Fredrik Hübinette (Hubbe) #include "pike_macros.h"
7ea7932003-08-03Martin Stjernholm #include "pike_error.h"
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #include "svalue.h"
05590d1998-04-23Fredrik Hübinette (Hubbe) #include "time_stuff.h"
e9ce612001-03-29Per Hedbor #include "program_id.h"
b2630d2004-05-20Henrik Grubbström (Grubba) #include "pike_rusage.h"
44e3402013-10-09Arne Goedeke #include "block_allocator.h"
2a3bfa2017-01-26Henrik Grubbström (Grubba) #include "string_builder.h"
bad5162000-06-23Fredrik Hübinette (Hubbe) 
1f21332000-07-28Fredrik Hübinette (Hubbe) /* Needed to support dynamic loading on NT */
3a10112006-07-05Martin Stjernholm PMOD_EXPORT extern struct program_state * Pike_compiler;
1f21332000-07-28Fredrik Hübinette (Hubbe) 
cd2be32004-03-13Henrik Grubbström (Grubba) /* Compilation flags */ #define COMPILATION_CHECK_FINAL 0x01 /* This flag is set when resolve functions should force the lookup so * that we don't get a placeholder back. Used for inherits. */ #define COMPILATION_FORCE_RESOLVE 0x02
f1ad632004-03-16Henrik Grubbström (Grubba) /* #define FORCE_RESOLVE_DEBUG */ /* Helper macros for force_resolve */ #ifdef FORCE_RESOLVE_DEBUG #define DO_IF_FRD(X) X #else /* !FORCE_RESOLVE_DEBUG */ #define DO_IF_FRD(X) #endif /* FORCE_RESOLVE_DEBUG */ #define SET_FORCE_RESOLVE(OLD) do { \ int tmp_ = (OLD) = Pike_compiler->flags; \ Pike_compiler->flags |= COMPILATION_FORCE_RESOLVE; \ DO_IF_FRD(fprintf(stderr, \ "Force resolve on. Flags:0x%04x (0x%04x)\n", \ Pike_compiler->flags, tmp_)); \ } while(0) #define UNSET_FORCE_RESOLVE(OLD) do { \ int tmp_ = (Pike_compiler->flags & ~COMPILATION_FORCE_RESOLVE) | \ ((OLD) & COMPILATION_FORCE_RESOLVE); \ DO_IF_FRD(fprintf(stderr, \ "Force resolve unset. Flags:0x%04x (0x%04x)\n", \ tmp_, Pike_compiler->flags)); \ Pike_compiler->flags = tmp_; \ } while(0)
9e26861999-12-31Martin Stjernholm extern struct pike_string *this_program_string;
6a22502014-09-30Per Hedbor extern struct pike_string *this_string;
cbe1302017-01-06Henrik Grubbström (Grubba) extern struct pike_string *args_string;
9e26861999-12-31Martin Stjernholm 
94d66b2008-05-24Henrik Grubbström (Grubba) /* Common compiler subsystems */ extern struct pike_string *parser_system_string; extern struct pike_string *type_check_system_string;
e6a5562016-06-20Per Hedbor enum LFUN { LFUN___INIT, LFUN_CREATE, LFUN_DESTROY, LFUN_ADD, LFUN_SUBTRACT, LFUN_AND, LFUN_OR, LFUN_XOR, LFUN_LSH, LFUN_RSH, LFUN_MULTIPLY, LFUN_DIVIDE, LFUN_MOD, LFUN_COMPL, LFUN_EQ, LFUN_LT, LFUN_GT, LFUN___HASH, LFUN_CAST, LFUN_NOT, LFUN_INDEX, LFUN_ASSIGN_INDEX, LFUN_ARROW, LFUN_ASSIGN_ARROW, LFUN__SIZEOF, LFUN__INDICES, LFUN__VALUES, LFUN_CALL, LFUN_RADD, LFUN_RSUBTRACT, LFUN_RAND, LFUN_ROR, LFUN_RXOR, LFUN_RLSH, LFUN_RRSH, LFUN_RMULTIPLY, LFUN_RDIVIDE, LFUN_RMOD, LFUN_ADD_EQ, LFUN__IS_TYPE, LFUN__SPRINTF, LFUN__EQUAL, LFUN__M_DELETE, LFUN__GET_ITERATOR, LFUN_RANGE, NUM_LFUNS,
142c802003-09-04Henrik Grubbström (Grubba) /* NOTE: After this point there are only fake lfuns. */
e6a5562016-06-20Per Hedbor  LFUN__SEARCH = NUM_LFUNS, LFUN__TYPES, LFUN__SERIALIZE, LFUN__DESERIALIZE, LFUN__SIZE_OBJECT, LFUN__RANDOM, LFUN_POW, LFUN_RPOW, LFUN__SQRT, };
142c802003-09-04Henrik Grubbström (Grubba) 
ebf5bb2004-09-18Per Hedbor extern const char *const lfun_names[];
5580691996-06-21Fredrik Hübinette (Hubbe) 
286afb2001-02-05Henrik Grubbström (Grubba) extern struct pike_string *lfun_strings[];
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #ifndef STRUCT_NODE_S_DECLARED #define STRUCT_NODE_S_DECLARED struct node_s;
e772e42003-11-14Martin Stjernholm typedef struct node_s node;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #endif
dfa5b31996-12-05Fredrik Hübinette (Hubbe) #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) 
3a8dd02006-07-09Marcus Comstedt #undef EXTERN #undef STRUCT #undef PUSH #undef POP #undef DECLARE
e772e42003-11-14Martin Stjernholm #define STRUCT #include "compilation.h" #define EXTERN #include "compilation.h"
aeaab72002-04-08Martin Stjernholm /* Byte-code method identification. */
2213702003-11-25Henrik Grubbström (Grubba) #define PIKE_BYTECODE_PORTABLE -1 /* Only used by the codec. */
aeaab72002-04-08Martin Stjernholm #define PIKE_BYTECODE_DEFAULT 0 #define PIKE_BYTECODE_GOTO 1 #define PIKE_BYTECODE_SPARC 2 #define PIKE_BYTECODE_IA32 3
d995a22006-04-27Tor Edvardsson #define PIKE_BYTECODE_PPC32 4 #define PIKE_BYTECODE_AMD64 5
a00f6f2007-04-01Marcus Comstedt #define PIKE_BYTECODE_PPC64 6
c2da762014-12-06Tobias S. Josefowitz #define PIKE_BYTECODE_ARM32 7
3ea5d12016-08-15Marcus Comstedt #define PIKE_BYTECODE_ARM64 8
aeaab72002-04-08Martin Stjernholm 
d9a40a2005-11-19Henrik Grubbström (Grubba) #ifndef PIKE_BYTECODE_METHOD #error PIKE_BYTECODE_METHOD not set. #endif
d8e19a2002-04-07Martin Stjernholm #if PIKE_BYTECODE_METHOD == PIKE_BYTECODE_IA32 #define PIKE_OPCODE_T unsigned INT8
d995a22006-04-27Tor Edvardsson #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_AMD64 #define PIKE_OPCODE_T unsigned INT8
d8e19a2002-04-07Martin Stjernholm #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_SPARC #define PIKE_OPCODE_T unsigned INT32 #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_PPC32 #define PIKE_OPCODE_T unsigned INT32
a00f6f2007-04-01Marcus Comstedt #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_PPC64 #define PIKE_OPCODE_T unsigned INT32
d8e19a2002-04-07Martin Stjernholm #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_GOTO #define PIKE_OPCODE_T void *
b97cd92003-03-20Martin Stjernholm #define PIKE_INSTR_T void *
c2da762014-12-06Tobias S. Josefowitz #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_ARM32 #define PIKE_OPCODE_T unsigned INT32
3ea5d12016-08-15Marcus Comstedt #elif PIKE_BYTECODE_METHOD == PIKE_BYTECODE_ARM64 #define PIKE_OPCODE_T unsigned INT32
d8e19a2002-04-07Martin Stjernholm #else #define PIKE_OPCODE_T unsigned INT8 #endif
b97cd92003-03-20Martin Stjernholm  #ifndef PIKE_INSTR_T /* The type for an opcode instruction identifier (not packed). In all * cases but PIKE_BYTECODE_GOTO, this is n - F_OFFSET where n is the * number in the Pike_opcodes enum. */ #define PIKE_INSTR_T unsigned int #endif
d8e19a2002-04-07Martin Stjernholm 
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 {
77fbd72010-11-25Henrik Grubbström (Grubba)  /* For variables: Offset of the variable in the storage pointed to * by inherit.storage_offset in the struct inherit that corresponds * to the identifier. See LOW_GET_GLOBAL and GET_GLOBAL. The stored * variable may be either a normal or a short svalue, depending on * identifier.run_time_type. (IDENTIFIER_VARIABLE) * * For pike functions: Offset to the start of the function in * program.program in the program pointed to by prog in the struct * inherit that corresponds to the identifier. Or -1 if a prototype. * (IDENTIFIER_PIKE_FUNCTION) */ ptrdiff_t offset;
b6f3022007-09-25Henrik Grubbström (Grubba)  /* External symbol reference. (IDENTIFIER_EXTERN) * * Note that this bit MUST be checked to be zero * before looking at the other four cases! */ struct { unsigned short depth; /* Scope count. */ unsigned short id; /* Reference number. */ } ext_ref;
89378b2010-11-23Henrik Grubbström (Grubba)  /* Constant. (IDENTIFIER_CONSTANT) * * Offset of the struct program_constant in program.constants * in the program pointed to by prog in the struct inherit * that corresponds to the identifier. */ struct { ptrdiff_t offset; /* Offset in the constants table. */ } const_info;
85e4552008-05-13Henrik Grubbström (Grubba)  /* Getter/setter reference pair. (IDENTIFIER_VARIABLE && PIKE_T_GET_SET) */ struct { INT16 getter; /* Reference to getter. */ INT16 setter; /* Reference to setter. */ } gs_info;
b6f3022007-09-25Henrik Grubbström (Grubba)  /* C function pointer. (IDENTIFIER_C_FUNCTION) */
5267b71995-08-09Fredrik Hübinette (Hubbe)  void (*c_fun)(INT32);
9823d62003-08-02Martin Stjernholm 
77fbd72010-11-25Henrik Grubbström (Grubba)  /* Direct svalue pointer. Only used in the reference vtable cache. */ struct svalue *sval;
5267b71995-08-09Fredrik Hübinette (Hubbe) };
7ea7932003-08-03Martin Stjernholm #define IDENTIFIER_VARIABLE 0
354bbe2007-09-24Henrik Grubbström (Grubba) #define IDENTIFIER_CONSTANT 1
5267b71995-08-09Fredrik Hübinette (Hubbe) #define IDENTIFIER_C_FUNCTION 2
354bbe2007-09-24Henrik Grubbström (Grubba) #define IDENTIFIER_PIKE_FUNCTION 3 #define IDENTIFIER_FUNCTION 2 #define IDENTIFIER_TYPE_MASK 3
64dd452007-09-29Henrik Grubbström (Grubba) #define IDENTIFIER_ALIAS 4 /* Identifier is an alias for another * (possibly extern) symbol. */
0ee38f2002-05-11Martin Stjernholm #define IDENTIFIER_VARARGS 8 /* Used for functions only. */
e0d6f52003-02-13Martin Stjernholm #define IDENTIFIER_NO_THIS_REF 8 /* Used for variables only: Don't count refs to self. */
98cf2a2003-02-24Martin Stjernholm #define IDENTIFIER_HAS_BODY 16 /* Function has a body (set already in pass 1). */
94c88f2016-11-05Henrik Grubbström (Grubba) #define IDENTIFIER_WEAK 16 /* Used for variables only: Weak reference. */
97f6282000-03-07Fredrik Hübinette (Hubbe) #define IDENTIFIER_SCOPED 32 /* This is used for local functions only */
8322b62000-05-08Fredrik Hübinette (Hubbe) #define IDENTIFIER_SCOPE_USED 64 /* contains scoped local functions */
d2c6081996-11-07Fredrik Hübinette (Hubbe)  #define IDENTIFIER_IS_FUNCTION(X) ((X) & IDENTIFIER_FUNCTION)
354bbe2007-09-24Henrik Grubbström (Grubba) #define IDENTIFIER_IS_PIKE_FUNCTION(X) (((X) & IDENTIFIER_TYPE_MASK) == IDENTIFIER_PIKE_FUNCTION) #define IDENTIFIER_IS_C_FUNCTION(X) (((X) & IDENTIFIER_TYPE_MASK) == IDENTIFIER_C_FUNCTION) #define IDENTIFIER_IS_CONSTANT(X) (((X) & IDENTIFIER_TYPE_MASK) == IDENTIFIER_CONSTANT)
7ea7932003-08-03Martin Stjernholm #define IDENTIFIER_IS_VARIABLE(X) (!((X) & IDENTIFIER_TYPE_MASK))
eff2b02001-07-03Henrik Grubbström (Grubba) #define IDENTIFIER_IS_ALIAS(X) ((X) & IDENTIFIER_ALIAS)
64dd452007-09-29Henrik Grubbström (Grubba) #define IDENTIFIER_IS_SCOPED(X) ((X) & IDENTIFIER_SCOPED)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
64dd452007-09-29Henrik Grubbström (Grubba) #define IDENTIFIER_MASK 127
97f6282000-03-07Fredrik Hübinette (Hubbe) 
2f075c2001-10-05Fredrik Hübinette (Hubbe) /* * Every constant, class, function and variable
0ee38f2002-05-11Martin Stjernholm  * gets exactly one of these.
2f075c2001-10-05Fredrik Hübinette (Hubbe)  */
5267b71995-08-09Fredrik Hübinette (Hubbe) struct identifier {
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *name;
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
ef24a82012-01-12Henrik Grubbström (Grubba)  INT_TYPE linenumber;
2011cc2014-10-06Per Hedbor  unsigned INT32 filename_strno; /* Index in strings. */
1ef5572000-08-30Henrik Grubbström (Grubba)  unsigned INT8 identifier_flags; /* IDENTIFIER_??? */ unsigned INT8 run_time_type; /* PIKE_T_??? */ unsigned INT16 opt_flags; /* OPT_??? */
be478c1997-08-30Henrik Grubbström (Grubba) #ifdef PROFILING
b2630d2004-05-20Henrik Grubbström (Grubba)  unsigned INT32 num_calls; /* Total number of calls. */
5ca7b52012-01-07Jonas Walldén  unsigned INT32 recur_depth; /* Recursion depth during timing. */
b2630d2004-05-20Henrik Grubbström (Grubba)  cpu_time_t total_time; /* Total time with children. */ cpu_time_t self_time; /* Total time excluding children. */
be478c1997-08-30Henrik Grubbström (Grubba) #endif /* PROFILING */
5267b71995-08-09Fredrik Hübinette (Hubbe)  union idptr func; };
2f075c2001-10-05Fredrik Hübinette (Hubbe) /* * This is used to store constants, both
13670c2015-05-25Martin Nilsson  * inline constants and those defined explicitly with
2f075c2001-10-05Fredrik Hübinette (Hubbe)  * the constant keyword. */
454d541999-09-18Fredrik Hübinette (Hubbe) struct program_constant {
4ea54f2004-05-29Henrik Grubbström (Grubba)  struct svalue sval; /* Value. */ ptrdiff_t offset; /* Offset in identifiers to initialization function. */
454d541999-09-18Fredrik Hübinette (Hubbe) };
5267b71995-08-09Fredrik Hübinette (Hubbe) /* * in the bytecode, a function starts with: * char num_args * char num_locals * char code[] */
09846a2007-10-06Henrik Grubbström (Grubba) #define ID_PROTECTED 0x01 /* Symbol is not visible by indexing */
b92e341999-12-30Henrik Grubbström (Grubba) #define ID_STATIC 0x01 /* Symbol is not visible by indexing */ #define ID_PRIVATE 0x02 /* Symbol is not visible by inherit */
09846a2007-10-06Henrik Grubbström (Grubba) #define ID_FINAL 0x04 /* Symbol may not be overloaded */
ab0d472007-12-28Martin Nilsson #define ID_NOMASK 0x04 /* Symbol may not be overloaded (deprecated) */
fa89602002-03-01Martin Nilsson #define ID_PUBLIC 0x08 /* Anti private */
33934f2008-05-21Henrik Grubbström (Grubba) #define ID_USED 0x10 /* This identifier has been used. Check
3f772f2007-10-11Henrik Grubbström (Grubba)  * that the type is compatible when * overloading. */
09846a2007-10-06Henrik Grubbström (Grubba) #define ID_LOCAL 0x20 /* Locally referenced symbol (not virtual) */
fa89602002-03-01Martin Nilsson #define ID_INLINE 0x20 /* Same as local */ #define ID_HIDDEN 0x40 /* Symbols that are private and inherited one step later */ #define ID_INHERITED 0x80 /* Symbol is inherited */
b92e341999-12-30Henrik Grubbström (Grubba) #define ID_OPTIONAL 0x100 /* Symbol is not required by the interface */ #define ID_EXTERN 0x200 /* Symbol is defined later */
5ca4352000-07-12Henrik Grubbström (Grubba) #define ID_VARIANT 0x400 /* Function is overloaded by argument. */
5e217c2016-11-05Henrik Grubbström (Grubba) #define ID_WEAK 0x800 /* Variable has weak references. */
f80d571999-11-23Henrik Grubbström (Grubba) 
5e217c2016-11-05Henrik Grubbström (Grubba) #define ID_MODIFIER_MASK 0x0fff
f80d571999-11-23Henrik Grubbström (Grubba) 
1fd11d2008-05-29Henrik Grubbström (Grubba) #define ID_STRICT_TYPES 0x8000 /* #pragma strict_types */ #define ID_SAVE_PARENT 0x10000 /* #pragma save_parent */ #define ID_DONT_SAVE_PARENT 0x20000 /* #pragma dont_save_parent */ #define ID_NO_DEPRECATION_WARNINGS 0x40000 /* #pragma no_deprecation_warnings */
9b4ac32014-11-26Henrik Grubbström (Grubba) #define ID_DISASSEMBLE 0x80000 /* #pragma disassemble */
0ffc192016-11-05Tobias S. Josefowitz #define ID_DYNAMIC_DOT 0x100000 /* #pragma dynamic_dot */
5267b71995-08-09Fredrik Hübinette (Hubbe) 
2f075c2001-10-05Fredrik Hübinette (Hubbe)  /* * All identifiers in this program * and all identifiers in inherited programs
fb79e02002-12-16Henrik Grubbström (Grubba)  * need to have a 'struct reference' in this
2f075c2001-10-05Fredrik Hübinette (Hubbe)  * program. When we overload a function, we simply * change the reference to point to the new 'struct identifier'.
9823d62003-08-02Martin Stjernholm  * * When an identifier is represented as an integer, it's typically the * offset of the corresponding struct reference in * program.identifier_references.
2f075c2001-10-05Fredrik Hübinette (Hubbe)  */
5267b71995-08-09Fredrik Hübinette (Hubbe) struct reference {
9823d62003-08-02Martin Stjernholm  /* Offset of the struct inherit in program.inherits for the program * that the struct identifier is in. See INHERIT_FROM_PTR and * INHERIT_FROM_INT. */
cb22561995-10-11Fredrik Hübinette (Hubbe)  unsigned INT16 inherit_offset;
9823d62003-08-02Martin Stjernholm  /* Offset of the struct identifier in program.identifiers in the * program pointed to by the struct inherit through inherit_offset * above. See ID_FROM_PTR and ID_FROM_INT. */
cb22561995-10-11Fredrik Hübinette (Hubbe)  unsigned INT16 identifier_offset;
9823d62003-08-02Martin Stjernholm 
9779872008-06-28Martin Stjernholm  /* ID_* flags - protected, private etc.. */
5838502007-01-01Martin Nilsson  unsigned INT16 id_flags;
77fbd72010-11-25Henrik Grubbström (Grubba)  /* V-table cache information from this point on. */ /* Run-time type for the value field if initialized. * PIKE_T_UNKNOWN indicates uninitialized. */ INT16 run_time_type; /* Cached value of the lookup. */ union idptr func;
5267b71995-08-09Fredrik Hübinette (Hubbe) };
7ea7932003-08-03Martin Stjernholm /* Magic value used as identifier reference integer to refer to this. */ #define IDREF_MAGIC_THIS -1
9823d62003-08-02Martin Stjernholm /* Magic values in inherit.parent_offset; see below. */ #define OBJECT_PARENT -18 #define INHERIT_PARENT -17
2f075c2001-10-05Fredrik Hübinette (Hubbe) /* * Each program has an array of these, * the first entry points to itself, the * rest are from inherited programs. * Note that when a program is inherited,
4145962003-01-31Martin Stjernholm  * all 'struct inherit' from that program are
2f075c2001-10-05Fredrik Hübinette (Hubbe)  * copied, so the whole tree of inherits is * represented. */
5267b71995-08-09Fredrik Hübinette (Hubbe) struct inherit {
9823d62003-08-02Martin Stjernholm  /* The depth of the inherited program in this program. I.e. the * number of times the program has been inherited, directly or * indirectly. * * Note that the struct inherit for the program that directly * inherited the program represented by this struct inherit can be * found by going backwards in program.inherits from this struct * until one is found with an inherit_level less than this one. */
342fef2000-08-23Fredrik Hübinette (Hubbe)  INT16 inherit_level;
9823d62003-08-02Martin Stjernholm 
89378b2010-11-23Henrik Grubbström (Grubba)  /* All the identifier references in the inherited program have been
9823d62003-08-02Martin Stjernholm  * copied to this program with the first one at this offset. */
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT16 identifier_level;
f2f29e2017-10-25Arne Goedeke  /* TODO: why is this signed. */
9823d62003-08-02Martin Stjernholm  /* The index of the identifier reference in the parent program for * the identifier from which this inherit was done. -1 if there's no * such thing. It's always -1 in the inherit struct for the top * level program. */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  INT16 parent_identifier;
9823d62003-08-02Martin Stjernholm  /* Describes how to find the parent object for the external * identifier references associated with this inherit: * * OBJECT_PARENT: Follow the object parent, providing * PROGRAM_USES_PARENT is set in the program containing this * inherit. See PARENT_INFO. This is used for external references * in the top level program (i.e. the one containing the inherit * table). * * INHERIT_PARENT: Follow the parent pointer in this inherit. This * is used when finished programs with parent objects are * inherited. * * A non-negative integer: The parent is found by following this * number of parent pointers in the program that directly * inherited the program in this inherit, i.e. in the closest * lower level inherit. This is used when a program is inherited * whose parent is still being compiled, so it's parent object is * fake. That implies that that program also contains the current * program on some level, and that level is stored here. An * example: * * class A { * class B {} * class C { * class D { * inherit B; * } * } * } * * The parent program of B is A, which is still being compiled * when B is inherited in D, so it has a fake object. A is also * the parent of D, but two levels out, and hence 2 is stored in * parent_offset. * * Note that parent_offset can be 0: * * class A { * class B {} * inherit B; * } */
61e9a01998-01-25Fredrik Hübinette (Hubbe)  INT16 parent_offset;
9823d62003-08-02Martin Stjernholm  /* The offset of the first entry in prog->identifier_references that * comes from the program in this inherit. prog is in this case the * program that directly inherited it, and not the top level * program. I.e. for inherits on level 1, this is always the same as * identifier_level. * * Are both really necessary? /mast */
1a49362002-05-10Henrik Grubbström (Grubba)  size_t identifier_ref_offset;
9823d62003-08-02Martin Stjernholm  /* Offset in object->storage to the start of the storage for the * variables from the program in this inherit. */
b819352000-08-14Henrik Grubbström (Grubba)  ptrdiff_t storage_offset;
9823d62003-08-02Martin Stjernholm  /* The parent object for the program in this inherit, or NULL if * there isn't any. */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct object *parent;
9823d62003-08-02Martin Stjernholm  /* The program for this inherit. */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct program *prog;
9823d62003-08-02Martin Stjernholm  /* The name of the inherit, if there is any. For nested inherits, * this can be a string on the form "A::B::C". */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct pike_string *name;
5267b71995-08-09Fredrik Hübinette (Hubbe) };
baa7712016-05-06Henrik Grubbström (Grubba) /** * Special inherit references. * * These are used by find_inherited_identifier(). */ #define INHERIT_SELF 0 /* Self. */
f352fe2017-01-28Henrik Grubbström (Grubba) #define INHERIT_LOCAL -1 /* Self and not overrideable (force local). */ #define INHERIT_GLOBAL -2 /* Self and overrideable. */ #define INHERIT_ALL -3 /* All inherits but not self. */
2f075c2001-10-05Fredrik Hübinette (Hubbe) 
454d541999-09-18Fredrik Hübinette (Hubbe) 
aa68b12001-03-19Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik 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 through first compiler pass */ #define PROGRAM_PASS_1_DONE 8
8aae6d1999-08-19Fredrik Hübinette (Hubbe) /* Program will be destructed as soon at it runs out of references. * Normally only used for mutex lock keys and similar */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_DESTRUCT_IMMEDIATE 0x10
b504ed1997-09-21Fredrik Hübinette (Hubbe) 
8aae6d1999-08-19Fredrik Hübinette (Hubbe) /* Self explanatory, automatically detected */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_HAS_C_METHODS 0x20
05590d1998-04-23Fredrik Hübinette (Hubbe) 
d2a6182016-02-18Henrik Grubbström (Grubba) /* Objects created from this program are immutable and shareable. */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_CONSTANT 0x40
8aae6d1999-08-19Fredrik Hübinette (Hubbe) 
9823d62003-08-02Martin Stjernholm /* Objects have pointers to the parent object. Use LOW_PARENT_INFO or
d2a6182016-02-18Henrik Grubbström (Grubba)  * PARENT_INFO to extract it. * Note that this is also set by #pragma save_parent. */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_USES_PARENT 0x80
1994251999-09-06Fredrik Hübinette (Hubbe) 
2b1b5f2002-02-06Henrik Grubbström (Grubba) /* Objects should not be destructed even when they only have weak
1b0ac81999-10-29Martin Stjernholm  * references left. */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_NO_WEAK_FREE 0x100
1b0ac81999-10-29Martin Stjernholm  /* Objects should not be destructed by f_destruct(). */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_NO_EXPLICIT_DESTRUCT 0x200
1b0ac81999-10-29Martin Stjernholm 
8ba59a2000-03-26Fredrik Hübinette (Hubbe) /* Program is in an inconsistant state */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_AVOID_CHECK 0x400
8ba59a2000-03-26Fredrik Hübinette (Hubbe) 
aa68b12001-03-19Fredrik Hübinette (Hubbe) /* Program has not yet been used for compilation */
f3c7152001-04-14Fredrik Hübinette (Hubbe) #define PROGRAM_VIRGIN 0x800
aa68b12001-03-19Fredrik Hübinette (Hubbe) 
9823d62003-08-02Martin Stjernholm /* Don't allow the program to be inherited or cloned if there's no
d2a6182016-02-18Henrik Grubbström (Grubba)  * parent object. May only be set if PROGRAM_USES_PARENT is. * Set this if the parent pointer is actually used by the program. */
22d7992001-06-23Fredrik Hübinette (Hubbe) #define PROGRAM_NEEDS_PARENT 0x1000
99cce52007-05-26Martin Stjernholm /* Program has code to be executed when it's destructed. This causes * the gc to consider objects of this program to be "live" and will * take care to ensure a good destruct sequence so that other * referenced things are intact as far as possible when the object is * destructed. See the blurb near the top of gc.c for further * discussion. * * This flag gets set automatically when an event handler that might * act on PROG_EVENT_EXIT is installed (i.e. through set_exit_callback * or pike_set_prog_event_callback). However, if the handler is very * simple then this flag may be cleared again to allow the gc to * handle objects of this program more efficiently (by considering * them "dead" and destroy them in an arbitrary order). * * Such a "very simple" handler should only do things like freeing * pointers and clearing variables in the object storage. It can not * assume that any other context is intact when it's called. It might * even get called after the module exit function, which means that * this optimization trick can never be used in a dynamically loaded * module. */ #define PROGRAM_LIVE_OBJ 0x2000
a947122014-06-16Henrik Grubbström (Grubba) /* Clear the object storage on destruct. */ #define PROGRAM_CLEAR_STORAGE 0x4000
b5dc812001-07-12Fredrik Hübinette (Hubbe) /* Using define instead of enum allows for ifdefs - Hubbe */ #define PROG_EVENT_INIT 0 #define PROG_EVENT_EXIT 1 #define PROG_EVENT_GC_RECURSE 2 #define PROG_EVENT_GC_CHECK 3 #define NUM_PROG_EVENTS 4
8ba59a2000-03-26Fredrik Hübinette (Hubbe) 
f3c7152001-04-14Fredrik Hübinette (Hubbe) /* These macros should only be used if (p->flags & PROGRAM_USES_PARENT) * is true */ #define LOW_PARENT_INFO(O,P) ((struct parent_info *)(PIKE_OBJ_STORAGE((O)) + (P)->parent_info_storage)) #define PARENT_INFO(O) LOW_PARENT_INFO( (O), (O)->prog)
2f075c2001-10-05Fredrik Hübinette (Hubbe) /* * Objects which needs to access their parent * have to allocate one of these structs in * the object data area. * The parent_info_storage member of the program * struct tells us where in the object to find this * data. */
f3c7152001-04-14Fredrik Hübinette (Hubbe) struct parent_info { struct object *parent; INT16 parent_identifier; };
79788d2009-06-22Henrik Grubbström (Grubba) /* Single entry cache for object indexing. */ struct identifier_lookup_cache { INT32 program_id; INT32 identifier_id; };
5267b71995-08-09Fredrik Hübinette (Hubbe) struct program {
f426422015-03-17Martin Nilsson  INT32 refs;
45637c2001-04-07Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT32 id; /* used to identify program in caches */
2ad3c01999-09-16Fredrik Hübinette (Hubbe)  /* storage_needed - storage needed in object struct * the first inherit[0].storage_offset bytes are not used and are * subtracted when inheriting. */
b819352000-08-14Henrik Grubbström (Grubba)  ptrdiff_t storage_needed; /* storage needed in the object struct */
f3c7152001-04-14Fredrik Hübinette (Hubbe)  ptrdiff_t xstorage; /* Non-inherited storage */ ptrdiff_t parent_info_storage;
8f29a31999-09-15Fredrik Hübinette (Hubbe)  INT16 flags; /* PROGRAM_* */
90e9781999-01-31Fredrik Hübinette (Hubbe)  unsigned INT8 alignment_needed;
e6a5562016-06-20Per Hedbor  /* 5 bytes padding.. */
05590d1998-04-23Fredrik Hübinette (Hubbe)  struct timeval timestamp;
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct program *next; struct program *prev;
f3c7152001-04-14Fredrik Hübinette (Hubbe)  struct program *parent;
13670c2015-05-25Martin Nilsson 
e772e42003-11-14Martin Stjernholm  node *(*optimize)(node *n);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
b5dc812001-07-12Fredrik Hübinette (Hubbe)  void (*event_handler)(int);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5267b71995-08-09Fredrik Hübinette (Hubbe)  unsigned INT32 checksum; #endif
be478c1997-08-30Henrik Grubbström (Grubba) #ifdef PROFILING unsigned INT32 num_clones; #endif /* PROFILING */
5267b71995-08-09Fredrik Hübinette (Hubbe) 
de1d7d2000-07-10Henrik Grubbström (Grubba)  size_t total_size;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
7e877a2003-04-02Martin Stjernholm #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) TYPE * NAME ;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #include "program_areas.h"
7e877a2003-04-02Martin Stjernholm #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) NUMTYPE PIKE_CONCAT(num_,NAME) ;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #include "program_areas.h"
13670c2015-05-25Martin Nilsson 
5580691996-06-21Fredrik Hübinette (Hubbe)  INT16 lfuns[NUM_LFUNS];
5267b71995-08-09Fredrik Hübinette (Hubbe) };
aa04222013-02-25Arne Goedeke PMOD_EXPORT void dump_program_tables (const struct program *p, int indent);
f2f29e2017-10-25Arne Goedeke  PIKE_UNUSED_ATTRIBUTE static inline unsigned INT16 CHECK_IDREF_RANGE(unsigned INT16 x, const struct program *p) {
cc60442008-12-13Martin Nilsson #ifdef PIKE_DEBUG
f2f29e2017-10-25Arne Goedeke  if (x >= p->num_identifier_references) {
c064522009-06-22Henrik Grubbström (Grubba)  dump_program_tables(p, 4);
7ea7932003-08-03Martin Stjernholm  debug_fatal ("Identifier reference index %d out of range 0..%d\n", x, p->num_identifier_references - 1);
79788d2009-06-22Henrik Grubbström (Grubba)  }
f2f29e2017-10-25Arne Goedeke #endif
7ea7932003-08-03Martin Stjernholm  return x; }
f2f29e2017-10-25Arne Goedeke static inline struct reference *PTR_FROM_INT(const struct program *p, unsigned INT16 x) { x = CHECK_IDREF_RANGE(x, p); return p->identifier_references + x; } static inline struct inherit *INHERIT_FROM_PTR(const struct program *p, const struct reference *x) { return dmalloc_touch(struct program *,p)->inherits + x->inherit_offset; }
a2ffef2003-08-20Henrik Grubbström (Grubba) 
f2f29e2017-10-25Arne Goedeke static inline struct program *PROG_FROM_PTR(const struct program *p, const struct reference *x) { return dmalloc_touch(struct program *, INHERIT_FROM_PTR(p,x)->prog); } static inline struct identifier *ID_FROM_PTR(const struct program *p, const struct reference *x) { return PROG_FROM_PTR(p,x)->identifiers + x->identifier_offset; } static inline struct inherit *INHERIT_FROM_INT(const struct program *p, const unsigned INT16 x) { struct reference *ref = PTR_FROM_INT(p, x); return INHERIT_FROM_PTR(p, ref); } static inline struct program *PROG_FROM_INT(const struct program *p, const unsigned INT16 x) { struct reference *ref = PTR_FROM_INT(p, x); return PROG_FROM_PTR(p, ref); } static inline struct identifier *ID_FROM_INT(const struct program *p, unsigned INT16 x) { struct reference *ref = PTR_FROM_INT(p, x); return ID_FROM_PTR(p, ref); }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9624482003-01-15Martin Stjernholm #define QUICK_FIND_LFUN(P,N) (dmalloc_touch(struct program *,(P))->lfuns[N])
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
3b65672004-05-23Martin Nilsson #ifdef DO_PIKE_CLEANUP
3a10112006-07-05Martin Stjernholm PMOD_EXPORT extern int gc_external_refs_zapped;
8b03a62012-01-27Henrik Grubbström (Grubba) PMOD_EXPORT void gc_check_zapped (void *a, TYPE_T type, const char *file, INT_TYPE line);
3b65672004-05-23Martin Nilsson #endif
3a10112006-07-05Martin Stjernholm #if defined (USE_DLL) && defined (DYNAMIC_MODULE) /* Use the function in modules so we don't have to export the block * alloc stuff. */ #define free_program(p) do_free_program(p) #else
4fab5f2004-04-18Martin Stjernholm #define free_program(p) do{ \ struct program *_=(p); \ debug_malloc_touch(_); \
31a8682004-09-27Martin Stjernholm  DO_IF_DEBUG ( \
dbcb292004-09-29Martin Stjernholm  DO_IF_PIKE_CLEANUP ( \ if (gc_external_refs_zapped) \ gc_check_zapped (_, PIKE_T_PROGRAM, __FILE__, __LINE__))); \
4fab5f2004-04-18Martin Stjernholm  if(!sub_ref(_)) \ really_free_program(_); \ }while(0)
3a10112006-07-05Martin Stjernholm #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d476592013-06-12Arne Goedeke ATTRIBUTE((malloc))
3b54e52014-08-21Martin Nilsson PMOD_EXPORT struct program * alloc_program(void);
d476592013-06-12Arne Goedeke PMOD_EXPORT void really_free_program(struct program * p);
990eb52013-11-03Tobias S. Josefowitz void count_memory_in_programs(size_t *num, size_t *_size);
3b54e52014-08-21Martin Nilsson void free_all_program_blocks(void);
13e01d2001-12-16Martin Stjernholm 
1994981998-04-07Fredrik Hübinette (Hubbe) 
1ca3ba1997-10-13Fredrik Hübinette (Hubbe) extern struct program *first_program;
e2d9e62000-06-10Martin Stjernholm extern struct program *gc_internal_program;
9649491998-02-27Fredrik Hübinette (Hubbe) 
8aae6d1999-08-19Fredrik Hübinette (Hubbe) /* Flags for identifier finding... */ #define SEE_STATIC 1
24736a2008-06-29Martin Nilsson #define SEE_PROTECTED 1
8aae6d1999-08-19Fredrik Hübinette (Hubbe) #define SEE_PRIVATE 2
94d66b2008-05-24Henrik Grubbström (Grubba) /* Report levels */ #define REPORT_NOTICE 0 /* FYI. */ #define REPORT_WARNING 1 /* Compiler warning. */ #define REPORT_ERROR 2 /* Compilation error. */ #define REPORT_FATAL 3 /* Unrecoverable error. */
8aae6d1999-08-19Fredrik Hübinette (Hubbe) 
9649491998-02-27Fredrik Hübinette (Hubbe) #define COMPILER_IN_CATCH 1
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
3653692005-03-14Per Hedbor #define ADD_STORAGE(X) low_add_storage(sizeof(X), ALIGNOF(X),0)
dfd8b32005-03-14Per Hedbor 
1f5bfe1999-09-28Fredrik Hübinette (Hubbe) #define STORAGE_NEEDED(X) ((X)->storage_needed - (X)->inherits[0].storage_offset)
90e9781999-01-31Fredrik Hübinette (Hubbe) 
e18a682009-08-17Henrik Grubbström (Grubba) #define FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \ void PIKE_CONCAT(add_to_,NAME)(ARGTYPE ARG); #define BAR(NUMTYPE,TYPE,ARGTYPE,NAME) \ void PIKE_CONCAT(low_add_many_to_,NAME)(struct program_state *state, ARGTYPE *ARG, NUMTYPE cnt); \ void PIKE_CONCAT(add_to_,NAME)(ARGTYPE ARG);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #include "program_areas.h"
5267b71995-08-09Fredrik Hübinette (Hubbe)  /* Prototypes begin here */
3a10112006-07-05Martin Stjernholm PMOD_EXPORT void do_free_program (struct program *p);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) void ins_int(INT32 i, void (*func)(char tmp));
1a49362002-05-10Henrik Grubbström (Grubba) void add_relocated_int_to_program(INT32 i);
591c0c1997-01-19Fredrik Hübinette (Hubbe) void use_module(struct svalue *s);
05590d1998-04-23Fredrik Hübinette (Hubbe) void unuse_modules(INT32 howmany);
e772e42003-11-14Martin Stjernholm node *find_module_identifier(struct pike_string *ident, int see_inherit);
1ae5552017-02-01Henrik Grubbström (Grubba) node *find_predef_identifier(struct pike_string *ident);
4c5d262017-02-19Henrik Grubbström (Grubba) int low_resolve_identifier(struct pike_string *ident);
e772e42003-11-14Martin Stjernholm node *resolve_identifier(struct pike_string *ident);
ef2adb2013-04-21Henrik Grubbström (Grubba) PMOD_EXPORT struct program *resolve_program(struct pike_string *ident);
54bc862016-05-02Henrik Grubbström (Grubba) node *find_inherited_identifier(struct program_state *inherit_state, int inherit_depth, int inh, struct pike_string *ident);
e772e42003-11-14Martin Stjernholm node *program_magic_identifier (struct program_state *state, int state_depth, int inherit_num, struct pike_string *ident, int colon_colon_ref);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) struct program *parent_compilation(int level);
b8cda21997-01-21Fredrik Hübinette (Hubbe) struct program *id_to_program(INT32 id);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) void optimize_program(struct program *p);
ab9db52003-02-20Henrik Grubbström (Grubba) void fsort_program_identifier_index(unsigned short *start, unsigned short *end, struct program *p);
ef24a82012-01-12Henrik Grubbström (Grubba) struct pike_string *find_program_name(struct program *p, INT_TYPE *line);
aaf40c2013-11-03Henrik Grubbström (Grubba) int override_identifier (struct reference *ref, struct pike_string *name, int required_flags);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) void fixate_program(void);
05590d1998-04-23Fredrik Hübinette (Hubbe) struct program *low_allocate_program(void);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) void low_start_new_program(struct program *p,
6d3bc82003-06-03Martin Stjernholm  int pass,
993ba72000-02-15Fredrik Hübinette (Hubbe)  struct pike_string *name, int flags, int *idp);
ef24a82012-01-12Henrik Grubbström (Grubba) PMOD_EXPORT void debug_start_new_program(INT_TYPE line, const char *file);
5683de1995-11-06Fredrik Hübinette (Hubbe) void dump_program_desc(struct program *p);
e964ae1998-04-08Fredrik Hübinette (Hubbe) int sizeof_variable(int run_time_type);
624d091996-02-24Fredrik Hübinette (Hubbe) void check_program(struct program *p);
b706222014-08-20Henrik Grubbström (Grubba) int low_is_variant_dispatcher(struct identifier *id);
a0a83a2013-06-16Henrik Grubbström (Grubba) int is_variant_dispatcher(struct program *prog, int fun);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) struct program *end_first_pass(int finish);
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT struct program *debug_end_program(void);
b819352000-08-14Henrik Grubbström (Grubba) PMOD_EXPORT size_t low_add_storage(size_t size, size_t alignment, ptrdiff_t modulo_orig);
6e4c642002-09-11Marcus Comstedt PMOD_EXPORT void set_init_callback(void (*init_callback)(struct object *)); PMOD_EXPORT void set_exit_callback(void (*exit_callback)(struct object *));
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void set_gc_recurse_callback(void (*m)(struct object *)); PMOD_EXPORT void set_gc_check_callback(void (*m)(struct object *));
3a10112006-07-05Martin Stjernholm PMOD_EXPORT void pike_set_prog_event_callback(void (*cb)(int)); PMOD_EXPORT void pike_set_prog_optimize_callback(node *(*opt)(node *));
b0c1a02013-10-28Henrik Grubbström (Grubba) PMOD_EXPORT int really_low_reference_inherited_identifier(struct program_state *q,
8029d72013-10-31Henrik Grubbström (Grubba)  int i, int f);
b0c1a02013-10-28Henrik Grubbström (Grubba) PMOD_EXPORT int low_reference_inherited_identifier(struct program_state *q, int e,
9fca412017-07-31Martin Nilsson  struct pike_string *name,
b0c1a02013-10-28Henrik Grubbström (Grubba)  int flags);
9fca412017-07-31Martin Nilsson int find_inherit(const struct program *p, const struct pike_string *name);
6d0fdb2013-04-28Henrik Grubbström (Grubba) PMOD_EXPORT int reference_inherited_identifier(struct program_state *state, struct pike_string *inherit, struct pike_string *name);
06983f1996-09-22Fredrik Hübinette (Hubbe) void rename_last_inherit(struct pike_string *n);
a0c9f62013-06-15Henrik Grubbström (Grubba) void lower_inherit(struct program *p, struct object *parent, int parent_identifier, int parent_offset, INT32 flags, struct pike_string *name);
56f2832006-07-05Martin Stjernholm PMOD_EXPORT void low_inherit(struct program *p, struct object *parent, int parent_identifier, int parent_offset, INT32 flags, struct pike_string *name);
3e4d312017-08-02Henrik Grubbström (Grubba) PMOD_EXPORT struct program *lexical_inherit(int scope_depth, struct pike_string *symbol, INT32 flags, int failure_severity_level);
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void do_inherit(struct svalue *s,
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  INT32 flags, struct pike_string *name);
e772e42003-11-14Martin Stjernholm void compiler_do_inherit(node *n, INT32 flags, struct pike_string *name);
9036e82001-08-16Martin Stjernholm int call_handle_inherit(struct pike_string *s);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) void simple_do_inherit(struct pike_string *s, INT32 flags, struct pike_string *name);
9fca412017-07-31Martin Nilsson int isidentifier(const struct pike_string *s);
64dd452007-09-29Henrik Grubbström (Grubba) int low_define_alias(struct pike_string *name, struct pike_type *type, int flags, int depth, int refno); PMOD_EXPORT int define_alias(struct pike_string *name, struct pike_type *type, int flags, int depth, int refno);
6e0fce2013-05-28Per Hedbor int is_auto_variable_type( int variable );
05c7cd1997-07-19Fredrik Hübinette (Hubbe) int low_define_variable(struct pike_string *name,
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *type,
05c7cd1997-07-19Fredrik Hübinette (Hubbe)  INT32 flags,
de1d7d2000-07-10Henrik Grubbström (Grubba)  size_t offset,
05c7cd1997-07-19Fredrik Hübinette (Hubbe)  INT32 run_time_type);
6e0fce2013-05-28Per Hedbor void fix_auto_variable_type( int id, struct pike_type *type );
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int quick_map_variable(const char *name,
e2d9e62000-06-10Martin Stjernholm  int name_length,
de1d7d2000-07-10Henrik Grubbström (Grubba)  size_t offset,
0929a02002-09-12Marcus Comstedt  const char *type,
e2d9e62000-06-10Martin Stjernholm  int type_length, INT32 run_time_type, INT32 flags);
06983f1996-09-22Fredrik Hübinette (Hubbe) int define_variable(struct pike_string *name,
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *type,
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT32 flags);
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT int add_constant(struct pike_string *name,
cca4872010-02-18Stephen R. van den Berg  const struct svalue *c,
eaa4da2001-10-04Fredrik Hübinette (Hubbe)  INT32 flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int simple_add_constant(const char *name,
eaa4da2001-10-04Fredrik Hübinette (Hubbe)  struct svalue *c, INT32 flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int add_integer_constant(const char *name,
e6f9132003-11-07Martin Stjernholm  INT_ARG_TYPE i, INT32 flags);
fa53ec2012-06-05Stephen R. van den Berg PMOD_EXPORT int low_add_integer_constant(struct pike_string *name, INT_ARG_TYPE i, INT32 flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int quick_add_integer_constant(const char *name,
e6f9132003-11-07Martin Stjernholm  int name_length, INT_ARG_TYPE i, INT32 flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int add_float_constant(const char *name,
e6f9132003-11-07Martin Stjernholm  FLOAT_ARG_TYPE f, INT32 flags); PMOD_EXPORT int quick_add_float_constant(const char *name, int name_length, FLOAT_ARG_TYPE f, INT32 flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int add_string_constant(const char *name,
e6f9132003-11-07Martin Stjernholm  const char *str, INT32 flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int add_program_constant(const char *name,
eaa4da2001-10-04Fredrik Hübinette (Hubbe)  struct program *p, INT32 flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int add_object_constant(const char *name,
eaa4da2001-10-04Fredrik Hübinette (Hubbe)  struct object *o, INT32 flags);
7e877a2003-04-02Martin Stjernholm PMOD_EXPORT int add_function_constant(const char *name, void (*cfun)(INT32), const char * type, int flags);
0929a02002-09-12Marcus Comstedt PMOD_EXPORT int debug_end_class(const char *name, ptrdiff_t namelen, INT32 flags);
06983f1996-09-22Fredrik Hübinette (Hubbe) INT32 define_function(struct pike_string *name,
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *type,
7e877a2003-04-02Martin Stjernholm  unsigned flags, unsigned function_flags,
1ef5572000-08-30Henrik Grubbström (Grubba)  union idptr *func,
7e877a2003-04-02Martin Stjernholm  unsigned opt_flags);
9fca412017-07-31Martin Nilsson PMOD_EXPORT int really_low_find_shared_string_identifier(const struct pike_string *name,
1117cf2014-11-06Martin Nilsson  const struct program *prog,
22f3002013-10-05Henrik Grubbström (Grubba)  int flags);
295afd2013-05-26Henrik Grubbström (Grubba) int really_low_find_variant_identifier(struct pike_string *name, struct program *prog, struct pike_type *type, int start_pos, int flags);
e6a5562016-06-20Per Hedbor PMOD_EXPORT int low_find_lfun(struct program *p, enum LFUN lfun); PMOD_EXPORT int find_lfun_fatal(struct program *p, enum LFUN lfun);
286afb2001-02-05Henrik Grubbström (Grubba) int lfun_lookup_id(struct pike_string *lfun_name);
9fca412017-07-31Martin Nilsson int low_find_shared_string_identifier(const struct pike_string *name,
1117cf2014-11-06Martin Nilsson  const struct program *prog);
5267b71995-08-09Fredrik Hübinette (Hubbe) struct ff_hash;
06983f1996-09-22Fredrik Hübinette (Hubbe) int find_shared_string_identifier(struct pike_string *name,
1117cf2014-11-06Martin Nilsson  const struct program *prog); PMOD_EXPORT int find_identifier(const char *name,const struct program *prog);
06983f1996-09-22Fredrik Hübinette (Hubbe) int store_prog_string(struct pike_string *str);
cca4872010-02-18Stephen R. van den Berg int store_constant(const struct svalue *foo,
1016021999-10-28Fredrik Hübinette (Hubbe)  int equal, struct pike_string *constant_name);
15ff8c1998-05-25Henrik Grubbström (Grubba) struct array *program_indices(struct program *p); struct array *program_values(struct program *p);
7195af2011-01-15Henrik Grubbström (Grubba) struct array *program_types(struct program *p);
5dcae82010-11-11Henrik Grubbström (Grubba) int low_program_index_no_free(struct svalue *to, struct program *p, int e, struct object *parent, int parent_identifier);
354bbe2007-09-24Henrik Grubbström (Grubba) int program_index_no_free(struct svalue *to, struct svalue *what, struct svalue *ind);
ef24a82012-01-12Henrik Grubbström (Grubba) INT_TYPE get_small_number(char **q); void ext_store_program_line (struct program *prog, INT_TYPE line, struct pike_string *file);
5267b71995-08-09Fredrik Hübinette (Hubbe) void start_line_numbering(void);
ef24a82012-01-12Henrik Grubbström (Grubba) void store_linenumber(INT_TYPE current_line, struct pike_string *current_file);
7c7a3f2002-12-01Martin Stjernholm PMOD_EXPORT struct pike_string *low_get_program_line(struct program *prog,
ef24a82012-01-12Henrik Grubbström (Grubba)  INT_TYPE *linep);
50edc82001-07-13Henrik Grubbström (Grubba) PMOD_EXPORT struct pike_string *get_program_line(struct program *prog,
ef24a82012-01-12Henrik Grubbström (Grubba)  INT_TYPE *linep); PMOD_EXPORT char *low_get_program_line_plain (struct program *prog, INT_TYPE *linep,
90a1ad2003-03-29Martin Stjernholm  int malloced);
7c7a3f2002-12-01Martin Stjernholm PMOD_EXPORT struct pike_string *low_get_line(PIKE_OPCODE_T *pc,
ef24a82012-01-12Henrik Grubbström (Grubba)  struct program *prog, INT_TYPE *linep);
90a1ad2003-03-29Martin Stjernholm PMOD_EXPORT char *low_get_line_plain (PIKE_OPCODE_T *pc, struct program *prog,
ef24a82012-01-12Henrik Grubbström (Grubba)  INT_TYPE *linep, int malloced);
50edc82001-07-13Henrik Grubbström (Grubba) PMOD_EXPORT struct pike_string *get_line(PIKE_OPCODE_T *pc,
ef24a82012-01-12Henrik Grubbström (Grubba)  struct program *prog, INT_TYPE *linep);
4145962003-01-31Martin Stjernholm PMOD_EXPORT struct pike_string *low_get_function_line (struct object *o,
ef24a82012-01-12Henrik Grubbström (Grubba)  int fun, INT_TYPE *linep);
4266ce2008-05-31Henrik Grubbström (Grubba) PMOD_EXPORT struct pike_string *get_identifier_line(struct program *p,
ef24a82012-01-12Henrik Grubbström (Grubba)  int fun, INT_TYPE *linep);
92c73b2001-11-08Fredrik Hübinette (Hubbe) struct supporter_marker;
7db3162012-03-08Henrik Grubbström (Grubba) void count_memory_in_supporter_markers(size_t *num, size_t *size);
e2eefa2015-08-23Henrik Grubbström (Grubba) PMOD_EXPORT int low_quick_add_function(struct pike_string *name_tmp,
f1b6362014-08-24Arne Goedeke  void (*cfun)(INT32), const char *type, int type_length, unsigned flags, unsigned opt_flags);
be478c1997-08-30Henrik Grubbström (Grubba) void check_all_programs(void);
4218011999-01-31Fredrik Hübinette (Hubbe) void init_program(void);
be478c1997-08-30Henrik Grubbström (Grubba) void cleanup_program(void);
d056542014-06-17Henrik Grubbström (Grubba) PMOD_EXPORT void visit_program (struct program *p, int action, void *extra);
c94c371996-03-28Fredrik Hübinette (Hubbe) void gc_mark_program_as_referenced(struct program *p);
1f21332000-07-28Fredrik Hübinette (Hubbe) void real_gc_cycle_check_program(struct program *p, int weak);
e2d9e62000-06-10Martin Stjernholm unsigned gc_touch_all_programs(void);
be478c1997-08-30Henrik Grubbström (Grubba) void gc_check_all_programs(void); void gc_mark_all_programs(void);
e2d9e62000-06-10Martin Stjernholm void gc_cycle_check_all_programs(void);
45d87e2000-07-18Martin Stjernholm void gc_zap_ext_weak_refs_in_programs(void);
88cf4f2003-01-11Martin Stjernholm size_t gc_free_all_unreferenced_programs(void);
e129c32014-05-26Per Hedbor PMOD_EXPORT void *get_inherit_storage(struct object *o, int inherit);
c7de532008-06-02Martin Stjernholm PMOD_EXPORT ptrdiff_t low_get_storage(struct program *o, struct program *p);
e129c32014-05-26Per Hedbor PMOD_EXPORT void *get_storage(struct object *o, struct program *p);
22f3002013-10-05Henrik Grubbström (Grubba) PMOD_EXPORT struct program *low_program_from_function(struct object *o, INT32 i);
3cd7482001-04-28Martin Stjernholm PMOD_EXPORT struct program *program_from_function(const struct svalue *f);
fe46a52014-02-26Henrik Grubbström (Grubba) PMOD_EXPORT struct program *program_from_type(const struct pike_type *t);
ae62c02012-10-27Henrik Grubbström (Grubba) PMOD_EXPORT struct program *low_program_from_svalue(const struct svalue *s, struct object **parent_obj, int *parent_id);
3cd7482001-04-28Martin Stjernholm PMOD_EXPORT struct program *program_from_svalue(const struct svalue *s);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) struct find_child_cache_s; int find_child(struct program *parent, struct program *child);
0ee27b1998-04-14Fredrik Hübinette (Hubbe) struct implements_cache_s;
d6896c2000-12-16Marcus Comstedt PMOD_EXPORT int implements(struct program *a, struct program *b); PMOD_EXPORT int is_compatible(struct program *a, struct program *b);
94d66b2008-05-24Henrik Grubbström (Grubba) void yyexplain_not_compatible(int severity_level, struct program *a, struct program *b); void yyexplain_not_implements(int severity_level, struct program *a, struct program *b);
4d404a2013-02-19Henrik Grubbström (Grubba) void string_builder_explain_not_compatible(struct string_builder *s, struct program *a, struct program *b); void string_builder_explain_not_implements(struct string_builder *s, struct program *a, struct program *b);
13e2ba2014-04-26Henrik Grubbström (Grubba) PMOD_EXPORT void *parent_storage(int depth, struct program *expected);
e310662014-06-02Henrik Grubbström (Grubba) PMOD_EXPORT void *get_inherited_storage(int inh, struct program *expected);
44d4dd2008-06-28Martin Stjernholm void make_area_executable (char *start, size_t len);
f822262001-07-16Fredrik Hübinette (Hubbe) void make_program_executable(struct program *p);
2ad55e2017-01-23Henrik Grubbström (Grubba) PMOD_EXPORT void string_builder_append_disassembly(struct string_builder *s, const PIKE_OPCODE_T *start, const PIKE_OPCODE_T *end, const char *opcode, const char **params, const char *comment);
0328ad2017-01-31Henrik Grubbström (Grubba) PMOD_EXPORT void add_reverse_symbol(struct pike_string *sym, void *addr); PMOD_EXPORT void simple_add_reverse_symbol(const char *sym, void *addr); PMOD_EXPORT void init_reverse_symbol_table(); PMOD_EXPORT struct pike_string *reverse_symbol_lookup(void *addr);
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Prototypes end here */
c5a4d22016-05-18Martin Nilsson /** * Look up the given lfun in the given program and returns the * function number it has in the program, or -1 if not found. */
e6a5562016-06-20Per Hedbor static inline int PIKE_UNUSED_ATTRIBUTE FIND_LFUN(struct program * p, enum LFUN lfun) {
900bf92014-02-25Per Hedbor #ifdef PIKE_DEBUG
0147f82014-01-16Arne Goedeke  dmalloc_touch(struct program*, p);
e5f8532016-07-11Arne Goedeke  if ((int)lfun < 0) return find_lfun_fatal(p, lfun);
900bf92014-02-25Per Hedbor #endif if (p->flags & PROGRAM_FIXED && lfun < NUM_LFUNS) return p->lfuns[lfun];
0147f82014-01-16Arne Goedeke  return low_find_lfun(p, lfun); }
f1b6362014-08-24Arne Goedeke #define quick_add_function(NAME, NLEN, FUNC, TYPE, TLEN, FLAGS, OPT) \
b22fe22017-04-18Henrik Grubbström (Grubba)  low_quick_add_function(STATIC_IS_CONSTANT(NAME) \
f1b6362014-08-24Arne Goedeke  ? make_shared_static_string(NAME, NLEN, eightbit) \ : make_shared_binary_string(NAME, NLEN), \ FUNC, TYPE, TLEN, FLAGS, OPT)
0147f82014-01-16Arne Goedeke 
f822262001-07-16Fredrik Hübinette (Hubbe) #ifndef PIKE_USE_MACHINE_CODE #define make_program_executable(X) #endif
1ef5572000-08-30Henrik Grubbström (Grubba) #define ADD_FUNCTION(NAME, FUNC, TYPE, FLAGS) \ quick_add_function(NAME, CONSTANT_STRLEN(NAME), FUNC, TYPE,\ CONSTANT_STRLEN(TYPE), FLAGS, \ OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND)
45ee5d1999-02-10Fredrik Hübinette (Hubbe) 
1ef5572000-08-30Henrik Grubbström (Grubba) #define ADD_PROTOTYPE(NAME, TYPE, FLAGS) \
106f592000-08-31Henrik Grubbström (Grubba)  ADD_FUNCTION(NAME, 0, TYPE, FLAGS) #define ADD_FUNCTION2(NAME, FUNC, TYPE, FLAGS, OPT_FLAGS) \ quick_add_function(NAME, CONSTANT_STRLEN(NAME), FUNC, TYPE,\ CONSTANT_STRLEN(TYPE), FLAGS, OPT_FLAGS) #define ADD_PROTOTYPE2(NAME, TYPE, FLAGS, OPT_FLAGS) \ ADD_FUNCTION2(NAME, 0, TYPE, FLAGS, OPT_FLAGS)
f0dcda2000-03-13Henrik Grubbström (Grubba) 
106f592000-08-31Henrik Grubbström (Grubba) #define ADD_INT_CONSTANT(NAME, CONST, FLAGS) \ quick_add_integer_constant(NAME, CONSTANT_STRLEN(NAME), CONST, FLAGS)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
e6f9132003-11-07Martin Stjernholm #define ADD_FLOAT_CONSTANT(NAME, CONST, FLAGS) \ quick_add_float_constant(NAME, CONSTANT_STRLEN(NAME), CONST, FLAGS)
106f592000-08-31Henrik Grubbström (Grubba) #define PIKE_MAP_VARIABLE(NAME, OFFSET, TYPE, RTTYPE, FLAGS) \ quick_map_variable(NAME, CONSTANT_STRLEN(NAME), OFFSET, \ TYPE, CONSTANT_STRLEN(TYPE), RTTYPE, FLAGS)
e2d9e62000-06-10Martin Stjernholm 
1ef5572000-08-30Henrik Grubbström (Grubba) #define ADD_FUNCTION_DTYPE(NAME,FUN,DTYPE,FLAGS) do { \ DTYPE_START; \ {DTYPE} \ { \ struct pike_string *_t; \ DTYPE_END(_t); \ quick_add_function(NAME, CONSTANT_STRLEN(NAME), FUN, \ _t->str, _t->len, FLAGS, \ OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); \ free_string(_t); \ } \
91aab41999-12-13Martin Stjernholm } while (0)
9036e82001-08-16Martin Stjernholm #define ADD_INHERIT(PROGRAM, FLAGS) \ low_inherit((PROGRAM), 0, 0, 0, (FLAGS), 0)
8524151999-12-14Fredrik Hübinette (Hubbe) #define START_NEW_PROGRAM_ID(ID) do { \
1ef5572000-08-30Henrik Grubbström (Grubba)  start_new_program(); \ Pike_compiler->new_program->id=PIKE_CONCAT3(PROG_,ID,_ID); \ }while(0)
8524151999-12-14Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) #ifdef DEBUG_MALLOC
d00c501999-03-11Henrik Grubbström (Grubba) #define end_program() ((struct program *)debug_malloc_pass(debug_end_program()))
bad5162000-06-23Fredrik Hübinette (Hubbe) #define end_class(NAME, FLAGS) (debug_malloc_touch(Pike_compiler->new_program), debug_end_class(NAME, CONSTANT_STRLEN(NAME), FLAGS))
3c0c281998-01-26Fredrik Hübinette (Hubbe) #else
45ee5d1999-02-10Fredrik Hübinette (Hubbe) #define end_class(NAME,FLAGS) debug_end_class(NAME, CONSTANT_STRLEN(NAME), FLAGS)
3c0c281998-01-26Fredrik Hübinette (Hubbe) #define end_program debug_end_program #endif
bcd5741999-03-17Fredrik Hübinette (Hubbe)  #define start_new_program() debug_start_new_program(__LINE__,__FILE__)
8524151999-12-14Fredrik Hübinette (Hubbe) 
7c36d52014-06-17Henrik Grubbström (Grubba) #define visit_program_ref(P, REF_TYPE, EXTRA) \
5e83442008-05-11Martin Stjernholm  visit_ref (pass_program (P), (REF_TYPE), \
7c36d52014-06-17Henrik Grubbström (Grubba)  (visit_thing_fn *) &visit_program, (EXTRA))
45d87e2000-07-18Martin Stjernholm #define gc_cycle_check_program(X, WEAK) \ gc_cycle_enqueue((gc_cycle_check_cb *) real_gc_cycle_check_program, (X), (WEAK))
e2d9e62000-06-10Martin Stjernholm 
bad5162000-06-23Fredrik Hübinette (Hubbe) /* This can be used for backwards compatibility * (if added to program.h in Pike 0.6 and Pike 7.0 * -Hubbe */ #define Pike_new_program Pike_compiler->new_program
e2d9e62000-06-10Martin Stjernholm 
4f91582001-01-10Martin Stjernholm /* Return true if compat version is equal or less than MAJOR.MINOR */
ac87152000-09-25Fredrik Hübinette (Hubbe) #define TEST_COMPAT(MAJOR,MINOR) \ (Pike_compiler->compat_major < (MAJOR) || \ (Pike_compiler->compat_major == (MAJOR) && \ Pike_compiler->compat_minor <= (MINOR)))
e2d9e62000-06-10Martin Stjernholm #endif /* PROGRAM_H */
1ef5572000-08-30Henrik Grubbström (Grubba)  /* Kludge... */ #ifndef LAS_H /* FIXME: Needed for the OPT_??? macros. * Maybe they should be moved here, since las.h includes this file anyway? */ #include "las.h" #endif /* !LAS_H */