Fixed some inconsistencies in array handling

git-svn-id: http://picoc.googlecode.com/svn/trunk@105 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-02-24 02:28:35 +00:00
parent 802f3e026f
commit cf28c7513c
2 changed files with 3 additions and 2 deletions

View file

@ -832,6 +832,7 @@ int ParseStatement(struct ParseState *Parser)
ProgramFail(Parser, "wrong return type");
// XXX - make assignment a separate function
// XXX - also arrays need cleverer assignment
memcpy(TopStackFrame->ReturnValue->Val, CValue->Val, TypeSizeValue(CValue));
Parser->Mode = RunModeReturn;
}

4
type.c
View file

@ -48,7 +48,7 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P
switch (Base)
{
case TypePointer: Sizeof = sizeof(struct PointerValue); break;
case TypeArray: Sizeof = ArraySize * ParentType->Sizeof; break;
case TypeArray: Sizeof = sizeof(struct ArrayValue) + ArraySize * ParentType->Sizeof; break;
case TypeEnum: Sizeof = sizeof(int); break;
default: Sizeof = 0; break; /* structs and unions will get bigger when we add members to them */
}
@ -71,7 +71,7 @@ int TypeSize(struct ValueType *Typ, int ArraySize)
if (Typ->Base != TypeArray)
return Typ->Sizeof;
else
return Typ->FromType->Sizeof * ArraySize;
return sizeof(struct ArrayValue) + Typ->FromType->Sizeof * ArraySize;
}
/* add a base type */