pike.git / src / lex.c

version» Context lines:

pike.git/src/lex.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: lex.c,v 1.13 1997/01/27 01:20:04 hubbe Exp $"); + RCSID("$Id: lex.c,v 1.14 1997/01/30 03:51:34 hubbe Exp $");   #include "language.h"   #include "array.h"   #include "lex.h"   #include "stralloc.h"   #include "dynamic_buffer.h"   #include "constants.h"   #include "hashtable.h"   #include "stuff.h"   #include "memory.h"   #include "interpret.h"
pike.git/src/lex.c:50:   };      struct pike_predef_s *pike_predefs=0;      static int calc();   static void calc1();      void exit_lex()   {   #ifdef DEBUG -  if(p_flag > 2) +  if(p_flag)    {    int e;    fprintf(stderr,"Opcode usage: (opcode, runned, compiled)\n");    for(e=0;e<F_MAX_OPCODE-F_OFFSET;e++)    {    fprintf(stderr,":: %-20s %8ld %8ld\n",    low_get_f_name(e+F_OFFSET,0),    (long)instrs[e].runs,    (long)instrs[e].compiles);    }
pike.git/src/lex.c:137:   { "void", F_VOID_ID, },   { "while", F_WHILE, },   };      struct keyword instr_names[]=   {   { "!", F_NOT },   { "!=", F_NE },   { "%", F_MOD },   { "%=", F_MOD_EQ }, - { "& global", F_GLOBAL_LVALUE }, - { "& local", F_LOCAL_LVALUE }, + { "& global", F_GLOBAL_LVALUE, 1 }, + { "& local", F_LOCAL_LVALUE, 1 },   { "&", F_AND }, - { "&&", F_LAND }, + { "&&", F_LAND, 1 },   { "&=", F_AND_EQ },   { "*", F_MULTIPLY },   { "*=", F_MULT_EQ },   { "+", F_ADD }, - { "++Loop", F_INC_LOOP }, - { "++Loop!=", F_INC_NEQ_LOOP }, + { "++Loop", F_INC_LOOP, 1 }, + { "++Loop!=", F_INC_NEQ_LOOP, 1 },   { "++x", F_INC },   { "+=", F_ADD_EQ },   { "-", F_SUBTRACT }, - { "-", F_SUBTRACT }, - { "--Loop", F_DEC_LOOP }, - { "--Loop!=", F_DEC_NEQ_LOOP }, + { "--Loop", F_DEC_LOOP, 1 }, + { "--Loop!=", F_DEC_NEQ_LOOP, 1 },   { "--x", F_DEC },   { "-=", F_SUB_EQ },   { "/", F_DIVIDE },   { "/=", F_DIV_EQ },   { "<", F_LT },   { "<<", F_LSH },   { "<<=", F_LSH_EQ },   { "<=", F_LE },   { "==", F_EQ },   { ">", F_GT },   { ">=", F_GE },   { ">>", F_RSH },   { ">>=", F_RSH_EQ },   { "@", F_PUSH_ARRAY },   { "^", F_XOR },   { "^=", F_XOR_EQ }, - { "add 1024 to opcode", F_ADD_1024 }, - { "add 256 to opcode", F_ADD_256 }, - { "add 512 to opcode", F_ADD_512 }, - { "add 768 to opcode", F_ADD_768 }, - { "add X*256 to opcode",F_ADD_256X }, +    { "arg+=1024", F_PREFIX_1024 },   { "arg+=256", F_PREFIX_256 },   { "arg+=256*X", F_PREFIX_CHARX256 },   { "arg+=256*XX", F_PREFIX_WORDX256 },   { "arg+=256*XXX", F_PREFIX_24BITX256 },   { "arg+=512", F_PREFIX_512 },   { "arg+=768", F_PREFIX_768 },   { "assign and pop", F_ASSIGN_AND_POP }, - { "assign global", F_ASSIGN_GLOBAL }, - { "assign global and pop", F_ASSIGN_GLOBAL_AND_POP }, - { "assign local", F_ASSIGN_LOCAL }, - { "assign local and pop", F_ASSIGN_LOCAL_AND_POP }, + { "assign global", F_ASSIGN_GLOBAL, 1 }, + { "assign global and pop", F_ASSIGN_GLOBAL_AND_POP, 1 }, + { "assign local", F_ASSIGN_LOCAL, 1 }, + { "assign local and pop", F_ASSIGN_LOCAL_AND_POP, 1 },   { "assign", F_ASSIGN }, - { "branch non zero", F_BRANCH_WHEN_NON_ZERO }, - { "branch when zero", F_BRANCH_WHEN_ZERO }, + { "branch non zero", F_BRANCH_WHEN_NON_ZERO, 1 }, + { "branch when zero", F_BRANCH_WHEN_ZERO, 1 },   { "break", F_BREAK },   { "case", F_CASE },   { "cast", F_CAST }, - { "catch", F_CATCH }, + { "catch", F_CATCH, 1 },   { "const-1", F_CONST_1 }, - { "constant", F_CONSTANT }, + { "constant", F_CONSTANT, 1 },   { "continue", F_CONTINUE },   { "copy_value", F_COPY_VALUE },   { "default", F_DEFAULT },   { "do-while", F_DO },   { "dumb return", F_DUMB_RETURN },   { "float number", F_FLOAT },   { "for", F_FOR }, - { "foreach", F_FOREACH }, - { "global", F_GLOBAL }, + { "foreach", F_FOREACH, 1 }, + { "global", F_GLOBAL, 1 },   { "index", F_INDEX }, - { "->", F_ARROW }, + { "->", F_ARROW, 1 },   { "clear string subtype", F_CLEAR_STRING_SUBTYPE }, - { "arrow string", F_ARROW_STRING }, + { "arrow string", F_ARROW_STRING, 1 },   { "indirect", F_INDIRECT }, - { "jump", F_BRANCH }, - { "local function call",F_CALL_LFUN }, - { "local function call and pop",F_CALL_LFUN_AND_POP }, - { "local function", F_LFUN }, - { "local", F_LOCAL }, + { "jump", F_BRANCH, 1 }, + { "local function call",F_CALL_LFUN, 1 }, + { "local function call and pop",F_CALL_LFUN_AND_POP, 1 }, + { "local function", F_LFUN, 1 }, + { "local", F_LOCAL, 1 }, + { "mark & local", F_MARK_AND_LOCAL, 1 },   { "ltosval2", F_LTOSVAL2 },   { "lvalue to svalue", F_LTOSVAL },   { "lvalue_list", F_LVALUE_LIST },   { "mark", F_MARK },   { "mark mark", F_MARK2 }, - { "negative number", F_NEG_NUMBER }, - { "number", F_NUMBER }, + { "negative number", F_NEG_NUMBER, 1 }, + { "number", F_NUMBER, 1 },   { "pop", F_POP_VALUE }, - { "pop_n_elems", F_POP_N_ELEMS }, + { "pop_n_elems", F_POP_N_ELEMS, 1 },   { "push 0", F_CONST0 },   { "push 1", F_CONST1 },   { "push 0x7fffffff", F_BIGNUM },   { "range", F_RANGE },   { "return", F_RETURN },   { "return 0", F_RETURN_0 }, - { "sscanf", F_SSCANF }, - { "string", F_STRING }, - { "switch", F_SWITCH }, + { "sscanf", F_SSCANF, 1 }, + { "string", F_STRING, 1 }, + { "switch", F_SWITCH, 1 },   { "unary minus", F_NEGATE },   { "while", F_WHILE },   { "x++ and pop", F_INC_AND_POP },   { "x++", F_POST_INC },   { "x-- and pop", F_DEC_AND_POP },   { "x--", F_POST_DEC },   { "|", F_OR },   { "|=", F_OR_EQ }, - { "||", F_LOR }, + { "||", F_LOR, 1 },   { "~", F_COMPL }, - { "label", F_LABEL }, - { "data", F_POINTER }, - { "align", F_ALIGN }, - { "call", F_APPLY }, - { "clear local", F_CLEAR_LOCAL }, - { "++local", F_INC_LOCAL }, - { "++local and pop", F_INC_LOCAL_AND_POP }, - { "local++", F_POST_INC_LOCAL }, - { "--local", F_DEC_LOCAL }, - { "--local and pop", F_DEC_LOCAL_AND_POP }, - { "local--", F_POST_DEC_LOCAL }, - { "branch if <", F_BRANCH_WHEN_LT }, - { "branch if >", F_BRANCH_WHEN_GT }, - { "branch if <=", F_BRANCH_WHEN_LE }, - { "branch if >=", F_BRANCH_WHEN_GE }, - { "branch if ==", F_BRANCH_WHEN_EQ }, - { "branch if !=", F_BRANCH_WHEN_NE }, + { "label", F_LABEL,1 }, + { "data", F_POINTER, 1 }, + { "align", F_ALIGN, 1 }, + { "call", F_APPLY, 1 }, + { "clear local", F_CLEAR_LOCAL, 1 }, + { "clear 2 local", F_CLEAR_2_LOCAL, 1 }, + { "++local", F_INC_LOCAL, 1 }, + { "++local and pop", F_INC_LOCAL_AND_POP, 1 }, + { "local++", F_POST_INC_LOCAL, 1 }, + { "--local", F_DEC_LOCAL, 1 }, + { "--local and pop", F_DEC_LOCAL_AND_POP, 1 }, + { "local--", F_POST_DEC_LOCAL, 1 }, + { "branch if <", F_BRANCH_WHEN_LT, 1 }, + { "branch if >", F_BRANCH_WHEN_GT, 1 }, + { "branch if <=", F_BRANCH_WHEN_LE, 1 }, + { "branch if >=", F_BRANCH_WHEN_GE, 1 }, + { "branch if ==", F_BRANCH_WHEN_EQ, 1 }, + { "branch if !=", F_BRANCH_WHEN_NE, 1 },   { "sizeof", F_SIZEOF }, - { "sizeof local", F_SIZEOF_LOCAL }, + { "sizeof local", F_SIZEOF_LOCAL, 1 },   { "throw(0)", F_THROW_ZERO }, - { "string index", F_STRING_INDEX }, - { "local index", F_LOCAL_INDEX }, - { "int index", F_POS_INT_INDEX }, - { "-int index", F_NEG_INT_INDEX }, + { "string index", F_STRING_INDEX, 1 }, + { "local index", F_LOCAL_INDEX, 1 }, + { "int index", F_POS_INT_INDEX, 1 }, + { "-int index", F_NEG_INT_INDEX, 1 }, + { "apply and pop", F_APPLY_AND_POP, 1 }, + { "2 locals", F_2_LOCALS, 1 }, + { "byte", F_BYTE, 1 },   };      struct instr instrs[F_MAX_INSTR - F_OFFSET];      struct reserved   {    struct hash_entry link;    int token;   };      struct hash_table *reswords;      void init_lex()   {    unsigned int i;    for(i=0; i<NELEM(instr_names);i++)    {    if(instr_names[i].token >= F_MAX_INSTR)    fatal("Error in instr_names[%u]\n\n",i); -  +  +  if(instrs[instr_names[i].token - F_OFFSET].name) +  fatal("Duplicate name for %s\n",instr_names[i].word); +     instrs[instr_names[i].token - F_OFFSET].name = instr_names[i].word; -  +  instrs[instr_names[i].token - F_OFFSET].hasarg=instr_names[i].hasarg;    }       reswords=create_hash_table();       for(i=0; i<NELEM(reserved_words); i++)    {    struct reserved *r=ALLOC_STRUCT(reserved);    r->token = reserved_words[i].token;    r->link.s = make_shared_string(reserved_words[i].word);    reswords=hash_insert(reswords, &r->link);