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.102 1999/11/11 19:43:11 grubba Exp $"); + RCSID("$Id: las.c,v 1.103 1999/11/12 01:32:04 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:252: Inside #if defined(SHARED_NODES)
   }    prior->next = n->next;    }   }      static node *freeze_node(node *orig)   {    unsigned INT32 hash = hash_node(orig);    node *n = node_hash.table[hash % node_hash.size];    +  /* free_node() wants a correct hash */ +  orig->hash = hash; +  + #ifdef PIKE_DEBUG +  if (orig->refs != 1) { +  print_tree(orig); +  fatal("Node to be frozen is already shared!\n"); +  } + #endif /* PIKE_DEBUG */ +  +  if (orig->node_info & OPT_NOT_SHARED) { +  /* No need to have this node in the hash-table. */ +  /* add_node(orig); */ +  return dmalloc_touch(node *, orig); +  } +     while (n) {    if ((n->hash == hash) &&    !MEMCMP(&(n->token), &(orig->token),    sizeof(node) - OFFSETOF(node_s, token))) { - #if 0 -  fprintf(stderr, "Found node: "); -  print_tree(n); - #endif /* 0 */ -  free_node(orig); + #ifdef PIKE_DEBUG +  if (n == orig) { +  fatal("Node to be frozen was already cold!\n"); +  } + #endif /* PIKE_DEBUG */ +  free_node(dmalloc_touch(node *, orig));    n->refs++; -  return n; +  return dmalloc_touch(node *, n);    }    n = n->next;    } -  orig->hash = hash; -  add_node(orig); +  add_node(dmalloc_touch(node *, orig));    return orig;   }      #else /* !SHARED_NODES */      #define freeze_node(X) (X)      #endif /* SHARED_NODES */      void free_all_nodes(void)
pike.git/src/las.c:327: Inside #if defined(PIKE_DEBUG)
   }    /* else */   #endif    {    /* Free the node and be happy */    /* 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); +  +  fprintf(stderr, "Freeing node that had %d refs.\n", tmp->refs);    /* Force the node to be freed. */    tmp->refs = 1;   #endif /* SHARED_NODES */    debug_malloc_touch(tmp->type);    free_node(tmp);    }    }    }    }   #if defined(PIKE_DEBUG)
pike.git/src/las.c:353:   #endif    free_all_node_s_blocks();    cumulative_parse_error=0;      #ifdef SHARED_NODES    MEMSET(node_hash.table, 0, sizeof(node *) * node_hash.size);   #endif /* SHARED_NODES */    }   }    - void free_node(node *n) + void debug_free_node(node *n)   {    if(!n) return;   #ifdef PIKE_DEBUG    if(l_flag>9)    print_tree(n);      #ifdef SHARED_NODES    {    unsigned INT32 hash;    if ((hash = hash_node(n)) != n->hash) {    fprintf(stderr, "Hash-value is bad 0x%08x != 0x%08x\n", hash, n->hash); - #if 0 +     print_tree(n);    fatal("token:%d, car:%p cdr:%p file:%s line:%d\n", -  n->token, CAR(n), CDR(n), n->current_file->str, n->line_number); - #endif /* 0 */ +  n->token, _CAR(n), _CDR(n), n->current_file->str, n->line_number);    }    }   #endif /* SHARED_NODES */   #endif /* PIKE_DEBUG */      #ifdef SHARED_NODES -  if (--n->refs) { +  if (dmalloc_touch(node *, n) && --(n->refs)) {    return;    } -  +  sub_node(dmalloc_touch(node *, n));   #endif /* SHARED_NODES */       switch(n->token)    {    case USHRT_MAX:    fatal("Freeing node again!\n");    break;       case F_CONSTANT:    free_svalue(&(n->u.sval));
pike.git/src/las.c:416: Inside #if defined(PIKE_DEBUG) && defined(SHARED_NODES)
  {   #if defined(PIKE_DEBUG) && defined(SHARED_NODES)    if (n && (n->hash != hash_node(n))) {    fatal("Bad node hash!\n");    }   #endif /* PIKE_DEBUG && SHARED_NODES */    return n;   }      /* here starts routines to make nodes */ - static node *mkemptynode(void) + static node *debug_mkemptynode(void)   {    node *res=alloc_node_s();      #ifdef SHARED_NODES    MEMSET(res, 0, sizeof(node));    res->hash = 0;    res->refs = 1;   #endif /* SHARED_NODES */       res->token=0;
pike.git/src/las.c:439:    copy_shared_string(res->current_file, lex.current_file);   #endif    res->type=0;    res->name=0;    res->node_info=0;    res->tree_info=0;    res->parent=0;    return res;   }    - node *mknode(short token, node *a, node *b) + #define mkemptynode() dmalloc_touch(node *, debug_mkemptynode()) +  + node *debug_mknode(short token, node *a, node *b)   {    node *res;      #if defined(PIKE_DEBUG) && !defined(SHARED_NODES) -  if(a && a==b) +  if(b && a==b)    fatal("mknode: a and be are the same!\n");   #endif       check_tree(a,0);    check_tree(b,0);       res = mkemptynode(); -  _CAR(res) = a; -  _CDR(res) = b; +  _CAR(res) = dmalloc_touch(node *, a); +  _CDR(res) = dmalloc_touch(node *, b);    res->node_info = 0;    res->tree_info = 0;    if(a) {    a->parent = res; - #ifdef SHARED_NODES -  a->refs++; - #endif /* SHARED_NODES */ +     }    if(b) {    b->parent = res; - #ifdef SHARED_NODES -  b->refs++; - #endif /* SHARED_NODES */ +     }       res->token = token;    res->type = 0;      #ifdef SHARED_NODES    {    node *res2 = freeze_node(res);       if (res2 != res) { -  return res2; +  return dmalloc_touch(node *, res2);    }    }   #endif /* SHARED_NODES */       switch(token)    {    case F_CATCH:    res->node_info |= OPT_SIDE_EFFECT;    break;   
pike.git/src/las.c:567:    }      #ifdef PIKE_DEBUG    if(d_flag > 3)    verify_shared_strings_tables();   #endif       return res;   }    - node *mkstrnode(struct pike_string *str) + node *debug_mkstrnode(struct pike_string *str)   {    node *res = mkemptynode();    res->token = F_CONSTANT;    copy_shared_string(res->type, string_type_string);    res->node_info = 0;    res->u.sval.type = T_STRING;   #ifdef __CHECKER__    res->u.sval.subtype = 0;   #endif    copy_shared_string(res->u.sval.u.string, str);       return freeze_node(res);   }    - node *mkintnode(int nr) + node *debug_mkintnode(int nr)   {    node *res = mkemptynode();    res->token = F_CONSTANT;    res->node_info = 0;    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);       return freeze_node(res);   }    - /* FIXME: Should probably have a flag on these nodes so they aren't reused. */ - node *mknewintnode(int nr) + node *debug_mknewintnode(int nr)   {    node *res = mkemptynode();    res->token = F_CONSTANT; -  res->node_info = 0; +  res->node_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;   }    - node *mkfloatnode(FLOAT_TYPE foo) + node *debug_mkfloatnode(FLOAT_TYPE foo)   {    node *res = mkemptynode();    res->token = F_CONSTANT;    copy_shared_string(res->type, float_type_string);    res->u.sval.type = T_FLOAT;   #ifdef __CHECKER__    res->u.sval.subtype = 0;   #endif    res->u.sval.u.float_number = foo;       return freeze_node(res);   }       - node *mkprgnode(struct program *p) + node *debug_mkprgnode(struct program *p)   {    struct svalue s;    s.u.program=p;    s.type = T_PROGRAM;   #ifdef __CHECKER__    s.subtype = 0;   #endif    return mkconstantsvaluenode(&s);   }    - node *mkapplynode(node *func,node *args) + node *debug_mkapplynode(node *func,node *args)   {    return mknode(F_APPLY, func, args);   }    - node *mkefuncallnode(char *function, node *args) + node *debug_mkefuncallnode(char *function, node *args)   {    struct pike_string *name;    node *n;    name = findstring(function);    if(!name || !(n=find_module_identifier(name)))    {    my_yyerror("Internally used efun undefined: %s",function);    return mkintnode(0);    }    n = mkapplynode(n, args);    return n;   }    - node *mkopernode(char *oper_id, node *arg1, node *arg2) + node *debug_mkopernode(char *oper_id, node *arg1, node *arg2)   {    if(arg1 && arg2)    arg1=mknode(F_ARG_LIST,arg1,arg2);       return mkefuncallnode(oper_id, arg1);   }    - node *mklocalnode(int var, int depth) + node *debug_mklocalnode(int var, int depth)   {    struct compiler_frame *f;    int e;    node *res = mkemptynode();    res->token = F_LOCAL;       f=compiler_frame;    for(e=0;e<depth;e++) f=f->previous;    copy_shared_string(res->type, f->variable[var].type);    -  res->node_info = OPT_NOT_CONST; -  res->tree_info=res->node_info; +  res->node_info = OPT_NOT_CONST | OPT_NOT_SHARED; +  res->tree_info = res->node_info;   #ifdef __CHECKER__    _CDR(res) = 0;   #endif    res->u.integer.a = var;    res->u.integer.b = depth;      #ifdef SHARED_NODES -  /* FIXME: Not common-subexpression optimized. */ +  /* FIXME: Not common-subexpression optimized. +  * Node would need to contain a ref to the current function, +  * and to the current program. +  */ +     res->hash = hash_node(res); -  res->refs = 1; +        /* return freeze_node(res); */   #endif /* SHARED_NODES */       return res;   }    - node *mkidentifiernode(int i) + node *debug_mkidentifiernode(int i)   {    node *res = mkemptynode();    res->token = F_IDENTIFIER;    copy_shared_string(res->type, ID_FROM_INT(new_program, i)->type);       /* FIXME */    if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(new_program, i)->identifier_flags))    {    res->node_info = OPT_EXTERNAL_DEPEND;    }else{
pike.git/src/las.c:725: Inside #if defined(SHARED_NODES)
  #ifdef SHARED_NODES    res->u.id.prog = new_program;   #endif /* SHARED_NODES */       res = freeze_node(res);       check_tree(res,0);    return res;   }    - node *mkexternalnode(int level, + node *debug_mkexternalnode(int level,    int i,    struct identifier *id)   {    node *res = mkemptynode();    res->token = F_EXTERNAL;       copy_shared_string(res->type, id->type);       /* FIXME */    if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(parent_compilation(level),
pike.git/src/las.c:756:   #endif    res->u.integer.a = level;    res->u.integer.b = i;       /* Bzot-i-zot */    new_program->flags |= PROGRAM_USES_PARENT;       return freeze_node(res);   }    - node *mkcastnode(struct pike_string *type,node *n) + node *debug_mkcastnode(struct pike_string *type,node *n)   {    node *res;       if(!n) return 0;    - #ifdef SHARED_NODES -  n->refs++; - #endif /* SHARED_NODES */ +     if(type==n->type) return n;       res = mkemptynode();    res->token = F_CAST;    copy_shared_string(res->type,type);       if(match_types(object_type_string, type) ||    match_types(object_type_string, type))    res->node_info |= OPT_SIDE_EFFECT;   
pike.git/src/las.c:1079:    return is_equal(&(a->u.sval), &(b->u.sval));       default:    if( a->type != b->type ) return 0;    if(car_is_node(a) && !node_is_eq(CAR(a), CAR(b))) return 0;    if(cdr_is_node(a) && !node_is_eq(CDR(a), CDR(b))) return 0;    return 1;    }   }    - node *mkconstantsvaluenode(struct svalue *s) + node *debug_mkconstantsvaluenode(struct svalue *s)   {    node *res = mkemptynode();    res->token = F_CONSTANT;    assign_svalue_no_free(& res->u.sval, s);    if(s->type == T_OBJECT ||    (s->type==T_FUNCTION && s->subtype!=FUNCTION_BUILTIN))    {    res->node_info|=OPT_EXTERNAL_DEPEND;    }    res->type = get_type_of_svalue(s);    return freeze_node(res);   }    - node *mkliteralsvaluenode(struct svalue *s) + node *debug_mkliteralsvaluenode(struct svalue *s)   {    node *res = mkconstantsvaluenode(s);       /* FIXME: The following affects other instances of this node,    * but probably not too much.    */    if(s->type!=T_STRING && s->type!=T_INT && s->type!=T_FLOAT)    res->node_info|=OPT_EXTERNAL_DEPEND;       return res;   }    - node *mksvaluenode(struct svalue *s) + node *debug_mksvaluenode(struct svalue *s)   {    switch(s->type)    {    case T_ARRAY:    return make_node_from_array(s->u.array);       case T_MULTISET:    return make_node_from_multiset(s->u.multiset);       case T_MAPPING:
pike.git/src/las.c:1384:    fprintf(stderr, "$<%ld>%ld",(long)foo->u.integer.b,(long)foo->u.integer.a);    }else{    fprintf(stderr, "$%ld",(long)foo->u.integer.a);    }    break;       case '?':    fprintf(stderr, "(");    low_print_tree(_CAR(foo),0);    fprintf(stderr, ")?("); +  if (_CDR(foo)) {    low_print_tree(_CADR(foo),0);    fprintf(stderr, "):(");    low_print_tree(_CDDR(foo),0); -  +  } else { +  fprintf(stderr, "0:0"); +  }    fprintf(stderr, ")");    break;       case F_IDENTIFIER:    if(needlval) fputc('&', stderr);    if (new_program) {    fprintf(stderr, "%s",ID_FROM_INT(new_program, foo->u.id.number)->name->str);    } else {    fprintf(stderr, "unknown identifier");    }
pike.git/src/las.c:2152: Inside #if defined(PIKE_DEBUG)
   print_tree(n);    }   #endif      #ifndef IN_TPIKE    switch(n->token)    {   #include "treeopt.h"    use_car:    tmp1=CAR(n); - #ifndef SHARED_NODES -  _CAR(n) = 0; - #endif /* !SHARED_NODES */ +  ADD_NODE_REF(CAR(n));    goto use_tmp1;       use_cdr:    tmp1=CDR(n); - #ifndef SHARED_NODES -  _CDR(n) = 0; - #endif /* !SHARED_NODES */ +  ADD_NODE_REF(CDR(n));    goto use_tmp1;       zap_node:    tmp1 = 0;    goto use_tmp1;       use_tmp1:   #ifdef SHARED_NODES    sub_node(n->parent);   #endif /* SHARED_NODES */       if(CAR(n->parent) == n) -  CAR(n->parent) = tmp1; +  _CAR(n->parent) = tmp1;    else -  CDR(n->parent) = tmp1; +  _CDR(n->parent) = tmp1;      #ifdef SHARED_NODES    n->parent->hash = hash_node(n->parent);    add_node(n->parent);   #endif /* SHARED_NODES */       if(tmp1)    tmp1->parent = n->parent;    else    tmp1 = n->parent;
pike.git/src/las.c:2246:    }   #endif       if(num_parse_error) return -1;       num_strings=new_program->num_strings;    num_constants=new_program->num_constants;    jump=PC;       store_linenumbers=0; -  docode(n); +  docode(dmalloc_touch(node *, n));    ins_f_byte(F_DUMB_RETURN);    store_linenumbers=1;       ret=-1;    if(!num_parse_error)    {    struct callback *tmp_callback;    struct timer_oflo foo;       /* This is how long we try to optimize before giving up... */
pike.git/src/las.c:2372:       default:    free_node(n);    n=NULL;    while(args--)    {    n=mknode(F_ARG_LIST,mksvaluenode(sp-1),n);    pop_stack();    }    } -  return n; +  return dmalloc_touch(node *, n);   }      INT32 last_function_opt_info;      static int stupid_args(node *n, int expected,int vargs)   {    if(!n) return expected;    switch(n->token)    {    case F_PUSH_ARRAY: