Branch: Tag:

1998-01-13

1998-01-13 23:01:47 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

Compiler update to use two pass

Rev: src/acconfig.h:1.14
Rev: src/builtin_functions.c:1.59
Rev: src/builtin_functions.h:1.5
Rev: src/compilation.h:1.4
Rev: src/configure.in:1.149
Rev: src/cpp.c:1.3
Rev: src/docode.c:1.24
Rev: src/docode.h:1.4
Rev: src/gc.c:1.24
Rev: src/interpret.c:1.57
Rev: src/interpret.h:1.16
Rev: src/language.yacc:1.51
Rev: src/las.c:1.40
Rev: src/las.h:1.9
Rev: src/lex.c:1.37
Rev: src/lex.h:1.7
Rev: src/main.c:1.32
Rev: src/modules/Image/blit.c:1.26
Rev: src/modules/Image/colortable.c:1.33
Rev: src/modules/Image/dct.c:1.11
Rev: src/modules/Image/image.c:1.73
Rev: src/modules/Image/matrix.c:1.13
Rev: src/modules/Image/operator.c:1.11
Rev: src/modules/Image/pattern.c:1.11
Rev: src/modules/Image/pnm.c:1.9
Rev: src/modules/Image/polyfill.c:1.18
Rev: src/modules/Image/togif.c:1.29
Rev: src/modules/Image/x.c:1.17
Rev: src/modules/Pipe/pipe.c:1.15
Rev: src/modules/Regexp/glue.c:1.9
Rev: src/modules/_Crypto/cbc.c:1.10
Rev: src/modules/_Crypto/crypto.c:1.24
Rev: src/modules/_Crypto/des.c:1.11
Rev: src/modules/_Crypto/pipe.c:1.11
Rev: src/modules/_Crypto/sha.c:1.9
Rev: src/modules/files/socktest.pike:1.6
Rev: src/modules/system/system.c:1.37
Rev: src/object.c:1.31
Rev: src/object.h:1.13
Rev: src/opcodes.c:1.10
Rev: src/operators.c:1.22
Rev: src/peep.c:1.16
Rev: src/peep.in:1.9
Rev: src/pike_types.c:1.27
Rev: src/pike_types.h:1.6
Rev: src/program.c:1.48
Rev: src/program.h:1.24
Rev: src/program_areas.h:1.2
Rev: src/stralloc.c:1.21
Rev: src/stralloc.h:1.10
Rev: src/svalue.c:1.18
Rev: src/testsuite.in:1.64
Rev: src/threads.c:1.51
Rev: src/threads.h:1.26

4:   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: las.c,v 1.39 1997/10/05 03:39:25 grubba Exp $"); + RCSID("$Id: las.c,v 1.40 1998/01/13 22:56:44 hubbe Exp $");      #include "language.h"   #include "interpret.h"
34:   static node *eval(node *);   static void optimize(node *n);    - dynamic_buffer areas[NUM_AREAS]; +    node *init_node = 0;   int num_parse_error;   int cumulative_parse_error=0;
46:   {    switch(n->token)    { +  case F_EXTERNAL:    case F_IDENTIFIER:    case F_CONSTANT:    case F_LOCAL:
60:   {    switch(n->token)    { +  case F_EXTERNAL:    case F_IDENTIFIER:    case F_CONSTANT:    case F_LOCAL:
135:   static struct node_chunk *node_chunks=0;   static node *free_nodes=0;    - void free_all_nodes(void) + void free_all_nodes()   { -  if(!local_variables) +  if(!compiler_frame)    {    node *tmp;    struct node_chunk *tmp2;
240:    res=free_nodes;    free_nodes=CAR(res);    res->token=0; -  res->line_number=current_line; +  res->line_number=lex.current_line;    res->type=0;    res->node_info=0;    res->tree_info=0;
273:    }    break;    +  case F_UNDEFINED: +  res->node_info |= OPT_EXTERNAL_DEPEND | OPT_SIDE_EFFECT; +  break; +     case F_RETURN:    res->node_info |= OPT_RETURN;    break;
310:       if(a) a->parent = res;    if(b) b->parent = res; -  if(!num_parse_error) optimize(res); +     -  +  if(!num_parse_error && compiler_pass==2) +  optimize(res); +    #ifdef DEBUG    if(d_flag > 3)    verify_shared_strings_tables();
372:    struct pike_string *name;    node *n;    name = findstring(function); -  if(!name || !find_module_identifier(name)) +  if(!name || !(n=find_module_identifier(name)))    {    my_yyerror("Internally used efun undefined: %s",function);    return mkintnode(0);    } -  n=mkapplynode(mksvaluenode(sp-1), args); -  pop_stack(); +  n=mkapplynode(n, args);    return n;   }   
394:   {    node *res = mkemptynode();    res->token = F_LOCAL; -  copy_shared_string(res->type, local_variables->variable[var].type); +  copy_shared_string(res->type, compiler_frame->variable[var].type);    res->node_info = OPT_NOT_CONST;    res->tree_info=res->node_info;   #ifdef __CHECKER__
408:   {    node *res = mkemptynode();    res->token = F_IDENTIFIER; -  setup_fake_program(); -  copy_shared_string(res->type, ID_FROM_INT(&fake_program, i)->type); +  copy_shared_string(res->type, ID_FROM_INT(new_program, i)->type);       /* FIXME */ -  if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(&fake_program, i)->identifier_flags)) +  if(IDENTIFIER_IS_CONSTANT(ID_FROM_INT(new_program, i)->identifier_flags))    {    res->node_info = OPT_EXTERNAL_DEPEND;    }else{
427:    return res;   }    + node *mkexternalnode(int level, +  int i, +  struct identifier *id) + { +  node *res = mkemptynode(); +  res->token = F_EXTERNAL; +  +  copy_shared_string(res->type, id->type); +  +  /* FIXME */ +  res->node_info = OPT_NOT_CONST; +  res->tree_info=res->node_info; +  + #ifdef __CHECKER__ +  CDR(res)=0; + #endif +  res->u.integer.a = level; +  res->u.integer.b = i; +  return res; + } +    node *mkcastnode(struct pike_string *type,node *n)   {    node *res;
451:   void resolv_constant(node *n)   {    struct identifier *i; +  struct program *p; +  INT32 numid; +     if(!n)    {    push_int(0);
459:    {    case F_CONSTANT:    push_svalue(& n->u.sval); -  break; +  return;    -  case F_IDENTIFIER: -  setup_fake_program(); -  i=ID_FROM_INT(& fake_program, n->u.number); -  -  if(IDENTIFIER_IS_CONSTANT(i->identifier_flags)) +  case F_EXTERNAL: +  p=parent_compilation(n->u.integer.a); +  if(!p)    { -  push_svalue(PROG_FROM_INT(&fake_program, n->u.number)->constants + -  i->func.offset); -  }else{ -  yyerror("Identifier is not a constant"); +  yyerror("Failed to resolv external constant");    push_int(0); -  +  return;    } -  +  numid=n->u.integer.b;    break;    -  +  case F_IDENTIFIER: +  p=new_program; +  numid=n->u.number; +  break; +     case F_LOCAL:    yyerror("Expected constant, got local variable");    push_int(0); -  break; +  return;       case F_GLOBAL:    yyerror("Expected constant, got global variable");    push_int(0); -  break; +  return; +  +  default: +  yyerror("Expected constant, got something else"); +  push_int(0); +  return;    } -  +  +  i=ID_FROM_INT(p, numid); +  +  if(IDENTIFIER_IS_CONSTANT(i->identifier_flags)) +  { +  push_svalue(PROG_FROM_INT(new_program, numid)->constants + +  i->func.offset); +  }else{ +  yyerror("Identifier is not a constant"); +  push_int(0);    }    } -  + }      node *index_node(node *n, struct pike_string * id)   {
798:       case F_IDENTIFIER:    if(needlval) putchar('&'); -  setup_fake_program(); -  printf("%s",ID_FROM_INT(&fake_program, foo->u.number)->name->str); +  printf("%s",ID_FROM_INT(new_program, foo->u.number)->name->str);    break;       case F_ASSIGN:
1235:    switch(CAR(n)->token)    {    case F_IDENTIFIER: -  setup_fake_program(); -  name=ID_FROM_INT(&fake_program, CAR(n)->u.number)->name->str; +  name=ID_FROM_INT(new_program, CAR(n)->u.number)->name->str;    break;       case F_CONSTANT:
1281:    {    yyerror("You cannot return a void expression");    } -  if(local_variables && -  local_variables->current_return_type && -  !match_types(local_variables->current_return_type,CAR(n)->type) && +  if(compiler_frame && +  compiler_frame->current_return_type && +  !match_types(compiler_frame->current_return_type,CAR(n)->type) &&    !( -  local_variables->current_return_type==void_type_string && +  compiler_frame->current_return_type==void_type_string &&    CAR(n)->token == F_CONSTANT &&    IS_ZERO(& CAR(n)->u.sval)    )
1364:   static void optimize(node *n)   {    node *tmp1, *tmp2, *tmp3; -  INT32 save_line = current_line; +  INT32 save_line = lex.current_line;    do    {    if(car_is_node(n) && !(CAR(n)->node_info & OPT_OPTIMIZED))
1377:    n=CDR(n);    continue;    } -  current_line = n->line_number; +  lex.current_line = n->line_number;          n->tree_info = n->node_info;
1807:    n->node_info |= OPT_OPTIMIZED;    n=n->parent;    }while(n); -  current_line = save_line; +  lex.current_line = save_line;   }      struct timer_oflo
1842:   #endif       if(num_parse_error) return -1; -  setup_fake_program(); +     -  num_strings=fake_program.num_strings; -  num_constants=fake_program.num_constants; +  num_strings=new_program->num_strings; +  num_constants=new_program->num_constants;    jump=PC;       store_linenumbers=0;
1853:    ins_f_byte(F_DUMB_RETURN);    store_linenumbers=1;    -  setup_fake_program(); +     ret=-1;    if(!num_parse_error)    {
1896:    remove_callback(tmp_callback);    }    -  while(fake_program.num_strings > num_strings) +  while(new_program->num_strings > num_strings)    { -  fake_program.num_strings--; -  free_string(fake_program.strings[fake_program.num_strings]); -  areas[A_STRINGS].s.len-=sizeof(struct pike_string *); +  new_program->num_strings--; +  free_string(new_program->strings[new_program->num_strings]);    }    -  while(fake_program.num_constants > num_constants) +  while(new_program->num_constants > num_constants)    { -  fake_program.num_constants--; -  free_svalue(fake_program.constants + fake_program.num_constants); -  areas[A_CONSTANTS].s.len-=sizeof(struct svalue); +  new_program->num_constants--; +  free_svalue(new_program->constants + new_program->num_constants);    }    -  areas[A_PROGRAM].s.len=jump; +  new_program->num_program=jump;       return ret;   }
2037:    struct svalue *foo;      #ifdef DEBUG -  if(recoveries && sp-evaluator_stack < recoveries->sp) -  fatal("Stack error before dooptcode (underflow)\n"); - #endif -  - #ifdef DEBUG +     if(a_flag > 1)    fprintf(stderr,"Doing function '%s' at %x\n",name->str,PC);   #endif -  last_function_opt_info=OPT_SIDE_EFFECT; +        args=count_arguments(type);    if(args < 0)
2055:    }else{    vargs=0;    } +  if(compiler_pass==1) +  { +  tmp.offset=-1; +  }else{    n=mknode(F_ARG_LIST,n,0);       if((foo=is_stupid_func(n, args, vargs)))
2073:    }       tmp.offset=PC; -  ins_byte(local_variables->max_number_of_locals, A_PROGRAM); -  ins_byte(args, A_PROGRAM); +  add_to_program(compiler_frame->max_number_of_locals); +  add_to_program(args);      #ifdef DEBUG    if(a_flag > 2)
2087:    {    do_code_block(n);    } +  }    - #ifdef DEBUG -  if(recoveries && sp-evaluator_stack < recoveries->sp) -  fatal("Stack error after do_code_block (underflow)\n"); - #endif -  +     ret=define_function(name,    type,    modifiers,
2103:    return ret;   }    - INT32 get_opt_info(void) { return last_function_opt_info; } +     -  +