Removed unused path in TableSet()

git-svn-id: http://picoc.googlecode.com/svn/trunk@16 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2008-12-21 03:13:25 +00:00
parent eba1492fcb
commit ebf601bfb9
3 changed files with 5 additions and 17 deletions

11
parse.c
View file

@ -30,17 +30,10 @@ void VariableDefine(struct LexState *Lexer, const Str *Ident, enum ValueType Typ
memset(&NewValue, '\0', sizeof(NewValue)); memset(&NewValue, '\0', sizeof(NewValue));
NewValue.Typ = Typ; NewValue.Typ = Typ;
if (!TableSet(&GlobalTable, Ident, &NewValue, FALSE)) if (!TableSet(&GlobalTable, Ident, &NewValue))
ProgramFail(Lexer, "'%S' is already defined", Ident); ProgramFail(Lexer, "'%S' is already defined", Ident);
} }
/* set the value of a variable */
void VariableSet(struct LexState *Lexer, Str *Ident, struct Value *Val)
{
if (!TableSet(&GlobalTable, Ident, Val, TRUE))
ProgramFail(Lexer, "'%S' is undefined", Ident);
}
/* get the value of a variable. must be defined */ /* get the value of a variable. must be defined */
void VariableGet(struct LexState *Lexer, Str *Ident, struct Value *Val, struct Value **LVal) void VariableGet(struct LexState *Lexer, Str *Ident, struct Value *Val, struct Value **LVal)
{ {
@ -208,7 +201,7 @@ void ParseFunctionDefinition(struct LexState *Lexer, Str *Identifier, struct Lex
FuncValue.Val.Integer = FunctionStoreUsed; FuncValue.Val.Integer = FunctionStoreUsed;
FunctionStoreUsed++; FunctionStoreUsed++;
if (!TableSet(&GlobalTable, Identifier, &FuncValue, FALSE)) if (!TableSet(&GlobalTable, Identifier, &FuncValue))
ProgramFail(Lexer, "'%S' is already defined", Identifier); ProgramFail(Lexer, "'%S' is already defined", Identifier);
} }

View file

@ -158,7 +158,7 @@ void ScanFile(const Str *FileName);
/* table.c */ /* table.c */
void TableInit(struct Table *Tbl, struct TableEntry *HashTable, const char *Name, int Size); void TableInit(struct Table *Tbl, struct TableEntry *HashTable, const char *Name, int Size);
int TableSet(struct Table *Tbl, const Str *Key, struct Value *Val, int Exists); int TableSet(struct Table *Tbl, const Str *Key, struct Value *Val);
int TableGet(struct Table *Tbl, const Str *Key, struct Value **Val); int TableGet(struct Table *Tbl, const Str *Key, struct Value **Val);
/* lex.c */ /* lex.c */

View file

@ -77,19 +77,14 @@ static int TableSearch(struct Table *Tbl, const Str *Key, int *AddAt)
} }
int TableSet(struct Table *Tbl, const Str *Key, struct Value *Val, int Exists) int TableSet(struct Table *Tbl, const Str *Key, struct Value *Val)
{ {
int HashPos; int HashPos;
int AddAt; int AddAt;
HashPos = TableSearch(Tbl, Key, &AddAt); HashPos = TableSearch(Tbl, Key, &AddAt);
if ( (HashPos != -1) != Exists) if (HashPos == -1)
return FALSE;
if (HashPos != -1)
Tbl->HashTable[HashPos].Val = *Val; /* found - update value */
else
{ {
if (AddAt == -1) if (AddAt == -1)
Fail("table '%s' is full\n", Tbl->Name); Fail("table '%s' is full\n", Tbl->Name);