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.179 2000/05/11 14:09:45 grubba Exp $"); + RCSID("$Id: las.c,v 1.180 2000/06/24 00:48:13 hubbe 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:33:   #include "opcodes.h"      #define LASDEBUG      int lasdebug=0;      static node *eval(node *);   static void optimize(node *n);   static node *localopt(node *n);    - node *init_node = 0; - int num_parse_error; +    int cumulative_parse_error=0;   extern char *get_type_name(int);      #define MAX_GLOBAL 2048      /* #define yywarning my_yyerror */      int car_is_node(node *n)   {    switch(n->token)
pike.git/src/las.c:340: Inside #if defined(SHARED_NODES)
  }      #else /* !SHARED_NODES */      #define freeze_node(X) (X)      #endif /* SHARED_NODES */      void free_all_nodes(void)   { -  if(!compiler_frame) +  if(!Pike_compiler->compiler_frame)    {    node *tmp;    struct node_s_block *tmp2;    int e=0;      #ifndef PIKE_DEBUG    if(cumulative_parse_error)    {   #endif   
pike.git/src/las.c:672:    if(token != F_ARG_LIST && (a || b))    res->node_info |= OPT_TRY_OPTIMIZE;       res->tree_info |= res->node_info;      #ifdef PIKE_DEBUG    if(d_flag > 3)    verify_shared_strings_tables();   #endif    -  if(!num_parse_error && compiler_pass==2) +  if(!Pike_compiler->num_parse_error && Pike_compiler->compiler_pass==2)    {    check_tree(res,0);    optimize(res);    check_tree(res,0);    }      #ifdef PIKE_DEBUG    if(d_flag > 3)    verify_shared_strings_tables();   #endif
pike.git/src/las.c:792:    return mkefuncallnode(oper_id, arg1);   }      node *debug_mklocalnode(int var, int depth)   {    struct compiler_frame *f;    int e;    node *res = mkemptynode();    res->token = F_LOCAL;    -  f=compiler_frame; +  f=Pike_compiler->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 | 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;
pike.git/src/las.c:822:    /* return freeze_node(res); */   #endif /* SHARED_NODES */       return res;   }      node *debug_mkidentifiernode(int i)   {    node *res = mkemptynode();    res->token = F_IDENTIFIER; -  copy_shared_string(res->type, ID_FROM_INT(new_program, i)->type); +  copy_shared_string(res->type, ID_FROM_INT(Pike_compiler->new_program, i)->type);       /* FIXME */ -  if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(new_program, i)->identifier_flags)) +  if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(Pike_compiler->new_program, i)->identifier_flags))    {    res->node_info = OPT_EXTERNAL_DEPEND;    }else{    res->node_info = OPT_NOT_CONST;    }    res->tree_info=res->node_info;      #ifdef __CHECKER__    _CDR(res) = 0;   #endif    res->u.id.number = i;   #ifdef SHARED_NODES -  res->u.id.prog = new_program; +  res->u.id.prog = Pike_compiler->new_program;   #endif /* SHARED_NODES */       res = freeze_node(res);       check_tree(res,0);    return res;   }      node *debug_mktrampolinenode(int i)   {    node *res = mkemptynode();    res->token = F_TRAMPOLINE; -  copy_shared_string(res->type, ID_FROM_INT(new_program, i)->type); +  copy_shared_string(res->type, ID_FROM_INT(Pike_compiler->new_program, i)->type);       /* FIXME */ -  if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(new_program, i)->identifier_flags)) +  if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(Pike_compiler->new_program, i)->identifier_flags))    {    res->node_info = OPT_EXTERNAL_DEPEND;    }else{    res->node_info = OPT_NOT_CONST;    }    res->tree_info=res->node_info;      #ifdef __CHECKER__    _CDR(res) = 0;   #endif    res->u.id.number = i;   #ifdef SHARED_NODES -  res->u.id.prog = new_program; +  res->u.id.prog = Pike_compiler->new_program;   #endif /* SHARED_NODES */       res = freeze_node(res);       check_tree(res,0);    return res;   }      node *debug_mkexternalnode(int level,    int i,
pike.git/src/las.c:902:    }    res->tree_info = res->node_info;      #ifdef __CHECKER__    _CDR(res) = 0;   #endif    res->u.integer.a = level;    res->u.integer.b = i;       /* Bzot-i-zot */ -  new_program->flags |= PROGRAM_USES_PARENT; +  Pike_compiler->new_program->flags |= PROGRAM_USES_PARENT;       return freeze_node(res);   }      node *debug_mkcastnode(struct pike_string *type,node *n)   {    node *res;       if(!n) return 0;   
pike.git/src/las.c:959:    node *res;       if(!n) return 0;      #ifdef PIKE_DEBUG    if (!type) {    fatal("Soft cast to no type!\n");    }   #endif /* PIKE_DEBUG */    -  if (compiler_pass == 2) { +  if (Pike_compiler->compiler_pass == 2) {    if (type == void_type_string) {    yywarning("Soft cast to void.");    return mknode(F_POP_VALUE, n, 0);    }       if(type==n->type) {    struct pike_string *t1 = describe_type(type);    yywarning("Soft cast to %s is a noop.", t1->str);    free_string(t1);    return n;
pike.git/src/las.c:1038:    if(!p)    {    yyerror("Failed to resolv external constant");    push_int(0);    return;    }    numid=n->u.integer.b;    break;       case F_IDENTIFIER: -  p=new_program; +  p=Pike_compiler->new_program;    numid=n->u.id.number;    break;       case F_LOCAL:    /* FIXME: Ought to have the name of the identifier in the message. */    yyerror("Expected constant, got local variable");    push_int(0);    return;       case F_GLOBAL:    /* FIXME: Ought to have the name of the identifier in the message. */    yyerror("Expected constant, got global variable");    push_int(0);    return;       case F_UNDEFINED: -  if(compiler_pass==2) { +  if(Pike_compiler->compiler_pass==2) {    /* FIXME: Ought to have the name of the identifier in the message. */    yyerror("Expected constant, got undefined identifier");    }    push_int(0);    return;       default:    {    char fnord[1000];    if(is_const(n))
pike.git/src/las.c:1103:    * This code doesn't produce function pointers for class constants,    * which can be harmful...    * /Hubbe    */    if(IDENTIFIER_IS_CONSTANT(i->identifier_flags))    {    if(i->func.offset != -1)    {    push_svalue(&PROG_FROM_INT(p, numid)->constants[i->func.offset].sval);    }else{ -  if(compiler_pass!=1) +  if(Pike_compiler->compiler_pass!=1)    yyerror("Constant is not defined yet.");    push_int(0);    }    }else{    my_yyerror("Identifier '%s' is not a constant", i->name->str);    push_int(0);    }    }   }   
pike.git/src/las.c:1133:    if(!sp[-1].u.object->prog)    {    pop_stack();    push_int(0);    }else{    f_object_program(1);    }    break;       default: -  if (compiler_pass!=1) +  if (Pike_compiler->compiler_pass!=1)    yyerror("Illegal program identifier");    pop_stack();    push_int(0);       case T_FUNCTION:    case T_PROGRAM:    break;    }   }   
pike.git/src/las.c:1157:    check_tree(n,0);       resolv_class(n);    switch(sp[-1].type)    {    case T_FUNCTION:    if(program_from_function(sp-1))    break;       default: -  if (compiler_pass!=1) +  if (Pike_compiler->compiler_pass!=1)    yyerror("Illegal program identifier");    pop_stack();    push_int(0);       case T_PROGRAM:    break;    }   }      
pike.git/src/las.c:1196:    my_yyerror("Couldn't index module '%s'.", node_name);    } else {    yyerror("Couldn't index module.");    }    push_int(0);    }else{    resolv_constant(n);    switch(sp[-1].type)    {    case T_INT: -  if(!num_parse_error) { +  if(!Pike_compiler->num_parse_error) {    if (node_name) {    my_yyerror("Failed to index module '%s' with '%s' "    "(module doesn't exist?)",    node_name, id->str);    } else {    my_yyerror("Failed to index module with '%s' "    "(module doesn't exist?)",    id->str);    }    }
pike.git/src/las.c:1364:    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:    return make_node_from_mapping(s->u.mapping);       case T_OBJECT: -  if(s->u.object == fake_object) +  if(s->u.object == Pike_compiler->fake_object)    {    return mkefuncallnode("this_object", 0);    }    if(s->u.object->next == s->u.object)    {    int x=0;    struct object *o;    node *n=mkefuncallnode("this_object", 0); -  for(o=fake_object;o!=s->u.object;o=o->parent) +  for(o=Pike_compiler->fake_object;o!=s->u.object;o=o->parent)    {    n=mkefuncallnode("function_object",    mkefuncallnode("object_program",n));    }    return n;    }    break;       case T_FUNCTION:    {    if(s->subtype != FUNCTION_BUILTIN)    { -  if(s->u.object == fake_object) +  if(s->u.object == Pike_compiler->fake_object)    return mkidentifiernode(s->subtype);       if(s->u.object->next == s->u.object)    {    int x=0;    struct object *o; -  for(o=fake_object->parent;o!=s->u.object;o=o->parent) x++; +  for(o=Pike_compiler->fake_object->parent;o!=s->u.object;o=o->parent) x++;    return mkexternalnode(x, s->subtype,    ID_FROM_INT(o->prog, s->subtype));       }      /* yyerror("Non-constant function pointer! (should not happen!)"); */    }    }    }   
pike.git/src/las.c:1660:    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); +  if (Pike_compiler->new_program) { +  fprintf(stderr, "%s",ID_FROM_INT(Pike_compiler->new_program, foo->u.id.number)->name->str);    } else {    fprintf(stderr, "unknown identifier");    }    break;       case F_TRAMPOLINE: -  if (new_program) { +  if (Pike_compiler->new_program) {    fprintf(stderr, "trampoline<%s>", -  ID_FROM_INT(new_program, foo->u.id.number)->name->str); +  ID_FROM_INT(Pike_compiler->new_program, foo->u.id.number)->name->str);    } else {    fprintf(stderr, "trampoline<unknown identifier>");    }    break;       case F_ASSIGN:    low_print_tree(_CDR(foo),1);    fprintf(stderr, "=");    low_print_tree(_CAR(foo),0);    break;
pike.git/src/las.c:2266:    case F_INDEX:    case F_ARROW:    if (!CAR(n) || (CAR(n)->type == void_type_string)) {    my_yyerror("Indexing a void expression.");    /* The optimizer converts this to an expression returning 0. */    copy_shared_string(n->type, zero_type_string);    } else {    type_a=CAR(n)->type;    type_b=CDR(n)->type;    if(!check_indexing(type_a, type_b, n)) -  if(!catch_level) +  if(!Pike_compiler->catch_level)    my_yyerror("Indexing on illegal type.");    n->type=index_type(type_a, type_b,n);    }    break;       case F_APPLY:    if (!CAR(n) || (CAR(n)->type == void_type_string)) {    my_yyerror("Calling a void expression.");    } else {    struct pike_string *s;
pike.git/src/las.c:2312:    free_string(s);    break;    }       switch(CAR(n)->token)    {   #if 0 /* FIXME */    case F_TRAMPOLINE:   #endif    case F_IDENTIFIER: -  name=ID_FROM_INT(new_program, CAR(n)->u.id.number)->name->str; +  name=ID_FROM_INT(Pike_compiler->new_program, CAR(n)->u.id.number)->name->str;    break;       case F_ARROW:    case F_INDEX:    if(CDAR(n)->token == F_CONSTANT &&    CDAR(n)->u.sval.type == T_STRING)    {    name=CDAR(n)->u.sval.u.string->str;    }else{    name="dynamically resolved function";
pike.git/src/las.c:2442:   #endif /* SHARED_NODES */    _CAR(n) = mkintnode(0);    copy_shared_string(n->type, CAR(n)->type);   #ifdef SHARED_NODES    n->hash = hash_node(n);    n->node_info |= OPT_DEFROSTED;    add_node(n);   #endif /* SHARED_NODES */    break;    } -  } else if(compiler_frame && compiler_frame->current_return_type) { -  if (!pike_types_le(CAR(n)->type, compiler_frame->current_return_type) && +  } else if(Pike_compiler->compiler_frame && Pike_compiler->compiler_frame->current_return_type) { +  if (!pike_types_le(CAR(n)->type, Pike_compiler->compiler_frame->current_return_type) &&    !( -  compiler_frame->current_return_type==void_type_string && +  Pike_compiler->compiler_frame->current_return_type==void_type_string &&    CAR(n)->token == F_CONSTANT &&    IS_ZERO(& CAR(n)->u.sval)    )    ) { -  if (!match_types(compiler_frame->current_return_type,CAR(n)->type)) +  if (!match_types(Pike_compiler->compiler_frame->current_return_type,CAR(n)->type))    {    yyerror("Wrong return type."); -  yyexplain_nonmatching_types(compiler_frame->current_return_type, +  yyexplain_nonmatching_types(Pike_compiler->compiler_frame->current_return_type,    CAR(n)->type,0);    }    else if (lex.pragmas & ID_STRICT_TYPES)    {    yytype_error("Return type mismatch.", -  compiler_frame->current_return_type, +  Pike_compiler->compiler_frame->current_return_type,    CAR(n)->type,    YYTE_IS_WARNING);    }    }    }    copy_shared_string(n->type,void_type_string);    break;       case F_CASE:    if (CDR(n) && CAR(n)) {
pike.git/src/las.c:3605:    int ret;      #ifdef PIKE_DEBUG    if(l_flag > 3 && n)    {    fprintf(stderr,"Evaluating (tree info=%x):",n->tree_info);    print_tree(n);    }   #endif    -  if(num_parse_error) return -1; +  if(Pike_compiler->num_parse_error) return -1;    -  num_strings=new_program->num_strings; -  num_constants=new_program->num_constants; +  num_strings=Pike_compiler->new_program->num_strings; +  num_constants=Pike_compiler->new_program->num_constants;    jump=PC;       store_linenumbers=0;    docode(dmalloc_touch(node *, n));    ins_f_byte(F_DUMB_RETURN);    store_linenumbers=1;       ret=-1; -  if(!num_parse_error) +  if(!Pike_compiler->num_parse_error)    {    struct callback *tmp_callback;    struct timer_oflo foo;       /* This is how long we try to optimize before giving up... */    foo.counter=10000;    foo.yes=0;       tmp_callback=add_to_callback(&evaluator_callbacks,    check_evaluation_time,    (void *)&foo,0);    -  if(apply_low_safe_and_stupid(fake_object, jump)) +  if(apply_low_safe_and_stupid(Pike_compiler->fake_object, jump))    {    /* Generate error message */ -  if(!catch_level) +  if(!Pike_compiler->catch_level)    {    if(throw_value.type == T_ARRAY && throw_value.u.array->size)    {    union anything *a;    a=low_array_get_item_ptr(throw_value.u.array, 0, T_STRING);    if(a)    {    yyerror(a->string->str);    }else{    yyerror("Nonstandard error format.");
pike.git/src/las.c:3672:    }else{    if(foo.yes)    pop_n_elems(sp-save_sp);    else    ret=sp-save_sp;    }       remove_callback(tmp_callback);    }    -  while(new_program->num_strings > num_strings) +  while(Pike_compiler->new_program->num_strings > num_strings)    { -  new_program->num_strings--; -  free_string(new_program->strings[new_program->num_strings]); +  Pike_compiler->new_program->num_strings--; +  free_string(Pike_compiler->new_program->strings[Pike_compiler->new_program->num_strings]);    }    -  while(new_program->num_constants > num_constants) +  while(Pike_compiler->new_program->num_constants > num_constants)    {    struct program_constant *p_const;    -  new_program->num_constants--; +  Pike_compiler->new_program->num_constants--;    -  p_const = new_program->constants + new_program->num_constants; +  p_const = Pike_compiler->new_program->constants + Pike_compiler->new_program->num_constants;       free_svalue(&p_const->sval);    if (p_const->name) {    free_string(p_const->name);    p_const->name = NULL;    }    }    -  new_program->num_program=jump; +  Pike_compiler->new_program->num_program=jump;       return ret;   }      static node *eval(node *n)   {    node *new;    int args;    extern struct svalue *sp;    if(!is_const(n) || n->token==':')
pike.git/src/las.c:3715:       args=eval_low(n);       switch(args)    {    case -1:    return n;    break;       case 0: -  if(catch_level) return n; +  if(Pike_compiler->catch_level) return n;    free_node(n);    n=0;    break;       case 1: -  if(catch_level && IS_ZERO(sp-1)) +  if(Pike_compiler->catch_level && IS_ZERO(sp-1))    {    pop_stack();    return n;    }    if (n->token == F_SOFT_CAST) {    new = mksoftcastnode(n->type, mksvaluenode(sp-1));    } else {    new = mksvaluenode(sp-1);    if (n->type && (!new->type || ((n->type != new->type) &&    pike_types_le(n->type,new->type)))) {
pike.git/src/las.c:3876:       args=count_arguments(type);    if(args < 0)    {    args=~args;    vargs=IDENTIFIER_VARARGS;    }else{    vargs=0;    }    -  if(compiler_frame->lexical_scope & SCOPE_SCOPED) +  if(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED)    vargs|=IDENTIFIER_SCOPED;    -  if(compiler_frame->lexical_scope & SCOPE_SCOPE_USED) +  if(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPE_USED)    vargs|=IDENTIFIER_SCOPE_USED;    -  if(compiler_pass==1) +  if(Pike_compiler->compiler_pass==1)    {    tmp.offset=-1;   #ifdef PIKE_DEBUG    if(a_flag > 4)    {    fprintf(stderr,"Making prototype (pass 1) for: ");    print_tree(n);    }   #endif    }else{
pike.git/src/las.c:3930: Inside #if defined(PIKE_DEBUG)
   lex.current_line,    name->str,    foo->u.efun->name->str);   #endif    return ret;    }    }    }       tmp.offset=PC; -  compiler_frame->num_args=args; +  Pike_compiler->compiler_frame->num_args=args;      #ifdef PIKE_DEBUG    if(a_flag > 2)    {    fprintf(stderr,"Coding: ");    print_tree(check_node_hash(n));    }   #endif -  if(!num_parse_error) +  if(!Pike_compiler->num_parse_error)    {    extern int remove_clear_locals;    remove_clear_locals=args;    if(vargs) remove_clear_locals++;    do_code_block(check_node_hash(n));    remove_clear_locals=0x7fffffff;    }    }       ret=define_function(name,