pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:1:   /*   || 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. - || $Id: program.c,v 1.657 2008/04/06 11:49:58 grubba Exp $ + || $Id: program.c,v 1.658 2008/04/06 21:43:31 grubba Exp $   */      #include "global.h"   #include "program.h"   #include "object.h"   #include "dynamic_buffer.h"   #include "pike_types.h"   #include "stralloc.h"   #include "las.h"   #include "lex.h"
pike.git/src/program.c:1209:    */      /*! @endclass    */      struct program *first_program = 0;   static int current_program_id = PROG_DYNAMIC_ID_START;      struct program *null_program=0;    + struct program *compilation_program = 0; +    struct object *error_handler=0;   struct object *compat_handler=0;      struct program *gc_internal_program = 0;   static struct program *gc_mark_program_pos = 0;      int compilation_depth=-1;   dynamic_buffer used_modules;   static struct mapping *resolve_cache=0;   
pike.git/src/program.c:7057:    ret++; /* dependency registred */    }    }    }    }    verify_supporters();    return ret;   }       + /*! @class PikeCompiler +  *! +  *! The Pike compiler. +  */ +    struct compilation   {    struct Supporter supporter;    struct pike_string *prog;    struct object *handler;    int major, minor;    struct program *target;    struct object *placeholder;       struct program *p;
pike.git/src/program.c:7088:      static void free_compilation(struct compilation *c)   {    debug_malloc_touch(c);    free_string(c->prog);    if(c->handler) free_object(c->handler);    if(c->target) free_program(c->target);    if(c->placeholder) free_object(c->placeholder);    free_svalue(& c->default_module);    free_supporter(&c->supporter); -  free((char *)c); +     verify_supporters();   }      static void run_init(struct compilation *c)   {    debug_malloc_touch(c);    c->save_depth=compilation_depth;    compilation_depth=-1;       c->saved_handler = error_handler;
pike.git/src/program.c:7466:   #endif    if(cc->p) {    ok = finish;    free_program(cc->p); /* later */    }       CDFPRINTF((stderr, "th(%ld) %p delayed compile %s.\n",    (long) th_self(), cc->target, ok ? "done" : "failed"));       free_compilation(cc); +  free(cc);    verify_supporters();       return ok;   }    -  + #define THIS_COMPILATION ((struct compilation *)(Pike_fp->current_storage)) +  + static void compilation_event_handler(int e) + { +  struct compilation *c = THIS_COMPILATION; +  switch (e) { +  case PROG_EVENT_INIT: +  c->default_module.type = T_INT; +  c->default_module.subtype = NUMBER_NUMBER; +  break; +  case PROG_EVENT_EXIT: +  free_compilation(c); +  break; +  } + } +  + /*! @decl compile(string code) +  *! +  *! Compile a segment of Pike code. +  */ + static void f_compilation_compile(INT32 args) + { +  pop_n_elems(args); +  push_int(0); + } +  + /*! @decl report(SeverityLevel severity, @ +  *! string filename, int linenumber, @ +  *! string subsystem, @ +  *! string message, mixed ... extra_args) +  *! +  *! Report a diagnostic from the compiler. +  */ + static void f_compilation_report(INT32 args) + { +  int level; +  struct pike_string *filename; +  INT_TYPE linenumber; +  struct pike_string *subsystem; +  struct pike_string *message; +  if (args > 5) { +  f_sprintf(args - 4); +  args = 5; +  } +  get_all_args("report", args, "%d%S%i%S%S", +  &level, &filename, &linenumber, &subsystem, &message); +  fprintf(stderr, "%s:%ld: %s\n", filename->str, linenumber, message->str); +  pop_n_elems(args); +  push_int(0); + } +  + /* Strap the compiler by creating the compilation program by hand. */ + static void compile_compiler(void) + { +  struct program *p = compilation_program = low_allocate_program(); +  struct reference *ref; +  struct identifier *i; +  struct inherit *inh; +  unsigned INT16 *ix; +  +  p->parent_info_storage = -1; +  p->event_handler = compilation_event_handler; +  p->flags |= PROGRAM_HAS_C_METHODS; +  +  p->inherits = inh = malloc(sizeof(struct inherit)); +  p->identifier_references = ref = malloc(sizeof(struct reference) * 2); +  p->identifiers = i = malloc(sizeof(struct identifier) * 2); +  p->identifier_index = ix = malloc(sizeof(unsigned INT16) * 2); +  +  inh->prog = p; +  inh->inherit_level = 0; +  inh->identifier_level = 0; +  inh->parent_identifier = -1; +  inh->parent_offset = OBJECT_PARENT; +  inh->identifier_ref_offset = 0; +  inh->storage_offset = 0; +  inh->parent = NULL; +  inh->name = NULL; +  p->num_inherits = 1; +  +  /* ADD_STORAGE(struct compilation); */ +  p->alignment_needed = ALIGNOF(struct compilation); +  p->inherits->storage_offset = 0; +  p->storage_needed = sizeof(struct compilation); +  +  /* ADD_FUNCTION("compile", f_compilation_compile, ...); */ +  i->name = make_shared_string("compile"); +  i->type = make_pike_type(tFunc(tStr, tPrg(tObj))); +  i->run_time_type = T_FUNCTION; +  i->identifier_flags = IDENTIFIER_C_FUNCTION; +  i->func.c_fun = f_compilation_compile; +  i->opt_flags = 0; +  i++; +  *(ix++) = ref->identifier_offset = compilation_program->num_identifiers++; +  p->num_identifier_index++; +  ref->id_flags = 0; +  ref->inherit_offset = 0; +  ref++; +  p->num_identifier_references++; +  +  /* ADD_FUNCTION("report", f_compilation_report, ...); */ +  i->name = make_shared_string("report"); +  i->type = make_pike_type(tFuncV(tName("SeverityLevel", tInt03) tStr tIntPos +  tStr tStr, tMix, tVoid)); +  i->run_time_type = T_FUNCTION; +  i->identifier_flags = IDENTIFIER_C_FUNCTION; +  i->func.c_fun = f_compilation_report; +  i->opt_flags = 0; +  i++; +  *(ix++) = ref->identifier_offset = compilation_program->num_identifiers++; +  p->num_identifier_index++; +  ref->id_flags = 0; +  ref->inherit_offset = 0; +  ref++; +  p->num_identifier_references++; +  +  p->flags |= PROGRAM_PASS_1_DONE; +  +  fsort_program_identifier_index(p->identifier_index, ix-1, p); +  p->flags |= PROGRAM_FIXED; +  +  optimize_program(p); +  p->flags |= PROGRAM_FINISHED; + } +  + /*! @endclass +  */ +    struct program *compile(struct pike_string *aprog,    struct object *ahandler,/* error handler */    int amajor, int aminor,    struct program *atarget,    struct object *aplaceholder)   {    int delay, dependants_ok = 1;    struct program *ret;   #ifdef PIKE_DEBUG    ONERROR tmp;
pike.git/src/program.c:7556:    }else{    /* finish now */    if(c->p) run_pass2(c);    debug_malloc_touch(c);    run_cleanup(c,0);       ret=c->p;       debug_malloc_touch(c);    free_compilation(c); +  free(c);       if (!dependants_ok) {    CDFPRINTF((stderr, "th(%ld) %p compile() reporting failure "    "since a dependant failed.\n",    (long) th_self(), c->target));    if (ret) free_program(ret);    throw_error_object(low_clone(compilation_error_program), 0, 0, 0,    "Compilation failed.\n");    }    if(!ret) {
pike.git/src/program.c:7810:   }      void init_program(void)   {    size_t i;    struct svalue key;    struct svalue val;    struct svalue id;    init_program_blocks();    +  compile_compiler(); +     MAKE_CONST_STRING(this_program_string,"this_program");    MAKE_CONST_STRING(this_string,"this");    MAKE_CONST_STRING(UNDEFINED_string,"UNDEFINED");       lfun_ids = allocate_mapping(NUM_LFUNS);    lfun_types = allocate_mapping(NUM_LFUNS);    for (i=0; i < NELEM(lfun_names); i++) {    lfun_strings[i] = make_shared_string(lfun_names[i]);       id.type = T_INT;
pike.git/src/program.c:7946: Inside #if defined(DO_PIKE_CLEANUP)
   free_object(placeholder_object);    placeholder_object=0;    }       if(placeholder_program)    {    free_program(placeholder_program);    placeholder_program=0;    }   #endif +  +  if (compilation_program) { +  free_program(compilation_program); +  compilation_program = 0;    } -  + }      void gc_mark_program_as_referenced(struct program *p)   {    debug_malloc_touch(p);       if (p->flags & PROGRAM_AVOID_CHECK) {    /* Program is in an inconsistent state.    * don't look closer at it.    */    debug_malloc_touch(p);