From d09e156558ef27cbd34b2d96f053234ed86c0af8 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Sun, 8 Nov 2009 19:23:50 +0000 Subject: [PATCH] Fixes for Surveyor SRV-1 platform git-svn-id: http://picoc.googlecode.com/svn/trunk@398 21eae674-98b7-11dd-bd71-f92a316d2d60 --- clibrary.c | 12 ++++++++++-- expression.c | 26 ++++++++++++++++++++++---- heap.c | 2 +- lex.c | 2 +- parse.c | 4 ++-- platform.h | 4 ++++ 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/clibrary.c b/clibrary.c index 8a8428b..70c2756 100644 --- a/clibrary.c +++ b/clibrary.c @@ -425,15 +425,19 @@ void LibMalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Valu ReturnValue->Val->NativePointer = malloc(Param[0]->Val->Integer); } +#ifndef NO_CALLOC void LibCalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->NativePointer = calloc(Param[0]->Val->Integer, Param[1]->Val->Integer); } +#endif +#ifndef NO_REALLOC void LibRealloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->NativePointer = realloc(Param[0]->Val->NativePointer, Param[1]->Val->Integer); } +#endif void LibFree(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { @@ -603,11 +607,15 @@ struct LibraryFunction CLibrary[] = { LibCeil, "float ceil(float)" }, { LibFloor, "float floor(float)" }, #endif -#ifndef NO_STRING_FUNCTIONS { LibMalloc, "void *malloc(int)" }, +#ifndef NO_CALLOC { LibCalloc, "void *calloc(int,int)" }, - { LibCalloc, "void *realloc(void *,int)" }, +#endif +#ifndef NO_REALLOC + { LibRealloc, "void *realloc(void *,int)" }, +#endif { LibFree, "void free(void *)" }, +#ifndef NO_STRING_FUNCTIONS { LibStrcpy, "void strcpy(char *,char *)" }, { LibStrncpy, "void strncpy(char *,char *,int)" }, { LibStrcmp, "int strcmp(char *,char *)" }, diff --git a/expression.c b/expression.c index 975e3c8..adcf1a0 100644 --- a/expression.c +++ b/expression.c @@ -171,8 +171,26 @@ unsigned long ExpressionCoerceUnsignedInteger(struct Value *Val) } } +#ifndef NO_FP double ExpressionCoerceFP(struct Value *Val) { +#ifndef BROKEN_FLOAT_CASTS + int IntVal; + unsigned UnsignedVal; + + switch (Val->Typ->Base) + { + case TypeInt: IntVal = Val->Val->Integer; return (double)IntVal; + case TypeChar: IntVal = Val->Val->Character; return (double)IntVal; + case TypeShort: IntVal = Val->Val->ShortInteger; return (double)IntVal; + case TypeLong: IntVal = Val->Val->LongInteger; return (double)IntVal; + case TypeUnsignedInt: UnsignedVal = Val->Val->UnsignedInteger; return (double)UnsignedVal; + case TypeUnsignedShort: UnsignedVal = Val->Val->UnsignedShortInteger; return (double)UnsignedVal; + case TypeUnsignedLong: UnsignedVal = Val->Val->UnsignedLongInteger; return (double)UnsignedVal; + case TypeFP: return Val->Val->FP; + default: return 0.0; + } +#else switch (Val->Typ->Base) { case TypeInt: return (double)Val->Val->Integer; @@ -182,12 +200,12 @@ double ExpressionCoerceFP(struct Value *Val) case TypeUnsignedInt: return (double)Val->Val->UnsignedInteger; case TypeUnsignedShort: return (double)Val->Val->UnsignedShortInteger; case TypeUnsignedLong: return (double)Val->Val->UnsignedLongInteger; -#ifndef NO_FP case TypeFP: return (double)Val->Val->FP; -#endif - default: return 0; + default: return 0.0; } +#endif } +#endif /* assign an integer value */ long ExpressionAssignInt(struct ParseState *Parser, struct Value *DestValue, long FromInt, int After) @@ -574,7 +592,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * { /* array index */ int ArrayIndex; - struct Value *Result; + struct Value *Result = NULL; if (!IS_NUMERIC_COERCIBLE(TopValue)) ProgramFail(Parser, "array index must be an integer"); diff --git a/heap.c b/heap.c index 5760b73..e23b072 100644 --- a/heap.c +++ b/heap.c @@ -65,7 +65,7 @@ void *HeapAllocStack(int Size) return NULL; HeapStackTop = (void *)NewTop; - memset(NewMem, '\0', Size); + memset((void *)NewMem, '\0', Size); return NewMem; } diff --git a/lex.c b/lex.c index ab11afd..3f1c9c4 100644 --- a/lex.c +++ b/lex.c @@ -482,7 +482,7 @@ void *LexTokenise(struct LexState *Lexer, int *TokenLen) if (ValueSize > 0) { /* store a value as well */ - memcpy(TokenPos, (void *)GotValue->Val, ValueSize); + memcpy((void *)TokenPos, (void *)GotValue->Val, ValueSize); TokenPos += ValueSize; MemUsed += ValueSize; } diff --git a/parse.c b/parse.c index 4302d16..1edbb77 100644 --- a/parse.c +++ b/parse.c @@ -123,7 +123,7 @@ void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVari for (ArrayIndex = 0; ArrayIndex < NewVariable->Typ->ArraySize; ArrayIndex++) { - struct Value *ArrayElement; + struct Value *ArrayElement = NULL; if (Token != TokenComma) ProgramFail(Parser, "comma expected"); @@ -170,7 +170,7 @@ int ParseDeclaration(struct ParseState *Parser, enum LexToken Token) char *Identifier; struct ValueType *BasicType; struct ValueType *Typ; - struct Value *NewVariable; + struct Value *NewVariable = NULL; TypeParseFront(Parser, &BasicType); do diff --git a/platform.h b/platform.h index 23932cb..8a5a033 100644 --- a/platform.h +++ b/platform.h @@ -93,12 +93,16 @@ extern jmp_buf ExitBuf; # include "../gps.h" # include "../i2c.h" # include "../jpeg.h" +# include "../malloc.h" # define assert(x) # undef INTERACTIVE_PROMPT_STATEMENT # undef INTERACTIVE_PROMPT_LINE # define INTERACTIVE_PROMPT_STATEMENT "> " # define INTERACTIVE_PROMPT_LINE "- " # undef BIG_ENDIAN +# define NO_CALLOC +# define NO_REALLOC +# define BROKEN_FLOAT_CASTS # else # ifdef UMON_HOST # define HEAP_SIZE (128*1024) /* space for the heap and the stack */