Varius fixes for 64 bit architectures
git-svn-id: http://picoc.googlecode.com/svn/trunk@381 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
d36833b139
commit
9ea0dcee28
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-Wall -pedantic -g -DUNIX_HOST -DDEBUG_HEAP
|
CFLAGS=-Wall -pedantic -g -DUNIX_HOST
|
||||||
LIBS=#-lm
|
LIBS=#-lm
|
||||||
|
|
||||||
TARGET = picoc
|
TARGET = picoc
|
||||||
|
|
20
expression.c
20
expression.c
|
@ -258,11 +258,15 @@ void ExpressionStackPushLValue(struct ParseState *Parser, struct ExpressionStack
|
||||||
void ExpressionStackPushDereference(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *DereferenceValue)
|
void ExpressionStackPushDereference(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *DereferenceValue)
|
||||||
{
|
{
|
||||||
struct Value *DerefVal;
|
struct Value *DerefVal;
|
||||||
|
struct Value *ValueLoc;
|
||||||
int Offset;
|
int Offset;
|
||||||
struct ValueType *DerefType;
|
struct ValueType *DerefType;
|
||||||
int DerefIsLValue;
|
int DerefIsLValue;
|
||||||
void *DerefDataLoc = VariableDereferencePointer(Parser, DereferenceValue, &DerefVal, &Offset, &DerefType, &DerefIsLValue);
|
void *DerefDataLoc = VariableDereferencePointer(Parser, DereferenceValue, &DerefVal, &Offset, &DerefType, &DerefIsLValue);
|
||||||
struct Value *ValueLoc = VariableAllocValueFromExistingData(Parser, DerefType, (union AnyValue *)DerefDataLoc, DerefIsLValue, DerefVal);
|
if (DerefDataLoc == NULL)
|
||||||
|
ProgramFail(Parser, "NULL pointer dereference");
|
||||||
|
|
||||||
|
ValueLoc = VariableAllocValueFromExistingData(Parser, DerefType, (union AnyValue *)DerefDataLoc, DerefIsLValue, DerefVal);
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
ExpressionStackPushValueNode(Parser, StackTop, ValueLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,6 +376,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
|
||||||
void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack **StackTop, enum LexToken Op, struct Value *TopValue)
|
void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack **StackTop, enum LexToken Op, struct Value *TopValue)
|
||||||
{
|
{
|
||||||
struct Value *Result;
|
struct Value *Result;
|
||||||
|
union AnyValue *ValPtr;
|
||||||
|
|
||||||
if (Parser->Mode != RunModeRun)
|
if (Parser->Mode != RunModeRun)
|
||||||
{
|
{
|
||||||
|
@ -387,8 +392,9 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
if (!TopValue->IsLValue)
|
if (!TopValue->IsLValue)
|
||||||
ProgramFail(Parser, "can't get the address of this");
|
ProgramFail(Parser, "can't get the address of this");
|
||||||
|
|
||||||
|
ValPtr = TopValue->Val;
|
||||||
Result = VariableAllocValueFromType(Parser, TypeGetMatching(Parser, TopValue->Typ, TypePointer, 0, StrEmpty), FALSE, NULL, FALSE);
|
Result = VariableAllocValueFromType(Parser, TypeGetMatching(Parser, TopValue->Typ, TypePointer, 0, StrEmpty), FALSE, NULL, FALSE);
|
||||||
Result->Val->NativePointer = TopValue->Val;
|
Result->Val->NativePointer = (void *)ValPtr;
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -762,7 +768,8 @@ void ExpressionStackCollapse(struct ParseState *Parser, struct ExpressionStack *
|
||||||
TopValue = TopStackNode->Val;
|
TopValue = TopStackNode->Val;
|
||||||
|
|
||||||
/* pop the value and then the prefix operator - assume they'll still be there until we're done */
|
/* pop the value and then the prefix operator - assume they'll still be there until we're done */
|
||||||
HeapPopStack(TopOperatorNode, sizeof(struct ExpressionStack)*2 + sizeof(struct Value) + TypeStackSizeValue(TopValue));
|
HeapPopStack(NULL, sizeof(struct ExpressionStack) + sizeof(struct Value) + TypeStackSizeValue(TopValue));
|
||||||
|
HeapPopStack(TopOperatorNode, sizeof(struct ExpressionStack));
|
||||||
*StackTop = TopOperatorNode->Next;
|
*StackTop = TopOperatorNode->Next;
|
||||||
|
|
||||||
/* do the prefix operation */
|
/* do the prefix operation */
|
||||||
|
@ -775,7 +782,8 @@ void ExpressionStackCollapse(struct ParseState *Parser, struct ExpressionStack *
|
||||||
TopValue = TopStackNode->Next->Val;
|
TopValue = TopStackNode->Next->Val;
|
||||||
|
|
||||||
/* pop the postfix operator and then the value - assume they'll still be there until we're done */
|
/* pop the postfix operator and then the value - assume they'll still be there until we're done */
|
||||||
HeapPopStack(TopValue, sizeof(struct ExpressionStack)*2 + sizeof(struct Value) + TypeStackSizeValue(TopValue));
|
HeapPopStack(NULL, sizeof(struct ExpressionStack));
|
||||||
|
HeapPopStack(TopValue, sizeof(struct ExpressionStack) + sizeof(struct Value) + TypeStackSizeValue(TopValue));
|
||||||
*StackTop = TopStackNode->Next->Next;
|
*StackTop = TopStackNode->Next->Next;
|
||||||
|
|
||||||
/* do the postfix operation */
|
/* do the postfix operation */
|
||||||
|
@ -791,7 +799,9 @@ void ExpressionStackCollapse(struct ParseState *Parser, struct ExpressionStack *
|
||||||
BottomValue = TopOperatorNode->Next->Val;
|
BottomValue = TopOperatorNode->Next->Val;
|
||||||
|
|
||||||
/* pop a value, the operator and another value - assume they'll still be there until we're done */
|
/* pop a value, the operator and another value - assume they'll still be there until we're done */
|
||||||
HeapPopStack(BottomValue, sizeof(struct ExpressionStack)*3 + sizeof(struct Value)*2 + TypeStackSizeValue(TopValue) + TypeStackSizeValue(BottomValue));
|
HeapPopStack(NULL, sizeof(struct ExpressionStack) + sizeof(struct Value) + TypeStackSizeValue(TopValue));
|
||||||
|
HeapPopStack(NULL, sizeof(struct ExpressionStack));
|
||||||
|
HeapPopStack(BottomValue, sizeof(struct ExpressionStack) + sizeof(struct Value) + TypeStackSizeValue(BottomValue));
|
||||||
*StackTop = TopOperatorNode->Next->Next;
|
*StackTop = TopOperatorNode->Next->Next;
|
||||||
|
|
||||||
/* do the infix operation */
|
/* do the infix operation */
|
||||||
|
|
6
heap.c
6
heap.c
|
@ -86,7 +86,7 @@ int HeapPopStack(void *Addr, int Size)
|
||||||
printf("HeapPopStack(0x%lx, %ld) back to 0x%lx\n", (unsigned long)Addr, (unsigned long)MEM_ALIGN(Size), (unsigned long)HeapStackTop - ToLose);
|
printf("HeapPopStack(0x%lx, %ld) back to 0x%lx\n", (unsigned long)Addr, (unsigned long)MEM_ALIGN(Size), (unsigned long)HeapStackTop - ToLose);
|
||||||
#endif
|
#endif
|
||||||
HeapStackTop = (void *)((char *)HeapStackTop - ToLose);
|
HeapStackTop = (void *)((char *)HeapStackTop - ToLose);
|
||||||
assert(HeapStackTop == Addr);
|
assert(Addr == NULL || HeapStackTop == Addr);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ void HeapPushStackFrame()
|
||||||
#endif
|
#endif
|
||||||
*(void **)HeapStackTop = StackFrame;
|
*(void **)HeapStackTop = StackFrame;
|
||||||
StackFrame = HeapStackTop;
|
StackFrame = HeapStackTop;
|
||||||
HeapStackTop = (void *)((char *)HeapStackTop + sizeof(void *));
|
HeapStackTop = (void *)((char *)HeapStackTop + MEM_ALIGN(sizeof(void *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pop the current stack frame, freeing all memory in the frame. can return NULL */
|
/* pop the current stack frame, freeing all memory in the frame. can return NULL */
|
||||||
|
@ -219,7 +219,7 @@ void HeapFreeMem(void *Mem)
|
||||||
int Bucket = MemNode->Size >> 2;
|
int Bucket = MemNode->Size >> 2;
|
||||||
|
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
printf("HeapFreeMem(%lx)\n", (unsigned long)Mem);
|
printf("HeapFreeMem(0x%lx)\n", (unsigned long)Mem);
|
||||||
#endif
|
#endif
|
||||||
assert((unsigned long)Mem >= (unsigned long)&HeapMemory[0] && (unsigned char *)Mem - &HeapMemory[0] < HEAP_SIZE);
|
assert((unsigned long)Mem >= (unsigned long)&HeapMemory[0] && (unsigned char *)Mem - &HeapMemory[0] < HEAP_SIZE);
|
||||||
assert(MemNode->Size < HEAP_SIZE && MemNode->Size > 0);
|
assert(MemNode->Size < HEAP_SIZE && MemNode->Size > 0);
|
||||||
|
|
4
type.c
4
type.c
|
@ -73,7 +73,7 @@ int TypeStackSizeValue(struct Value *Val)
|
||||||
int TypeSizeValue(struct Value *Val)
|
int TypeSizeValue(struct Value *Val)
|
||||||
{
|
{
|
||||||
if (Val->Typ->Base == TypeChar || Val->Typ->Base == TypeShort)
|
if (Val->Typ->Base == TypeChar || Val->Typ->Base == TypeShort)
|
||||||
return sizeof(int); /* allow some extra room for type extension to int */
|
return sizeof(void *); /* allow some extra room for type extension */
|
||||||
else if (Val->Typ->Base != TypeArray)
|
else if (Val->Typ->Base != TypeArray)
|
||||||
return Val->Typ->Sizeof;
|
return Val->Typ->Sizeof;
|
||||||
else
|
else
|
||||||
|
@ -84,7 +84,7 @@ int TypeSizeValue(struct Value *Val)
|
||||||
int TypeSize(struct ValueType *Typ, int ArraySize, int Compact)
|
int TypeSize(struct ValueType *Typ, int ArraySize, int Compact)
|
||||||
{
|
{
|
||||||
if ( (Typ->Base == TypeChar || Typ->Base == TypeShort) && !Compact)
|
if ( (Typ->Base == TypeChar || Typ->Base == TypeShort) && !Compact)
|
||||||
return sizeof(int); /* allow some extra room for type extension to int */
|
return sizeof(void *); /* allow some extra room for type extension */
|
||||||
else if (Typ->Base != TypeArray)
|
else if (Typ->Base != TypeArray)
|
||||||
return Typ->Sizeof;
|
return Typ->Sizeof;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue