pike.git / src / language.yacc

version» Context lines:

pike.git/src/language.yacc:20:   %token F_BRANCH F_BRANCH_WHEN_ZERO F_BRANCH_WHEN_NON_ZERO   %token F_BRANCH_AND_POP_WHEN_ZERO F_BRANCH_AND_POP_WHEN_NON_ZERO   %token F_BRANCH_WHEN_LT F_BRANCH_WHEN_GT   %token F_BRANCH_WHEN_LE F_BRANCH_WHEN_GE   %token F_BRANCH_WHEN_EQ F_BRANCH_WHEN_NE   %token F_BRANCH_IF_LOCAL F_BRANCH_IF_NOT_LOCAL   %token F_BRANCH_IF_NOT_LOCAL_ARROW   %token F_INC_LOOP F_DEC_LOOP   %token F_INC_NEQ_LOOP F_DEC_NEQ_LOOP    + %token F_LEXICAL_LOCAL F_LEXICAL_LOCAL_LVALUE +    %token F_INDEX F_ARROW F_INDIRECT F_STRING_INDEX F_LOCAL_INDEX   %token F_LOCAL_LOCAL_INDEX F_LOCAL_ARROW F_GLOBAL_LOCAL_INDEX   %token F_POS_INT_INDEX F_NEG_INT_INDEX   %token F_LTOSVAL F_LTOSVAL2   %token F_PUSH_ARRAY   %token F_RANGE F_COPY_VALUE      /*    * Basic value pushing    */ - %token F_LFUN + %token F_LFUN F_TRAMPOLINE   %token F_GLOBAL F_GLOBAL_LVALUE   %token F_LOCAL F_2_LOCALS F_LOCAL_LVALUE F_MARK_AND_LOCAL   %token F_EXTERNAL F_EXTERNAL_LVALUE   %token F_CLEAR_LOCAL F_CLEAR_2_LOCAL F_CLEAR_4_LOCAL   %token F_CLEAR_STRING_SUBTYPE   %token F_CONSTANT F_FLOAT F_STRING F_ARROW_STRING   %token F_NUMBER F_NEG_NUMBER F_CONST_1 F_CONST0 F_CONST1 F_BIGNUM   /*    * These are the predefined functions that can be accessed from Pike.    */
pike.git/src/language.yacc:172:   %left F_LSH F_RSH   %left '+' '-'   %left '*' '%' '/'   %right F_NOT '~'   %nonassoc F_INC F_DEC      %{   /* This is the grammar definition of Pike. */      #include "global.h" - RCSID("$Id: language.yacc,v 1.108 1998/11/22 11:02:55 hubbe Exp $"); + RCSID("$Id: language.yacc,v 1.109 1999/01/31 09:01:50 hubbe Exp $");   #ifdef HAVE_MEMORY_H   #include <memory.h>   #endif      #include "interpret.h"   #include "array.h"   #include "object.h"   #include "stralloc.h"   #include "las.h"   #include "interpret.h"
pike.git/src/language.yacc:203:      #ifdef PIKE_DEBUG   #ifndef YYDEBUG   /* May also be defined by machine.h */   #define YYDEBUG 1   #endif /* YYDEBUG */   #endif         void add_local_name(struct pike_string *,struct pike_string *); + static node *lexical_islocal(struct pike_string *);      static int varargs;   static INT32 current_modifiers;   static struct pike_string *last_identifier=0;         /*    * Kludge for Bison not using prototypes.    */   #ifndef __GNUC__
pike.git/src/language.yacc:559:    if(compiler_frame->current_type)    free_string(compiler_frame->current_type);    copy_shared_string(compiler_frame->current_type,$1->u.sval.u.string);    free_node($1);    }    ;         def: modifiers type_or_error optional_stars F_IDENTIFIER    { -  push_compiler_frame(); +  push_compiler_frame(0);    if(!compiler_frame->previous ||    !compiler_frame->previous->current_type)    {    yyerror("Internal compiler fault.");    copy_shared_string(compiler_frame->current_type,    mixed_type_string);    }else{    copy_shared_string(compiler_frame->current_type,    compiler_frame->previous->current_type);    }
pike.git/src/language.yacc:986:    free_node($4);    }    ;         new_local_name: optional_stars F_IDENTIFIER    {    push_finished_type($<n>0->u.sval.u.string);    while($1--) push_type(T_ARRAY);    add_local_name($2->u.sval.u.string, compiler_pop_type()); -  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($2->u.sval.u.string))); +  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($2->u.sval.u.string),0));    free_node($2);    }    | optional_stars bad_identifier { $$=0; }    | optional_stars F_IDENTIFIER '=' expr0    {    push_finished_type($<n>0->u.sval.u.string);    while($1--) push_type(T_ARRAY);    add_local_name($2->u.sval.u.string, compiler_pop_type()); -  $$=mknode(F_ASSIGN,$4,mklocalnode(islocal($2->u.sval.u.string))); +  $$=mknode(F_ASSIGN,$4,mklocalnode(islocal($2->u.sval.u.string),0));    free_node($2);    }    | optional_stars bad_identifier '=' expr0    {    free_node($4);    $$=0;    }    | optional_stars F_IDENTIFIER '=' error    {    free_node($2);
pike.git/src/language.yacc:1022:    free_node($2);    /* No yyerok here since we aren't done yet. */    $$=0;    }    ;      new_local_name2: F_IDENTIFIER    {    add_ref($<n>0->u.sval.u.string);    add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.string); -  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($1->u.sval.u.string))); +  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(islocal($1->u.sval.u.string),0));    free_node($1);    }    | bad_identifier { $$=mkintnode(0); }    | F_IDENTIFIER '=' safe_expr0    {    add_ref($<n>0->u.sval.u.string);    add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.string); -  $$=mknode(F_ASSIGN,$3, mklocalnode(islocal($1->u.sval.u.string))); +  $$=mknode(F_ASSIGN,$3, mklocalnode(islocal($1->u.sval.u.string),0));    free_node($1);    }    | bad_identifier '=' safe_expr0 { $$=$3; }    ;      block:'{'    {    $<number>1=num_used_modules;    $<number>$=compiler_frame->current_number_of_locals;    }
pike.git/src/language.yacc:1123:    | F_DEFAULT    {    $$=mknode(F_DEFAULT,0,0); yyerror("Expected ':' after default.");    }    ;      continue: F_CONTINUE { $$=mknode(F_CONTINUE,0,0); } ;      lambda: F_LAMBDA    { -  push_compiler_frame(); +  push_compiler_frame(1);       if(compiler_frame->current_return_type)    free_string(compiler_frame->current_return_type);    copy_shared_string(compiler_frame->current_return_type,any_type_string);    }    func_args failsafe_block    {    struct pike_string *type;    char buf[40];    int f,e;
pike.git/src/language.yacc:1178:    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",    compiler_pass, buf, (long)new_program->id, local_class_counter-1);   #endif /* LAMBDA_DEBUG */       f=dooptcode(name,    $4,    type,    ID_PRIVATE | ID_INLINE);       $$=mkidentifiernode(f); +  if(compiler_frame->lexical_scope == 2) +  $$->token=F_TRAMPOLINE;    free_string(name);    free_string(type);    pop_compiler_frame();    }    ;      failsafe_program: '{' program end_block    | error { yyerrok; }    | F_LEX_EOF    {
pike.git/src/language.yacc:1658:    | idents '.' bad_identifier {}    | idents '.' error {}    ;      low_idents: F_IDENTIFIER    {    int i;    struct efun *f;    if(last_identifier) free_string(last_identifier);    copy_shared_string(last_identifier, $1->u.sval.u.string); -  if((i=islocal(last_identifier))>=0) +  +  if(($$=lexical_islocal(last_identifier)))    { -  $$=mklocalnode(i); +  /* done, nothing to do here */    }else if((i=isidentifier(last_identifier))>=0){    $$=mkidentifiernode(i);    }else if(!($$=find_module_identifier(last_identifier))){    if(!num_parse_error)    {    if(compiler_pass==2)    {    my_yyerror("'%s' undefined.", last_identifier->str);    $$=0;    }else{
pike.git/src/language.yacc:1898:    }    | F_SSCANF '(' error '}' { $$=mkintnode(0); yyerror("Missing ')'."); }    | F_SSCANF '(' error ';' { $$=mkintnode(0); yyerror("Missing ')'."); }    ;      lvalue: expr4    | '[' low_lvalue_list ']' { $$=mknode(F_ARRAY_LVALUE, $2,0); }    | type6 F_IDENTIFIER    {    add_local_name($2->u.sval.u.string,compiler_pop_type()); -  $$=mklocalnode(islocal($2->u.sval.u.string)); +  $$=mklocalnode(islocal($2->u.sval.u.string),0);    free_node($2);    }    | bad_lvalue    { $$=mkintnode(0); }    ;   low_lvalue_list: lvalue lvalue_list { $$=mknode(F_LVALUE_LIST,$1,$2); }    ;      lvalue_list: /* empty */ { $$ = 0; }    | ',' lvalue lvalue_list { $$ = mknode(F_LVALUE_LIST,$2,$3); }
pike.git/src/language.yacc:2085:   /* argument must be a shared string */   int islocal(struct pike_string *str)   {    int e;    for(e=compiler_frame->current_number_of_locals-1;e>=0;e--)    if(compiler_frame->variable[e].name==str)    return e;    return -1;   }    + /* argument must be a shared string */ + static node *lexical_islocal(struct pike_string *str) + { +  int e,depth=0; +  struct compiler_frame *f=compiler_frame; +  +  while(1) +  { +  for(e=f->current_number_of_locals-1;e>=0;e--) +  { +  if(f->variable[e].name==str) +  { +  struct compiler_frame *q=compiler_frame; +  while(q!=f) +  { +  q->lexical_scope=2; +  q=q->previous; +  } +  return mklocalnode(e,depth); +  } +  } +  if(!f->lexical_scope) return 0; +  depth++; +  f=f->previous; +  } + } +    void cleanup_compiler(void)   {    if(last_identifier)    {    free_string(last_identifier);    last_identifier=0;    }   }