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: las.c,v 1.405 2008/02/26 21:51:37 grubba Exp $ + || $Id: las.c,v 1.406 2008/04/14 10:14:39 grubba Exp $   */      #include "global.h"
30:   #include "opcodes.h"   #include "pikecode.h"   #include "gc.h" + #include "pike_compiler.h"   #include "block_alloc.h"      /* Define this if you want the optimizer to be paranoid about aliasing
375:    yytype_error(msg, t, n->type, 0);    return 0;    } -  if (lex.pragmas & ID_STRICT_TYPES) { +  if (THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES) {    yytype_error(msg, t, n->type, YYTE_IS_WARNING);    }    if (runtime_options & RUNTIME_CHECK_TYPES) {
620:   {    node *res=alloc_node_s();    +  CHECK_COMPILER(); +    #ifdef __CHECKER__    MEMSET(res, 0, sizeof(node));   #endif /* __CHECKER__ */
627:    res->refs = 0;    add_ref(res); /* For DMALLOC... */    res->token=0; -  res->line_number=lex.current_line; -  copy_shared_string(res->current_file, lex.current_file); +  res->line_number=THIS_COMPILATION->lex.current_line; +  copy_shared_string(res->current_file, THIS_COMPILATION->lex.current_file);    res->type=0;    res->name=0;    res->node_info=0;
3235:      void fix_type_field(node *n)   { +  struct compilation *c = THIS_COMPILATION;    struct pike_type *type_a, *type_b;    struct pike_type *old_type;   
3365:    yytype_error("Bad type in assignment.",    CDR(n)->type, CAR(n)->type, 0);    } else { -  if (lex.pragmas & ID_STRICT_TYPES) { +  if (c->lex.pragmas & ID_STRICT_TYPES) {    struct pike_string *t1 = describe_type(CAR(n)->type);    struct pike_string *t2 = describe_type(CDR(n)->type);   #ifdef PIKE_DEBUG
3580:    s = pop_type();    f = CAR(n)->type?CAR(n)->type:mixed_type_string;    n->type = check_call(s, f, -  (lex.pragmas & ID_STRICT_TYPES) && +  (c->lex.pragmas & ID_STRICT_TYPES) &&    !(n->node_info & OPT_WEAK_TYPE));    args = count_arguments(s);    max_args = count_arguments(f);
3838:       n->type = check_call(call_type,    op_node->type ? op_node->type : mixed_type_string, -  (lex.pragmas & ID_STRICT_TYPES) && +  (c->lex.pragmas & ID_STRICT_TYPES) &&    !(op_node->node_info & OPT_WEAK_TYPE));    if (n->type) {    /* Type check ok. */
3902:    yytype_error("Type mismatch in case range.",    CAR(n)->type, CDR(n)->type, 0);    } -  } else if ((lex.pragmas & ID_STRICT_TYPES) && +  } else if ((c->lex.pragmas & ID_STRICT_TYPES) &&    (CAR(n)->type != CDR(n)->type)) {    /* The type should be the same for both CAR & CDR. */    if (!pike_types_le(CDR(n)->type, CAR(n)->type)) {
4016:    if (!match_types(CADAR(n)->type, index_type)) {    yytype_error("Type mismatch for index in foreach().",    index_type, CADAR(n)->type, 0); -  } else if (lex.pragmas & ID_STRICT_TYPES) { +  } else if (c->lex.pragmas & ID_STRICT_TYPES) {    yytype_error("Type mismatch for index in foreach().",    index_type, CADAR(n)->type, YYTE_IS_WARNING);    }
4046:    if (!match_types(CDDAR(n)->type, value_type)) {    yytype_error("Type mismatch for value in foreach().",    value_type, CDDAR(n)->type, 0); -  } else if (lex.pragmas & ID_STRICT_TYPES) { +  } else if (c->lex.pragmas & ID_STRICT_TYPES) {    yytype_error("Type mismatch for value in foreach().",    value_type, CDDAR(n)->type, YYTE_IS_WARNING);    }
4064:    if (!pike_types_le(array_zero, CAAR(n)->type)) {    yyerror("Bad argument 1 to foreach().");    } else { -  if ((lex.pragmas & ID_STRICT_TYPES) && +  if ((c->lex.pragmas & ID_STRICT_TYPES) &&    !pike_types_le(CAAR(n)->type, array_type_string)) {    struct pike_string *t = describe_type(CAAR(n)->type);    yywarning("Argument 1 to foreach() is not always an array.");
4944:   static void optimize(node *n)   {    node *tmp1, *tmp2, *tmp3; +  struct compilation *c = THIS_COMPILATION;    struct pike_string *save_file = -  dmalloc_touch(struct pike_string *, lex.current_file); -  INT32 save_line = lex.current_line; +  dmalloc_touch(struct pike_string *, c->lex.current_file); +  INT32 save_line = c->lex.current_line;       do    {
4963:    continue;    }    -  lex.current_line = n->line_number; -  lex.current_file = dmalloc_touch(struct pike_string *, n->current_file); +  c->lex.current_line = n->line_number; +  c->lex.current_file = dmalloc_touch(struct pike_string *, n->current_file);       n->tree_info = n->node_info;    if(car_is_node(n)) n->tree_info |= CAR(n)->tree_info;
5078:    n=n->parent;    }while(n);    -  lex.current_line = save_line; -  lex.current_file = dmalloc_touch(struct pike_string *, save_file); +  c->lex.current_line = save_line; +  c->lex.current_file = dmalloc_touch(struct pike_string *, save_file);   }      void optimize_node(node *n)
5392:    int args, vargs, ret;    struct svalue *foo;    +  CHECK_COMPILER(); +     optimize_node(n);       check_tree(n, 0);
5451:    tmp.c_fun != f_backtrace)    {   #ifdef PIKE_DEBUG +  struct compilation *c = THIS_COMPILATION; +     if(a_flag > 1)    fprintf(stderr,"%s:%d: IDENTIFIER OPTIMIZATION %s == %s\n", -  lex.current_file->str, -  lex.current_line, +  c->lex.current_file->str, +  c->lex.current_line,    name->str,    foo->u.efun->name->str);   #endif