pike.git / src / docode.c

version» Context lines:

pike.git/src/docode.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: docode.c,v 1.23 1997/09/22 01:01:15 hubbe Exp $"); + RCSID("$Id: docode.c,v 1.24 1998/01/13 22:56:42 hubbe Exp $");   #include "las.h"   #include "program.h"   #include "language.h"   #include "pike_types.h"   #include "stralloc.h"   #include "interpret.h"   #include "constants.h"   #include "array.h"   #include "pike_macros.h"   #include "error.h" - #include "pike_memory.h" + #include "memory.h"   #include "svalue.h"   #include "main.h"   #include "lex.h"   #include "builtin_functions.h"   #include "peep.h"   #include "docode.h"   #include "operators.h"      INT32 current_break=-1;   INT32 current_continue=-1;      static INT32 current_switch_case;   static INT32 current_switch_default;   static INT32 current_switch_values_on_stack;   static INT32 *current_switch_jumptable =0;    - void ins_byte(unsigned char b,int area) - { -  add_to_mem_block(area, (char *)&b, 1); - } -  - void ins_signed_byte(char b,int area) - { -  add_to_mem_block(area, (char *)&b, 1); - } -  - void ins_short(INT16 l,int area) - { -  add_to_mem_block(area, (char *)&l, sizeof(INT16)); - } -  - /* -  * Store an INT32. -  */ - void ins_int(INT32 l,int area) - { -  add_to_mem_block(area, (char *)&l+0, sizeof(INT32)); - } -  +    void upd_int(int offset, INT32 tmp)   { - #ifdef HANDLES_UNALIGNED_MEMORY_ACCESS -  *((int *)(areas[A_PROGRAM].s.str+offset))=tmp; - #else -  MEMCPY(areas[A_PROGRAM].s.str+offset, (char *)&tmp,sizeof(tmp)); - #endif +  MEMCPY(new_program->program+offset, (char *)&tmp,sizeof(tmp));   }      INT32 read_int(int offset)   { -  INT32 tmp; - #ifdef HANDLES_UNALIGNED_MEMORY_ACCESS -  tmp=*((int *)(areas[A_PROGRAM].s.str+offset)); - #else -  MEMCPY((char *)&tmp, areas[A_PROGRAM].s.str+offset,sizeof(tmp)); - #endif -  return tmp; +  return EXTRACT_INT(new_program->program+offset);   }      int store_linenumbers=1;      /*    * A mechanism to remember addresses on a stack.    */   int comp_stackp;   INT32 comp_stack[COMPILER_STACK_SIZE];   
pike.git/src/docode.c:141:    case 1: emit2(F_POP_VALUE); break;    default: emit(F_POP_N_ELEMS,x); break;    }   }      #define DO_CODE_BLOCK(X) do_pop(do_docode((X),DO_NOT_COPY | DO_POP));      int do_docode(node *n,INT16 flags)   {    int i; -  int save_current_line=current_line; +  int save_current_line=lex.current_line;    if(!n) return 0; -  current_line=n->line_number; +  lex.current_line=n->line_number;    i=do_docode2(n, flags);    -  current_line=save_current_line; +  lex.current_line=save_current_line;    return i;   }         static int is_efun(node *n, c_fun fun)   {    return n && n->token == F_CONSTANT &&    n->u.sval.subtype == FUNCTION_BUILTIN &&    n->u.sval.u.efun->function == fun;   }      static void code_expression(node *n, int flags, char *err)   {    switch(do_docode(n, flags & ~ DO_POP))    {    case 0: my_yyerror("Void expression for %s",err);    case 1: return;    case 2:    fatal("Internal compiler error (%s), line %ld, file %s\n",    err, -  (long)current_line, -  current_file?current_file->str:"Unknown"); +  (long)lex.current_line, +  lex.current_file?lex.current_file->str:"Unknown");    }   }      void do_cond_jump(node *n, int label, int iftrue, int flags)   {    iftrue=!!iftrue;    if((flags & DO_POP) && node_is_tossable(n))    {    int t,f;    t=!!node_is_true(n);
pike.git/src/docode.c:272:       if(!n) return 0;       if(flags & DO_LVALUE)    {    switch(n->token)    {    default:    yyerror("Illegal lvalue.");    emit(F_NUMBER,0); -  emit(F_NUMBER,0); -  return 2; +  return 1;       case F_LVALUE_LIST:    case F_LOCAL:    case F_GLOBAL:    case F_IDENTIFIER:    case F_INDEX:    case F_ARROW:    case F_ARG_LIST: -  +  case F_EXTERNAL:    break;    }    }       switch(n->token)    { -  +  case F_EXTERNAL: +  emit(F_LDA, n->u.integer.a); +  if(flags & DO_LVALUE) +  { +  emit(F_EXTERNAL_LVALUE, n->u.integer.b); +  return 2; +  }else{ +  emit(F_EXTERNAL, n->u.integer.b); +  return 1; +  } +  break; +  +  case F_UNDEFINED: +  yyerror("Undefined identifier"); +  emit(F_NUMBER,0); +  return 1; +     case F_PUSH_ARRAY:    code_expression(CAR(n), 0, "`@");    emit2(F_PUSH_ARRAY);    return -0x7ffffff;       case '?':    {    INT32 *prev_switch_jumptable = current_switch_jumptable;    int adroppings , bdroppings;    current_switch_jumptable=0;
pike.git/src/docode.c:361:    case F_LSH_EQ:    case F_RSH_EQ:    case F_ADD_EQ:    case F_SUB_EQ:    case F_MULT_EQ:    case F_MOD_EQ:    case F_DIV_EQ:    tmp1=do_docode(CAR(n),DO_LVALUE);   #ifdef DEBUG    if(tmp1 != 2) -  fatal("HELP! FATAL INTERNAL COMPILER ERROR\n"); +  fatal("HELP! FATAL INTERNAL COMPILER ERROR (7)\n");   #endif       if(match_types(CAR(n)->type,array_type_string) ||    match_types(CAR(n)->type,string_type_string))    {    code_expression(CDR(n), 0, "assignment");    emit2(F_LTOSVAL2);    }else{    emit2(F_LTOSVAL);    code_expression(CDR(n), 0, "assignment");
pike.git/src/docode.c:434:    emit2(CAR(n)->token);       emit2(n->token);    return n->token==F_ASSIGN;    }       default:    switch(CDR(n)->token)    {    case F_LOCAL: -  if(CDR(n)->u.number >= local_variables->max_number_of_locals) +  if(CDR(n)->u.number >= compiler_frame->max_number_of_locals)    yyerror("Illegal to use local variable here.");       code_expression(CAR(n), 0, "RHS");    emit(flags & DO_POP ? F_ASSIGN_LOCAL_AND_POP:F_ASSIGN_LOCAL,    CDR(n)->u.number );    break;       case F_IDENTIFIER: -  if(!IDENTIFIER_IS_VARIABLE( ID_FROM_INT(& fake_program, CDR(n)->u.number)->identifier_flags)) +  if(!IDENTIFIER_IS_VARIABLE( ID_FROM_INT(new_program, CDR(n)->u.number)->identifier_flags))    {    yyerror("Cannot assign functions or constants.\n");    }else{    code_expression(CAR(n), 0, "RHS");    emit(flags & DO_POP ? F_ASSIGN_GLOBAL_AND_POP:F_ASSIGN_GLOBAL,    CDR(n)->u.number);    }    break;       default:
pike.git/src/docode.c:494:    case F_OR:    case F_AND:    case F_NOT:    case F_COMPL:    case F_NEGATE:    fatal("Optimizer errror.\n");       case F_RANGE:    tmp1=do_docode(CAR(n),DO_NOT_COPY);    if(do_docode(CDR(n),DO_NOT_COPY)!=2) -  fatal("Compiler internal error (at %ld).\n",(long)current_line); +  fatal("Compiler internal error (at %ld).\n",(long)lex.current_line);    emit2(n->token);    return tmp1;       case F_INC:    case F_POST_INC:    tmp1=do_docode(CAR(n),DO_LVALUE);   #ifdef DEBUG    if(tmp1 != 2) -  fatal("HELP! FATAL INTERNAL COMPILER ERROR (again)\n"); +  fatal("HELP! FATAL INTERNAL COMPILER ERROR (1)\n");   #endif       if(flags & DO_POP)    {    emit2(F_INC_AND_POP);    return 0;    }else{    emit2(n->token);    return 1;    }       case F_DEC:    case F_POST_DEC:    tmp1=do_docode(CAR(n),DO_LVALUE);   #ifdef DEBUG    if(tmp1 != 2) -  fatal("HELP! FATAL INTERNAL COMPILER ERROR (yet again)\n"); +  fatal("HELP! FATAL INTERNAL COMPILER ERROR (2)\n");   #endif    if(flags & DO_POP)    {    emit2(F_DEC_AND_POP);    return 0;    }else{    emit2(n->token);    return 1;    }   
pike.git/src/docode.c:696:       emit2(F_MARK);    do_docode(CDR(n),0);    tmp1=store_constant(& CAR(n)->u.sval,    !(CAR(n)->tree_info & OPT_EXTERNAL_DEPEND));    emit(F_APPLY,tmp1);       return 1;    }    else if(CAR(n)->token == F_IDENTIFIER && -  IDENTIFIER_IS_FUNCTION(ID_FROM_INT(& fake_program, CAR(n)->u.number)->identifier_flags)) +  IDENTIFIER_IS_FUNCTION(ID_FROM_INT(new_program, CAR(n)->u.number)->identifier_flags))    {    emit2(F_MARK);    do_docode(CDR(n),0);    emit(F_CALL_LFUN, CAR(n)->u.number);    return 1;    }    else    {    struct pike_string *tmp;    struct efun *fun;    node *foo;       emit2(F_MARK);    do_docode(CAR(n),0);    do_docode(CDR(n),0);       tmp=findstring("call_function");    if(!tmp) yyerror("No call_function efun."); -  if(!find_module_identifier(tmp)) +  foo=find_module_identifier(tmp); +  if(!foo || !foo->token==F_CONSTANT)    {    yyerror("No call_function efun.");    }else{ -  tmp1=store_constant(sp-1, 1); -  pop_stack(); +  tmp1=store_constant(& foo->u.sval, 1);    emit(F_APPLY, tmp1);    } -  +  free_node(foo);    return 1;    }       case F_ARG_LIST:    tmp1=do_docode(CAR(n),flags & ~DO_LVALUE);    tmp1+=do_docode(CDR(n),flags);    return tmp1;          /* Switch:
pike.git/src/docode.c:1058:    emit(F_CONSTANT,tmp1);       /* copy now or later ? */    if(!(flags & DO_NOT_COPY) && !(n->tree_info & OPT_EXTERNAL_DEPEND))    emit2(F_COPY_VALUE);    return 1;       }       case F_LOCAL: -  if(n->u.number >= local_variables->max_number_of_locals) +  if(n->u.number >= compiler_frame->max_number_of_locals)    yyerror("Illegal to use local variable here.");    if(flags & DO_LVALUE)    {    emit(F_LOCAL_LVALUE,n->u.number);    return 2;    }else{    emit(F_LOCAL,n->u.number);    return 1;    }       case F_IDENTIFIER: -  if(IDENTIFIER_IS_FUNCTION(ID_FROM_INT(& fake_program, n->u.number)->identifier_flags)) +  if(IDENTIFIER_IS_FUNCTION(ID_FROM_INT(new_program, n->u.number)->identifier_flags))    {    if(flags & DO_LVALUE)    {    yyerror("Cannot assign functions.\n");    }else{    emit(F_LFUN,n->u.number);    }    }else{    if(flags & DO_LVALUE)    {