pike.git / src / las.c

version» Context lines:

pike.git/src/las.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   /**/   #include "global.h" - RCSID("$Id: las.c,v 1.222 2000/11/20 01:20:25 mast Exp $"); + RCSID("$Id: las.c,v 1.223 2000/11/25 16:45:02 grubba Exp $");      #include "language.h"   #include "interpret.h"   #include "las.h"   #include "array.h"   #include "object.h"   #include "stralloc.h"   #include "dynamic_buffer.h"   #include "lex.h"   #include "pike_types.h"
pike.git/src/las.c:393: Inside #if defined(SHARED_NODES)
   }   #endif /* PIKE_DEBUG */    n->next = node_hash.table[hval];    node_hash.table[hval] = n;   }      static void sub_node(node *n)   {    node *prior;    + #ifdef PIKE_DEBUG    if (!node_hash.size) {    return;    } -  + #endif /* PIKE_DEBUG */       prior = node_hash.table[n->hash % node_hash.size];       if (!prior) {    return;    }    if (prior == n) {    node_hash.table[n->hash % node_hash.size] = n->next;    } else {    while(prior && (prior->next != n)) {
pike.git/src/las.c:420: Inside #if defined(SHARED_NODES)
   }    prior->next = n->next;    }    n->next = NULL;   }      static node *freeze_node(node *orig)   {    size_t hash = hash_node(orig);    node *n; +  int found = 0;       /* free_node() wants a correct hash */    orig->hash = hash;    -  if (orig->node_info & OPT_NOT_SHARED) { +  if (orig->tree_info & OPT_NOT_SHARED) {    /* No need to have this node in the hash-table. */    /* add_node(orig); */    return check_node_hash(dmalloc_touch(node *, orig));    }       /* Mark this node as a possible duplicate */    orig->node_info |= OPT_DEFROSTED;    /* Make sure we don't find ourselves */ -  sub_node(orig); +  /* sub_node(orig); */       n = node_hash.table[hash % node_hash.size];       while (n) { -  +  if (n == orig) { +  found = 1; +  if (!(n = n->next)) { +  break; +  } +  }    if ((n->hash == hash) &&    !MEMCMP(&(n->token), &(orig->token),    sizeof(node) - OFFSETOF(node_s, token))) {    if (orig->type && (orig->type != n->type)) {    if (n->type) {    /* Use the new type if it's stricter. */    if (pike_types_le(orig->type, n->type)) {    free_string(n->type);    copy_shared_string(n->type, orig->type);    }    } else {    /* This probably doesn't happen, but... */    copy_shared_string(n->type, orig->type);    }    } -  +  if (!found) { +  node *scan = n; +  while(scan->next) { +  if (scan->next == orig) { +  scan->next = orig->next; +  break; +  } +  scan = scan->next; +  } +  } else { +  /* FIXME: sub_node() recalculates the hash index. +  * We might get better performance by using the one we already have. +  */ +  sub_node(orig); +  }    free_node(dmalloc_touch(node *, orig));    n->refs++;    return check_node_hash(dmalloc_touch(node *, n));    }    n = n->next;    }    orig->node_info &= ~OPT_DEFROSTED; -  +  if (!found) {    add_node(dmalloc_touch(node *, orig)); -  +  }    check_tree(orig,0);    return check_node_hash(orig);   }      #else /* !SHARED_NODES */      #ifdef PIKE_DEBUG   static node *freeze_node(node *orig)   {    check_tree(orig, 0);
pike.git/src/las.c:524: Inside #if defined(PIKE_DEBUG)
      debug_malloc_dump_references(tmp,0,2,0);       if(tmp->token==F_CONSTANT)    print_tree(tmp);    }    /* else */   #endif    {    /* Free the node and be happy */ + #ifdef SHARED_NODES +  /* Force the hashtable to be cleared. */ +  tmp->next = NULL; +  sub_node(tmp); + #endif /* SHARED_NODES */    /* Make sure we don't free any nodes twice */    if(car_is_node(tmp)) _CAR(tmp)=0;    if(cdr_is_node(tmp)) _CDR(tmp)=0;   #ifdef SHARED_NODES    tmp->hash = hash_node(tmp);   #ifdef PIKE_DEBUG    if (l_flag > 3) {    fprintf(stderr, "Freeing node that had %d refs.\n",    tmp->refs);    }
pike.git/src/las.c:556:    fatal("Failed to free %d nodes when compiling!\n",e2);   #endif    }   #ifndef PIKE_DEBUG    }   #endif    free_all_node_s_blocks();    cumulative_parse_error=0;      #ifdef SHARED_NODES -  MEMSET(node_hash.table, 0, sizeof(node *) * node_hash.size); +  /* MEMSET(node_hash.table, 0, sizeof(node *) * node_hash.size); */   #endif /* SHARED_NODES */    }   }      void debug_free_node(node *n)   {    if(!n) return;      #ifdef SHARED_NODES    if (--n->refs) {
pike.git/src/las.c:809:    if(a) {    a->parent = res;    }    if(b) {    b->parent = res;    }       res->token = token;    res->type = 0;    - #ifdef SHARED_NODES -  { -  node *res2 = freeze_node(res); -  -  if (res2 != res) { -  return dmalloc_touch(node *, res2); -  } -  } - #endif /* SHARED_NODES */ -  +     switch(token)    {    case F_CATCH:    res->node_info |= OPT_SIDE_EFFECT;    if (a) {    res->tree_info |= a->tree_info & ~OPT_BREAK;    }    break;       case F_APPLY:
pike.git/src/las.c:971:    if(a) res->tree_info |= a->tree_info;    if(b) res->tree_info |= b->tree_info;    }       /* We try to optimize most things, but argument lists are hard... */    if((token != F_ARG_LIST) && (a || b))    res->node_info |= OPT_TRY_OPTIMIZE;       res->tree_info |= res->node_info;    + #ifdef SHARED_NODES +  /* No need to freeze the node if it can't be shared. */ +  if (!(res->tree_info & OPT_NOT_SHARED)) +  { +  node *res2 = freeze_node(res); +  +  if (res2 != res) { +  return dmalloc_touch(node *, res2); +  } +  } + #endif /* SHARED_NODES */ +    #ifdef PIKE_DEBUG    if(d_flag > 3)    verify_shared_strings_tables();   #endif       check_tree(res,0);    if(!Pike_compiler->num_parse_error && Pike_compiler->compiler_pass==2 &&    (res->node_info & OPT_TRY_OPTIMIZE))    {    optimize(res);
pike.git/src/las.c:1025:    res->type=get_type_of_svalue( & res->u.sval);       return freeze_node(res);   }      node *debug_mknewintnode(int nr)   {    node *res = mkemptynode();    res->token = F_CONSTANT;    res->node_info = OPT_NOT_SHARED; +  res->tree_info = OPT_NOT_SHARED;    res->u.sval.type = T_INT;    res->u.sval.subtype = NUMBER_NUMBER;    res->u.sval.u.integer = nr;    res->type=get_type_of_svalue( & res->u.sval);   #ifdef SHARED_NODES    res->refs = 1;    res->hash = hash_node(res);   #endif /* SHARED_NODES */       return res;