Fixed bug in stdarg handling of non-stack values

git-svn-id: http://picoc.googlecode.com/svn/trunk@142 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-03-02 22:13:47 +00:00
parent 36b777f39f
commit 676c937a7b
4 changed files with 14 additions and 2 deletions

View file

@ -124,7 +124,7 @@ void LibPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
PrintStr("XXX", PlatformPutc); /* not enough parameters for format */
else
{
NextArg = (struct Value *)((void *)NextArg + sizeof(struct Value) + TypeSizeValue(NextArg));
NextArg = (struct Value *)((void *)NextArg + sizeof(struct Value) + TypeStackSizeValue(NextArg));
if (NextArg->Typ != FormatType)
PrintStr("XXX", PlatformPutc); /* bad type for format */
else

View file

@ -122,6 +122,7 @@ struct FuncDef
struct ParseState Body; /* lexical tokens of the function body if not intrinsic */
};
/* values */
struct ArrayValue
{
unsigned int Size; /* the number of elements in the array */
@ -161,6 +162,7 @@ struct Value
char ValOnHeap; /* the AnyValue is on the heap (but this Value is on the stack) */
char ValOnStack; /* the AnyValue is on the stack along with this Value */
char IsLValue; /* is modifiable and is allocated somewhere we can usefully modify it */
char TempToken; /* temporary token used in expression evaluation */
};
/* hash table data structure */
@ -260,6 +262,7 @@ void Parse(const char *FileName, const char *Source, int SourceLen, int RunIt);
void TypeInit();
int TypeSize(struct ValueType *Typ, int ArraySize);
int TypeSizeValue(struct Value *Val);
int TypeStackSizeValue(struct Value *Val);
void TypeParse(struct ParseState *Parser, struct ValueType **Typ, char **Identifier);
struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier);

View file

@ -19,7 +19,7 @@ void Random(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
static int SomeVar = 42;
static int SomeArray[4];
static int Blobcnt, Blobx1, Blobx2, Bloby1, Bloby2;
static int Blobcnt = 12, Blobx1 = 34, Blobx2 = 56, Bloby1 = 78, Bloby2 = 90;
void PlatformLibraryInit()
{
struct ValueType *IntArrayType;

9
type.c
View file

@ -56,6 +56,15 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P
return TypeAdd(Parser, ParentType, Base, ArraySize, Identifier, Sizeof);
}
/* stack space used by a value */
int TypeStackSizeValue(struct Value *Val)
{
if (Val->ValOnStack)
return TypeSizeValue(Val); // XXX - doesn't handle passing system-memory arrays by value correctly
else
return 0;
}
/* memory used by a value */
int TypeSizeValue(struct Value *Val)
{