Made a cleaner interface to creating shared values

git-svn-id: http://picoc.googlecode.com/svn/trunk@74 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-02-11 06:47:36 +00:00
parent 177c2a549b
commit bd5fe4b73c
3 changed files with 9 additions and 2 deletions

View file

@ -140,7 +140,7 @@ int ParseValue(struct ParseState *Parser, struct Value **Result, int ResultOnHea
LocalLValue = (*Result)->Val->Pointer.Segment;
VariableStackPop(Parser, *Result);
*Result = VariableAllocValueFromExistingData(Parser, LocalLValue->Typ, LocalLValue->Val, ResultOnHeap);
*Result = VariableAllocValueShared(Parser, LocalLValue, ResultOnHeap);
break;
case TokenAmpersand:
@ -172,7 +172,7 @@ int ParseValue(struct ParseState *Parser, struct Value **Result, int ResultOnHea
else if (LocalLValue->Typ == TypeVoid)
ProgramFail(Parser, "a void value isn't much use here");
else
*Result = VariableAllocValueFromExistingData(Parser, LocalLValue->Typ, LocalLValue->Val, ResultOnHeap);
*Result = VariableAllocValueShared(Parser, LocalLValue, ResultOnHeap);
}
}
break;

View file

@ -254,6 +254,7 @@ struct Value *VariableAllocValueAndData(struct ParseState *Parser, int DataSize,
struct Value *VariableAllocValueAndCopy(struct ParseState *Parser, struct Value *FromValue, int OnHeap);
struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct ValueType *Typ, int OnHeap);
struct Value *VariableAllocValueFromExistingData(struct ParseState *Parser, struct ValueType *Typ, union AnyValue *FromValue, int OnHeap);
struct Value *VariableAllocValueShared(struct ParseState *Parser, struct Value *FromValue, int OnHeap);
void VariableDefine(struct ParseState *Parser, const char *Ident, struct Value *InitValue);
int VariableDefined(const char *Ident);
void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LVal);

View file

@ -81,6 +81,12 @@ struct Value *VariableAllocValueFromExistingData(struct ParseState *Parser, stru
return NewValue;
}
/* allocate a value either on the heap or the stack from an existing Value, sharing the value */
struct Value *VariableAllocValueShared(struct ParseState *Parser, struct Value *FromValue, int OnHeap)
{
return VariableAllocValueFromExistingData(Parser, FromValue->Typ, FromValue->Val, OnHeap);
}
/* define a variable */
void VariableDefine(struct ParseState *Parser, const char *Ident, struct Value *InitValue)
{