diff --git a/Makefile b/Makefile index 749248d..5a00203 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-Wall -g -DUNIX_HOST #-DDEBUG_HEAP #-DDEBUG_EXPRESSIONS #-DDEBUG_LEXER +CFLAGS=-Wall -pedantic -g -DUNIX_HOST #-DDEBUG_HEAP #-DDEBUG_EXPRESSIONS #-DDEBUG_LEXER LIBS=#-lm TARGET = picoc diff --git a/clibrary.c b/clibrary.c index 197dcf0..7e7e251 100644 --- a/clibrary.c +++ b/clibrary.c @@ -165,10 +165,10 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct if (Param[0]->Val->Pointer.Offset < 0 || Param[0]->Val->Pointer.Offset >= CharArray->Val->Array.Size) Format = StrEmpty; else - Format = CharArray->Val->Array.Data + Param[0]->Val->Pointer.Offset; + Format = (char *)CharArray->Val->Array.Data + Param[0]->Val->Pointer.Offset; #else char *Format = Param[0]->Val->NativePointer; - // XXX - dereference this properly + /* XXX - dereference this properly */ #endif for (FPos = Format; *FPos != '\0'; FPos++) @@ -194,7 +194,7 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct PrintStr("XXX", Stream); /* not enough parameters for format */ else { - NextArg = (struct Value *)((void *)NextArg + sizeof(struct Value) + TypeStackSizeValue(NextArg)); + NextArg = (struct Value *)((char *)NextArg + sizeof(struct Value) + TypeStackSizeValue(NextArg)); if (NextArg->Typ != FormatType && !((FormatType == &IntType || *FPos == 'f') && IS_NUMERIC_COERCIBLE(NextArg))) PrintStr("XXX", Stream); /* bad type for format */ else @@ -210,10 +210,10 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct if (NextArg->Val->Pointer.Offset < 0 || NextArg->Val->Pointer.Offset >= CharArray->Val->Array.Size) Str = StrEmpty; else - Str = CharArray->Val->Array.Data + NextArg->Val->Pointer.Offset; + Str = (char *)CharArray->Val->Array.Data + NextArg->Val->Pointer.Offset; #else char *Str = NextArg->Val->NativePointer; - // XXX - dereference this properly + /* XXX - dereference this properly */ #endif PrintStr(Str, Stream); @@ -275,7 +275,7 @@ void LibGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value { #ifndef NATIVE_POINTERS struct Value *CharArray = Param[0]->Val->Pointer.Segment; - char *ReadBuffer = CharArray->Val->Array.Data + Param[0]->Val->Pointer.Offset; + char *ReadBuffer = (char *)CharArray->Val->Array.Data + Param[0]->Val->Pointer.Offset; int MaxLength = CharArray->Val->Array.Size - Param[0]->Val->Pointer.Offset; char *Result; @@ -407,7 +407,7 @@ void LibSqrt(struct ParseState *Parser, struct Value *ReturnValue, struct Value void LibRound(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - ReturnValue->Val->FP = math_floor(Param[0]->Val->FP + 0.5); // XXX - fix for soft float + ReturnValue->Val->FP = math_floor(Param[0]->Val->FP + 0.5); /* XXX - fix for soft float */ } void LibCeil(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) diff --git a/expression.c b/expression.c index 4b61108..a090ae2 100644 --- a/expression.c +++ b/expression.c @@ -38,9 +38,9 @@ struct ExpressionStack /* operator precedence definitions */ struct OpPrecedence { - unsigned char PrefixPrecedence:4; - unsigned char PostfixPrecedence:4; - unsigned char InfixPrecedence:4; + unsigned int PrefixPrecedence:4; + unsigned int PostfixPrecedence:4; + unsigned int InfixPrecedence:4; char *Name; }; @@ -168,7 +168,6 @@ void ExpressionStackPushValueNode(struct ParseState *Parser, struct ExpressionSt /* push a blank value on to the expression stack by type */ struct Value *ExpressionStackPushValueByType(struct ParseState *Parser, struct ExpressionStack **StackTop, struct ValueType *PushType) { - debugf("ExpressionStackPushValueByType()\n"); struct Value *ValueLoc = VariableAllocValueFromType(Parser, PushType, FALSE, NULL, FALSE); ExpressionStackPushValueNode(Parser, StackTop, ValueLoc); @@ -178,16 +177,14 @@ struct Value *ExpressionStackPushValueByType(struct ParseState *Parser, struct E /* push a value on to the expression stack */ void ExpressionStackPushValue(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *PushValue) { - debugf("ExpressionStackPushValue()\n"); struct Value *ValueLoc = VariableAllocValueAndCopy(Parser, PushValue, FALSE); ExpressionStackPushValueNode(Parser, StackTop, ValueLoc); } void ExpressionStackPushLValue(struct ParseState *Parser, struct ExpressionStack **StackTop, struct Value *PushValue, int Offset) { - debugf("ExpressionStackPushLValue()\n"); struct Value *ValueLoc = VariableAllocValueShared(Parser, PushValue); - ValueLoc->Val = (void *)ValueLoc->Val + Offset; + ValueLoc->Val = (void *)((char *)ValueLoc->Val + Offset); ExpressionStackPushValueNode(Parser, StackTop, ValueLoc); } @@ -203,7 +200,6 @@ void ExpressionStackPushDereference(struct ParseState *Parser, struct Expression void ExpressionPushInt(struct ParseState *Parser, struct ExpressionStack **StackTop, int IntValue) { - debugf("ExpressionPushInt()\n"); struct Value *ValueLoc = VariableAllocValueFromType(Parser, &IntType, FALSE, NULL, FALSE); ValueLoc->Val->Integer = IntValue; ExpressionStackPushValueNode(Parser, StackTop, ValueLoc); @@ -212,7 +208,6 @@ void ExpressionPushInt(struct ParseState *Parser, struct ExpressionStack **Stack #ifndef NO_FP void ExpressionPushFP(struct ParseState *Parser, struct ExpressionStack **StackTop, double FPValue) { - debugf("ExpressionPushFP()\n"); struct Value *ValueLoc = VariableAllocValueFromType(Parser, &FPType, FALSE, NULL, FALSE); ValueLoc->Val->FP = FPValue; ExpressionStackPushValueNode(Parser, StackTop, ValueLoc); @@ -356,7 +351,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack #ifndef NATIVE_POINTERS Result->Val->Pointer.Segment = TempLValue; if (Result->LValueFrom != NULL) - Result->Val->Pointer.Offset = (void *)Result->Val - (void *)Result->LValueFrom; + Result->Val->Pointer.Offset = (char *)Result->Val - (char *)Result->LValueFrom; #else Result->Val->NativePointer = TempLValue; #endif @@ -368,15 +363,15 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack break; case TokenSizeof: - // XXX + /* XXX */ break; case TokenLeftSquareBracket: - // XXX + /* XXX */ break; case TokenOpenBracket: - // XXX - cast + /* XXX - cast */ break; default: @@ -485,8 +480,8 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack { case TokenIncrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt+1, TRUE); break; case TokenDecrement: ResultInt = ExpressionAssignInt(Parser, TopValue, TopInt-1, TRUE); break; - case TokenRightSquareBracket: break; // XXX - case TokenCloseBracket: break; // XXX + case TokenRightSquareBracket: break; /* XXX */ + case TokenCloseBracket: break; /* XXX */ default: ProgramFail(Parser, "invalid operation"); break; } @@ -581,7 +576,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * ProgramFail(Parser, "illegal array index %d [0..%d]", ArrayIndex, BottomValue->Val->Array.Size-1); /* make the array element result */ - Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)(BottomValue->Val->Array.Data + TypeSize(BottomValue->Typ->FromType, 0, FALSE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); + Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->Array.Data + TypeSize(BottomValue->Typ->FromType, 0, FALSE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); ExpressionStackPushValueNode(Parser, StackTop, Result); } #ifndef NO_FP @@ -641,8 +636,8 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * case TokenArithmeticAndAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt & TopInt, FALSE); break; case TokenArithmeticOrAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt | TopInt, FALSE); break; case TokenArithmeticExorAssign: ResultInt = ExpressionAssignInt(Parser, BottomValue, BottomInt ^ TopInt, FALSE); break; - case TokenQuestionMark: break; // XXX - case TokenColon: break; // XXX + case TokenQuestionMark: break; /* XXX */ + case TokenColon: break; /* XXX */ case TokenLogicalOr: ResultInt = BottomInt || TopInt; break; case TokenLogicalAnd: ResultInt = BottomInt && TopInt; break; case TokenArithmeticOr: ResultInt = BottomInt | TopInt; break; @@ -729,7 +724,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * else if (Op == TokenAssign && TopInt == 0) { /* assign a NULL pointer */ - HeapUnpopStack(sizeof(struct Value)); // XXX - possible bug if lvalue is a temp value and takes more than sizeof(struct Value) + HeapUnpopStack(sizeof(struct Value)); /* XXX - possible bug if lvalue is a temp value and takes more than sizeof(struct Value) */ ExpressionAssign(Parser, BottomValue, TopValue, FALSE); ExpressionStackPushValueNode(Parser, StackTop, BottomValue); } @@ -740,11 +735,11 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * { /* pointer/pointer operations */ #ifndef NATIVE_POINTERS - void *TopLoc = (void *)TopValue->Val->Pointer.Segment->Val + TopValue->Val->Pointer.Offset; - void *BottomLoc = (void *)BottomValue->Val->Pointer.Segment->Val + BottomValue->Val->Pointer.Offset; + char *TopLoc = (char *)TopValue->Val->Pointer.Segment->Val + TopValue->Val->Pointer.Offset; + char *BottomLoc = (char *)BottomValue->Val->Pointer.Segment->Val + BottomValue->Val->Pointer.Offset; #else - void *TopLoc = (void *)TopValue->Val->NativePointer; - void *BottomLoc = (void *)BottomValue->Val->NativePointer; + char *TopLoc = (char *)TopValue->Val->NativePointer; + char *BottomLoc = (char *)BottomValue->Val->NativePointer; #endif switch (Op) @@ -758,7 +753,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * else if (Op == TokenAssign) { /* assign a non-numeric type */ - HeapUnpopStack(sizeof(struct Value)); // XXX - possible bug if lvalue is a temp value and takes more than sizeof(struct Value) + HeapUnpopStack(sizeof(struct Value)); /* XXX - possible bug if lvalue is a temp value and takes more than sizeof(struct Value) */ ExpressionAssign(Parser, BottomValue, TopValue, FALSE); ExpressionStackPushValueNode(Parser, StackTop, BottomValue); } @@ -883,7 +878,7 @@ void ExpressionGetStructElement(struct ParseState *Parser, struct ExpressionStac struct Value *StructVal = ParamVal; int StructOffset = 0; struct ValueType *StructType = ParamVal->Typ; - void *DerefDataLoc = (void *)ParamVal->Val; + char *DerefDataLoc = (char *)ParamVal->Val; struct Value *MemberValue; struct Value *Result; @@ -902,7 +897,7 @@ void ExpressionGetStructElement(struct ParseState *Parser, struct ExpressionStac *StackTop = (*StackTop)->Next; /* make the result value for this member only */ - Result = VariableAllocValueFromExistingData(Parser, MemberValue->Typ, DerefDataLoc + MemberValue->Val->Integer, TRUE, StructVal->LValueFrom); + Result = VariableAllocValueFromExistingData(Parser, MemberValue->Typ, (void *)(DerefDataLoc + MemberValue->Val->Integer), TRUE, StructVal->LValueFrom); ExpressionStackPushValueNode(Parser, StackTop, Result); } } diff --git a/heap.c b/heap.c index efebaf3..4b91ab1 100644 --- a/heap.c +++ b/heap.c @@ -53,15 +53,15 @@ void HeapInit() * clears memory. can return NULL if out of stack space */ void *HeapAllocStack(int Size) { - void *NewMem = HeapStackTop; - void *NewTop = HeapStackTop + MEM_ALIGN(Size); + char *NewMem = HeapStackTop; + char *NewTop = (char *)HeapStackTop + MEM_ALIGN(Size); #ifdef DEBUG_HEAP printf("HeapAllocStack(%d) at 0x%lx\n", MEM_ALIGN(Size), (unsigned long)HeapStackTop); #endif - if (NewTop > HeapBottom) + if (NewTop > (char *)HeapBottom) return NULL; - HeapStackTop = NewTop; + HeapStackTop = (void *)NewTop; memset(NewMem, '\0', Size); return NewMem; } @@ -72,20 +72,20 @@ void HeapUnpopStack(int Size) #ifdef DEBUG_HEAP printf("HeapUnpopStack(%d) at 0x%lx\n", MEM_ALIGN(Size), (unsigned long)HeapStackTop); #endif - HeapStackTop = HeapStackTop + MEM_ALIGN(Size); + HeapStackTop = (void *)((char *)HeapStackTop + MEM_ALIGN(Size)); } /* free some space at the top of the stack */ int HeapPopStack(void *Addr, int Size) { int ToLose = MEM_ALIGN(Size); - if (ToLose > (HeapStackTop - (void *)&HeapMemory[0])) + if (ToLose > ((char *)HeapStackTop - (char *)&HeapMemory[0])) return FALSE; #ifdef DEBUG_HEAP printf("HeapPopStack(0x%lx, %d) back to 0x%lx\n", (unsigned long)Addr, MEM_ALIGN(Size), (unsigned long)HeapStackTop - ToLose); #endif - HeapStackTop -= ToLose; + HeapStackTop = (void *)((char *)HeapStackTop - ToLose); assert(HeapStackTop == Addr); return TRUE; @@ -99,7 +99,7 @@ void HeapPushStackFrame() #endif *(void **)HeapStackTop = StackFrame; StackFrame = HeapStackTop; - HeapStackTop += sizeof(void *); + HeapStackTop = (void *)((char *)HeapStackTop + sizeof(void *)); } /* pop the current stack frame, freeing all memory in the frame. can return NULL */ @@ -173,7 +173,7 @@ void *HeapAlloc(int Size) #ifdef DEBUG_HEAP printf("allocating %d(%d) from freelist, split chunk (%d)", Size, AllocSize, (*FreeNode)->Size); #endif - NewMem = (void *)*FreeNode + (*FreeNode)->Size - AllocSize; + NewMem = (void *)((char *)*FreeNode + (*FreeNode)->Size - AllocSize); assert((unsigned long)NewMem >= (unsigned long)&HeapMemory[0] && (unsigned char *)NewMem - &HeapMemory[0] < HEAP_SIZE); (*FreeNode)->Size -= AllocSize; NewMem->Size = AllocSize; @@ -186,10 +186,10 @@ void *HeapAlloc(int Size) #ifdef DEBUG_HEAP printf("allocating %d(%d) at bottom of heap (0x%lx-0x%lx)", Size, AllocSize, (long)(HeapBottom - AllocSize), (long)HeapBottom); #endif - if (HeapBottom - AllocSize < HeapStackTop) + if ((char *)HeapBottom - AllocSize < (char *)HeapStackTop) return NULL; - HeapBottom -= AllocSize; + HeapBottom = (void *)((char *)HeapBottom - AllocSize); NewMem = HeapBottom; NewMem->Size = AllocSize; } @@ -208,7 +208,7 @@ void HeapFree(void *Mem) #ifdef USE_MALLOC_HEAP return free(Mem); #else - struct AllocNode *MemNode = (struct AllocNode *)(Mem-sizeof(int)); + struct AllocNode *MemNode = (struct AllocNode *)((char *)Mem-sizeof(int)); int Bucket = MemNode->Size >> 2; assert((unsigned long)Mem >= (unsigned long)&HeapMemory[0] && (unsigned char *)Mem - &HeapMemory[0] < HEAP_SIZE); @@ -221,7 +221,7 @@ void HeapFree(void *Mem) #ifdef DEBUG_HEAP printf("freeing %d from bottom of heap\n", MemNode->Size); #endif - HeapBottom += MemNode->Size; + HeapBottom = (void *)((char *)HeapBottom + MemNode->Size); #ifdef DEBUG_HEAP ShowBigList(); #endif diff --git a/lex.c b/lex.c index 913f9cd..f66f9df 100644 --- a/lex.c +++ b/lex.c @@ -435,7 +435,7 @@ void *LexTokenise(struct LexState *Lexer, int *TokenLen) int ValueSize; int ReserveSpace = (Lexer->End - Lexer->Pos) * 3 + 1; void *TokenSpace = HeapAllocStack(ReserveSpace); - void *TokenPos = TokenSpace; + char *TokenPos = (char *)TokenSpace; if (TokenSpace == NULL) LexFail(Lexer, "out of memory"); @@ -601,7 +601,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I default: break; } - memcpy((void *)LexValue.Val, (void *)Parser->Pos+1, ValueSize); + memcpy((void *)LexValue.Val, (void *)((char *)Parser->Pos+1), ValueSize); LexValue.ValOnHeap = FALSE; LexValue.ValOnStack = FALSE; LexValue.IsLValue = FALSE; @@ -660,7 +660,7 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser for (InteractiveCurrentLine = InteractiveHead; InteractiveCurrentLine != NULL && (Pos < &InteractiveCurrentLine->Tokens[0] || Pos >= &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes]); InteractiveCurrentLine = InteractiveCurrentLine->Next) {} /* find the line we just counted */ - if (EndParser->Pos >= StartParser->Pos && EndParser->Pos < (void *)&InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes]) + if (EndParser->Pos >= StartParser->Pos && EndParser->Pos < &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes]) { /* all on a single line */ MemSize = EndParser->Pos - StartParser->Pos; @@ -671,23 +671,23 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser { /* it's spread across multiple lines */ MemSize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes-1] - Pos; - for (ILine = InteractiveCurrentLine->Next; ILine != NULL && (EndParser->Pos < (void *)&ILine->Tokens[0] || EndParser->Pos >= (void *)&ILine->Tokens[ILine->NumBytes]); ILine = ILine->Next) + for (ILine = InteractiveCurrentLine->Next; ILine != NULL && (EndParser->Pos < &ILine->Tokens[0] || EndParser->Pos >= &ILine->Tokens[ILine->NumBytes]); ILine = ILine->Next) MemSize += ILine->NumBytes - 1; assert(ILine != NULL); - MemSize += EndParser->Pos - (void *)&ILine->Tokens[0]; + MemSize += EndParser->Pos - &ILine->Tokens[0]; NewTokens = VariableAlloc(StartParser, MemSize + 1, TRUE); CopySize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes-1] - Pos; memcpy(NewTokens, Pos, CopySize); NewTokenPos = NewTokens + CopySize; - for (ILine = InteractiveCurrentLine->Next; ILine != NULL && (EndParser->Pos < (void *)&ILine->Tokens[0] || EndParser->Pos >= (void *)&ILine->Tokens[ILine->NumBytes]); ILine = ILine->Next) + for (ILine = InteractiveCurrentLine->Next; ILine != NULL && (EndParser->Pos < &ILine->Tokens[0] || EndParser->Pos >= &ILine->Tokens[ILine->NumBytes]); ILine = ILine->Next) { memcpy(NewTokenPos, &ILine->Tokens[0], ILine->NumBytes-1); NewTokenPos += ILine->NumBytes-1; } assert(ILine != NULL); - memcpy(NewTokenPos, &ILine->Tokens[0], EndParser->Pos - (void *)&ILine->Tokens[0]); + memcpy(NewTokenPos, &ILine->Tokens[0], EndParser->Pos - &ILine->Tokens[0]); } } @@ -715,7 +715,7 @@ void LexInteractiveClear(struct ParseState *Parser) /* indicate that we've completed up to this point in the interactive input and free expired tokens */ void LexInteractiveCompleted(struct ParseState *Parser) { - while (InteractiveHead != NULL && !(Parser->Pos >= (void *)&InteractiveHead->Tokens[0] && Parser->Pos < (void *)&InteractiveHead->Tokens[InteractiveHead->NumBytes])) + while (InteractiveHead != NULL && !(Parser->Pos >= &InteractiveHead->Tokens[0] && Parser->Pos < &InteractiveHead->Tokens[InteractiveHead->NumBytes])) { /* this token line is no longer needed - free it */ struct TokenLine *NextLine = InteractiveHead->Next; diff --git a/parse.c b/parse.c index 14ea6a3..654069d 100644 --- a/parse.c +++ b/parse.c @@ -16,8 +16,9 @@ int ParseStatementMaybeRun(struct ParseState *Parser, int Condition) if (Parser->Mode != RunModeSkip && !Condition) { enum RunMode OldMode = Parser->Mode; + int Result; Parser->Mode = RunModeSkip; - int Result = ParseStatement(Parser); + Result = ParseStatement(Parser); Parser->Mode = OldMode; return Result; } @@ -59,8 +60,8 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp FuncValue->Val->FuncDef.ReturnType = ReturnType; FuncValue->Val->FuncDef.NumParams = ParamCount; FuncValue->Val->FuncDef.VarArgs = FALSE; - FuncValue->Val->FuncDef.ParamType = (void *)FuncValue->Val + sizeof(struct FuncDef); - FuncValue->Val->FuncDef.ParamName = (void *)FuncValue->Val->FuncDef.ParamType + sizeof(struct ValueType *) * ParamCount; + FuncValue->Val->FuncDef.ParamType = (struct ValueType **)((char *)FuncValue->Val + sizeof(struct FuncDef)); + FuncValue->Val->FuncDef.ParamName = (char **)((char *)FuncValue->Val->FuncDef.ParamType + sizeof(struct ValueType *) * ParamCount); for (ParamCount = 0; ParamCount < FuncValue->Val->FuncDef.NumParams; ParamCount++) { @@ -497,7 +498,7 @@ int ParseStatement(struct ParseState *Parser) { if (TopStackFrame->ReturnValue->Typ->Base == TypePointer) { /* this was a pointer to something - delete the object we're pointing to */ - // XXX - now I'm having second thoughts about this + /* XXX - now I'm having second thoughts about this */ WasPointer = TRUE; } diff --git a/picoc.c b/picoc.c index 2787e3d..2db57be 100644 --- a/picoc.c +++ b/picoc.c @@ -61,10 +61,10 @@ int picoc(char *SourceStr) Initialise(); if (SourceStr) { - for (ix=0; ixValOnStack) - return TypeSizeValue(Val); // XXX - doesn't handle passing system-memory arrays by value correctly + return TypeSizeValue(Val); /* XXX - doesn't handle passing system-memory arrays by value correctly */ else return 0; } @@ -194,8 +194,8 @@ void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsSt LexGetToken(Parser, NULL, TRUE); (*Typ)->Members = VariableAlloc(Parser, sizeof(struct Table) + STRUCT_TABLE_SIZE * sizeof(struct TableEntry), TRUE); - (*Typ)->Members->HashTable = (void *)(*Typ)->Members + sizeof(struct Table); - TableInitTable((*Typ)->Members, (void *)(*Typ)->Members + sizeof(struct Table), STRUCT_TABLE_SIZE, TRUE); + (*Typ)->Members->HashTable = (struct TableEntry **)((char *)(*Typ)->Members + sizeof(struct Table)); + TableInitTable((*Typ)->Members, (struct TableEntry **)((char *)(*Typ)->Members + sizeof(struct Table)), STRUCT_TABLE_SIZE, TRUE); do { TypeParse(Parser, &MemberType, &MemberIdentifier); @@ -375,8 +375,9 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s case TokenLeftSquareBracket: { enum RunMode OldMode = Parser->Mode; + int ArraySize; Parser->Mode = RunModeRun; - int ArraySize = ExpressionParseInt(Parser); + ArraySize = ExpressionParseInt(Parser); Parser->Mode = OldMode; if (LexGetToken(Parser, NULL, TRUE) != TokenRightSquareBracket) @@ -386,8 +387,10 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s } break; -// case TokenOpenBracket: -// break; // XXX - finish this +#if 0 + case TokenOpenBracket: + break; /* XXX - finish this */ +#endif default: *Parser = Before; Done = TRUE; break; } diff --git a/variable.c b/variable.c index 30846ae..f5d505e 100644 --- a/variable.c +++ b/variable.c @@ -89,7 +89,7 @@ void *VariableAlloc(struct ParseState *Parser, int Size, int OnHeap) struct Value *VariableAllocValueAndData(struct ParseState *Parser, int DataSize, int IsLValue, struct Value *LValueFrom, int OnHeap) { struct Value *NewValue = VariableAlloc(Parser, sizeof(struct Value) + DataSize, OnHeap); - NewValue->Val = (union AnyValue *)((void *)NewValue + sizeof(struct Value)); + NewValue->Val = (union AnyValue *)((char *)NewValue + sizeof(struct Value)); NewValue->ValOnHeap = OnHeap; NewValue->ValOnStack = !OnHeap; NewValue->IsLValue = IsLValue; @@ -108,7 +108,7 @@ struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct Value if (Typ->Base == TypeArray) { NewValue->Val->Array.Size = Typ->ArraySize; - NewValue->Val->Array.Data = (void *)NewValue->Val + sizeof(struct ArrayValue); + NewValue->Val->Array.Data = (void *)((char *)NewValue->Val + sizeof(struct ArrayValue)); } return NewValue; @@ -210,8 +210,8 @@ void VariableStackPop(struct ParseState *Parser, struct Value *Var) int Success; #ifdef DEBUG_HEAP -// if (Var->ValOnStack) -// printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var); + if (Var->ValOnStack) + printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var); #endif if (Var->ValOnHeap) @@ -241,7 +241,7 @@ void VariableStackFrameAdd(struct ParseState *Parser, int NumParams) ProgramFail(Parser, "out of memory"); NewFrame->ReturnParser = *Parser; - NewFrame->Parameter = (NumParams > 0) ? ((void *)NewFrame + sizeof(struct StackFrame)) : NULL; + NewFrame->Parameter = (NumParams > 0) ? ((void *)((char *)NewFrame + sizeof(struct StackFrame))) : NULL; TableInitTable(&NewFrame->LocalTable, &NewFrame->LocalHashTable[0], LOCAL_TABLE_SIZE, FALSE); NewFrame->PreviousStackFrame = TopStackFrame; TopStackFrame = NewFrame; @@ -301,9 +301,9 @@ void *VariableDereferencePointer(struct ParseState *Parser, struct Value *Pointe /* return a pointer to the data */ if (PointedToValue->Typ->Base == TypeArray) - return PointedToValue->Val->Array.Data + PointerValue->Val->Pointer.Offset; + return (void *)((char *)PointedToValue->Val->Array.Data + PointerValue->Val->Pointer.Offset); else - return (void *)PointedToValue->Val + PointerValue->Val->Pointer.Offset; + return (void *)((char *)PointedToValue->Val + PointerValue->Val->Pointer.Offset); #else struct Value *PointedToValue = PointerValue->Val->NativePointer;