Branch: Tag:

2008-04-14

2008-04-14 10:14:41 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Pike compiler mega patch.
Added predef::CompilerEnvironment, which is a wrapper for struct compilation.
Moved the definition of struct compilation to the new header file "pike_compiler.h".
The compilation struct is now contained in the current context in the current_object during compilation.
The global variable lex is no more, it has moved into the compilation struct.
Added enter_compiler() and exit_compiler().
predef::compile() is now shorthand for predef::CompilerContext()->compile().

Rev: src/builtin_functions.c:1.652
Rev: src/compilation.h:1.35
Rev: src/docode.c:1.197
Rev: src/docode.h:1.20
Rev: src/dynamic_load.c:1.90
Rev: src/encode.c:1.263
Rev: src/language.yacc:1.411
Rev: src/las.c:1.406
Rev: src/lex.c:1.121
Rev: src/lex.h:1.36
Rev: src/lexer.h:1.66
Rev: src/module.c:1.52
Rev: src/object.c:1.284
Rev: src/operators.c:1.230
Rev: src/pike_compiler.h:1.1
Rev: src/pike_types.c:1.321
Rev: src/program.c:1.660
Rev: src/program.h:1.237

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: docode.c,v 1.196 2008/03/22 13:22:20 grubba Exp $ + || $Id: docode.c,v 1.197 2008/04/14 10:14:35 grubba Exp $   */      #include "global.h"
27:   #include "lex.h"   #include "mapping.h"   #include "multiset.h" + #include "pike_compiler.h"      static int do_docode2(node *n, int flags);   
187:      int do_jump(int token,INT32 lbl)   { +  struct compilation *c = THIS_COMPILATION;    if(lbl==-1) lbl=alloc_label();    emit1(token, lbl);    return lbl;
201:      static int do_branch(INT32 lbl)   { +  struct compilation *c = THIS_COMPILATION;    if(lbl==-1)    {    lbl=alloc_label();
232:      static void low_insert_label(int lbl)   { +  struct compilation *c = THIS_COMPILATION;    lbl_cache[ lbl % LBLCACHESIZE ] = CURRENT_INSTR;    emit1(F_LABEL, lbl);   }
245:      void do_pop(int x)   { +  struct compilation *c = THIS_COMPILATION;   #ifdef PIKE_DEBUG    if (x < 0) Pike_fatal("Cannot do pop of %d args.\n", x);   #endif
259:      static void do_pop_mark(void *ignored)   { +  struct compilation *c = THIS_COMPILATION;    emit0(F_POP_MARK);   }      static void do_pop_to_mark(void *ignored)   { -  +  struct compilation *c = THIS_COMPILATION;    emit0(F_POP_TO_MARK);   }      static void do_cleanup_synch_mark(void)   { -  +  struct compilation *c = THIS_COMPILATION;    if (d_flag > 2)    emit0(F_CLEANUP_SYNCH_MARK);   }      static void do_escape_catch(void)   { -  +  struct compilation *c = THIS_COMPILATION;    emit0(F_ESCAPE_CATCH);   }   
284:   {    int i;    int stack_depth_save = current_stack_depth; -  int save_current_line=lex.current_line; +  struct compilation *c = THIS_COMPILATION; +  int save_current_line = c->lex.current_line;    if(!n) return 0; -  lex.current_line=n->line_number; +  c->lex.current_line=n->line_number;   #ifdef PIKE_DEBUG    if (current_stack_depth == -4711) Pike_fatal("do_docode() used outside docode().\n");   #endif    i=do_docode2(n, flags);    current_stack_depth = stack_depth_save + i;    -  lex.current_line=save_current_line; +  c->lex.current_line=save_current_line;    return i;   }   
313:    case 2:    Pike_fatal("Internal compiler error (%s), line %ld, file %s\n",    err, -  (long)lex.current_line, -  lex.current_file?lex.current_file->str:"Unknown"); +  (long)THIS_COMPILATION->lex.current_line, +  THIS_COMPILATION->lex.current_file->str);    }   }   
412:      int generate_call_function(node *n)   { +  struct compilation *c = THIS_COMPILATION;    emit0(F_MARK);    PUSH_CLEANUP_FRAME(do_pop_mark, 0);    do_docode(CDR(n),DO_NOT_COPY);
433:   static int do_lfun_call(int id, node *args)   {   #if 1 +  struct compilation *c = THIS_COMPILATION;    struct reference *ref =    Pike_compiler->new_program->identifier_references + id;   
509:   static void emit_apply_builtin(char *func)   {    INT32 tmp1; +  struct compilation *c = THIS_COMPILATION;    struct pike_string *n1=make_shared_string(func);    node *n=find_module_identifier(n1,0);    free_string(n1);
535:   static int do_encode_automap_arg_list(node *n,    int flags)   { +  struct compilation *c = THIS_COMPILATION;    int stack_depth_save = current_stack_depth;    if(!n) return 0;    switch(n->token)
572:   static void emit_builtin_svalue(char *func)   {    INT32 tmp1; +  struct compilation *c = THIS_COMPILATION;    struct pike_string *n1=make_shared_string(func);    node *n=find_module_identifier(n1,0);    free_string(n1);
594:      static void emit_range (node *n DO_IF_DEBUG (COMMA int num_args))   { +  struct compilation *c = THIS_COMPILATION;    node *low = CADR (n), *high = CDDR (n);    int bound_types;   
640:      static void emit_multi_assign(node *vals, node *vars, int no)   { +  struct compilation *c = THIS_COMPILATION;    node *var;    node *val;    node **valp = my_get_arg(&vals, no);
762:      static int do_docode2(node *n, int flags)   { +  struct compilation *c = THIS_COMPILATION;    ptrdiff_t tmp1,tmp2,tmp3;    int ret;   
2128:    if (!match_types(case_val->type, current_switch.type)) {    yytype_error("Type mismatch in case.",    current_switch.type, case_val->type, 0); -  } else if (lex.pragmas & ID_STRICT_TYPES) { +  } else if (c->lex.pragmas & ID_STRICT_TYPES) {    yytype_error("Type mismatch in case.",    current_switch.type, case_val->type, YYTE_IS_WARNING);    }
2261:    struct statement_label_name *lbl_name;    for (lbl_name = label->name; lbl_name; lbl_name = lbl_name->next)    if (lbl_name->str == name.str) { -  INT32 save_line = lex.current_line; -  lex.current_line = name.line_number; +  INT32 save_line = c->lex.current_line; +  c->lex.current_line = name.line_number;    my_yyerror("Duplicate nested labels, previous one on line %d.",    lbl_name->line_number); -  lex.current_line = save_line; +  c->lex.current_line = save_line;    goto label_check_done;    }    }
2657:   /* Used to generate code for functions. */   INT32 do_code_block(node *n)   { +  struct compilation *c = THIS_COMPILATION;    INT32 entry_point;   #ifdef PIKE_DEBUG    if (current_stack_depth != -4711) Pike_fatal("Reentrance in do_code_block().\n");