Fix for a bug where variables which were initialised on declaration weren't writable.
git-svn-id: http://picoc.googlecode.com/svn/trunk@279 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
6b851b88d2
commit
5dcde3d5ea
|
@ -1134,7 +1134,7 @@ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionSta
|
|||
TopStackFrame->NumParams = ArgCount;
|
||||
TopStackFrame->ReturnValue = ReturnValue;
|
||||
for (Count = 0; Count < FuncValue->Val->FuncDef.NumParams; Count++)
|
||||
VariableDefine(Parser, FuncValue->Val->FuncDef.ParamName[Count], ParamArray[Count]);
|
||||
VariableDefine(Parser, FuncValue->Val->FuncDef.ParamName[Count], ParamArray[Count], TRUE);
|
||||
|
||||
if (!ParseStatement(&FuncParser))
|
||||
ProgramFail(&FuncParser, "function body expected");
|
||||
|
|
4
parse.c
4
parse.c
|
@ -127,14 +127,14 @@ int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
|
|||
ProgramFail(Parser, "can't define a void variable");
|
||||
|
||||
if (LexGetToken(Parser, NULL, FALSE) != TokenAssign)
|
||||
VariableDefine(Parser, Identifier, VariableAllocValueFromType(Parser, Typ, TRUE, NULL));
|
||||
VariableDefine(Parser, Identifier, VariableAllocValueFromType(Parser, Typ, TRUE, NULL), TRUE);
|
||||
else
|
||||
{ /* we're assigning an initial value */
|
||||
LexGetToken(Parser, NULL, TRUE);
|
||||
if (!ExpressionParse(Parser, &CValue))
|
||||
ProgramFail(Parser, "expression expected");
|
||||
|
||||
VariableDefine(Parser, Identifier, CValue);
|
||||
VariableDefine(Parser, Identifier, CValue, TRUE);
|
||||
if (Parser->Mode == RunModeRun)
|
||||
VariableStackPop(Parser, CValue);
|
||||
}
|
||||
|
|
2
picoc.h
2
picoc.h
|
@ -350,7 +350,7 @@ struct Value *VariableAllocValueAndCopy(struct ParseState *Parser, struct Value
|
|||
struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct ValueType *Typ, int IsLValue, struct Value *LValueFrom);
|
||||
struct Value *VariableAllocValueFromExistingData(struct ParseState *Parser, struct ValueType *Typ, union AnyValue *FromValue, int IsLValue, struct Value *LValueFrom);
|
||||
struct Value *VariableAllocValueShared(struct ParseState *Parser, struct Value *FromValue);
|
||||
void VariableDefine(struct ParseState *Parser, char *Ident, struct Value *InitValue);
|
||||
void VariableDefine(struct ParseState *Parser, char *Ident, struct Value *InitValue, int MakeWritable);
|
||||
int VariableDefined(const char *Ident);
|
||||
void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LVal);
|
||||
void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable);
|
||||
|
|
2
type.c
2
type.c
|
@ -270,7 +270,7 @@ void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ)
|
|||
EnumValue = ExpressionParseInt(Parser);
|
||||
}
|
||||
|
||||
VariableDefine(Parser, EnumIdentifier, &InitValue);
|
||||
VariableDefine(Parser, EnumIdentifier, &InitValue, FALSE);
|
||||
|
||||
Token = LexGetToken(Parser, NULL, TRUE);
|
||||
if (Token != TokenComma && Token != TokenRightBrace)
|
||||
|
|
|
@ -145,9 +145,14 @@ struct Value *VariableAllocValueShared(struct ParseState *Parser, struct Value *
|
|||
}
|
||||
|
||||
/* define a variable. Ident must be registered */
|
||||
void VariableDefine(struct ParseState *Parser, char *Ident, struct Value *InitValue)
|
||||
void VariableDefine(struct ParseState *Parser, char *Ident, struct Value *InitValue, int MakeWritable)
|
||||
{
|
||||
if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, Ident, VariableAllocValueAndCopy(Parser, InitValue, TopStackFrame == NULL)))
|
||||
struct Value *AssignValue = VariableAllocValueAndCopy(Parser, InitValue, TopStackFrame == NULL);
|
||||
|
||||
if (MakeWritable)
|
||||
AssignValue->IsLValue = TRUE;
|
||||
|
||||
if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, Ident, AssignValue))
|
||||
ProgramFail(Parser, "'%s' is already defined", Ident);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue