From 7c2ce7290ae7f5f3dbe0f0e68f8383cd7aed2ca5 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Sun, 19 Apr 2009 01:15:01 +0000 Subject: [PATCH] Fixes for a clean surveyor compile git-svn-id: http://picoc.googlecode.com/svn/trunk@253 21eae674-98b7-11dd-bd71-f92a316d2d60 --- expression.c | 20 +++++++++++++------- heap.c | 2 +- library_surveyor.c | 25 ++++++++++++++++++------- platform.h | 3 ++- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/expression.c b/expression.c index 7e4dd0e..2f8b8a9 100644 --- a/expression.c +++ b/expression.c @@ -180,6 +180,7 @@ void ExpressionPushInt(struct ParseState *Parser, struct ExpressionStack **Stack ExpressionStackPushValueNode(Parser, StackTop, ValueLoc); } +#ifndef NO_FP void ExpressionPushFP(struct ParseState *Parser, struct ExpressionStack **StackTop, double FPValue) { debugf("ExpressionPushFP()\n"); @@ -187,6 +188,7 @@ void ExpressionPushFP(struct ParseState *Parser, struct ExpressionStack **StackT ValueLoc->Val->FP = FPValue; ExpressionStackPushValueNode(Parser, StackTop, ValueLoc); } +#endif /* evaluate a prefix operator */ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack **StackTop, enum LexToken Op, struct Value *TopValue) @@ -240,7 +242,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack if (IS_INTEGER_COERCIBLE(TopValue)) { /* integer prefix arithmetic */ - int ResultInt; + int ResultInt = 0; int TopInt = COERCE_INTEGER(TopValue); switch (Op) { @@ -293,7 +295,7 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack debugf("ExpressionPostfixOperator()\n"); if (IS_INTEGER_COERCIBLE(TopValue)) { - int ResultInt; + int ResultInt = 0; int TopInt = COERCE_INTEGER(TopValue); switch (Op) { @@ -311,8 +313,7 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack /* evaluate an infix operator */ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack **StackTop, enum LexToken Op, struct Value *BottomValue, struct Value *TopValue) { - int ResultIsInt = FALSE; - int ResultInt; + int ResultInt = 0; if (Parser->Mode != RunModeRun) { @@ -354,7 +355,9 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * case TokenSubtractAssign: ASSIGN_INT(BottomValue, BottomInt - TopInt); break; case TokenMultiplyAssign: ASSIGN_INT(BottomValue, BottomInt * TopInt); break; case TokenDivideAssign: ASSIGN_INT(BottomValue, BottomInt / TopInt); break; +#ifndef NO_MODULUS case TokenModulusAssign: ASSIGN_INT(BottomValue, BottomInt % TopInt); break; +#endif case TokenShiftLeftAssign: ASSIGN_INT(BottomValue, BottomInt << TopInt); break; case TokenShiftRightAssign: ASSIGN_INT(BottomValue, BottomInt >> TopInt); break; case TokenArithmeticAndAssign: ASSIGN_INT(BottomValue, BottomInt & TopInt); break; @@ -379,7 +382,9 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * case TokenMinus: ResultInt = BottomInt - TopInt; break; case TokenAsterisk: ResultInt = BottomInt * TopInt; break; case TokenSlash: ResultInt = BottomInt / TopInt; break; +#ifndef NO_MODULUS case TokenModulus: ResultInt = BottomInt % TopInt; break; +#endif default: ProgramFail(Parser, "invalid operation"); break; } @@ -391,7 +396,8 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * (IS_INTEGER_COERCIBLE(TopValue) && BottomValue->Typ == &FPType) ) { /* floating point infix arithmetic */ - double ResultFP; + int ResultIsInt = FALSE; + double ResultFP = 0.0; double TopFP = (TopValue->Typ == &FPType) ? TopValue->Val->FP : (double)COERCE_INTEGER(TopValue); double BottomFP = (BottomValue->Typ == &FPType) ? BottomValue->Val->FP : (double)COERCE_INTEGER(BottomValue); @@ -456,7 +462,7 @@ XXX - finish this if (BottomValue->Typ != TopValue->Typ) ProgramFail(Parser, "can't assign to a different type of variable"); - memcpy(BottomValue->Val, TopValue->Val, TypeSizeValue(TopValue)); + memcpy((void *)BottomValue->Val, (void *)TopValue->Val, TypeSizeValue(TopValue)); // XXX - need to handle arrays ExpressionStackPushValue(Parser, StackTop, TopValue); } else @@ -794,7 +800,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) /* do a function call */ void ExpressionParseFunctionCall(struct ParseState *Parser, struct ExpressionStack **StackTop, const char *FuncName) { - struct Value *ReturnValue; + struct Value *ReturnValue = NULL; struct Value *FuncValue; struct Value *Param; struct Value **ParamArray = NULL; diff --git a/heap.c b/heap.c index 1b53661..f2b49e1 100644 --- a/heap.c +++ b/heap.c @@ -9,7 +9,7 @@ static unsigned char *HeapMemory = (unsigned char *)C_HEAPSTART; /* all memory - stack and heap */ static void *HeapBottom = (void *)C_HEAPSTART + HEAP_SIZE; /* the bottom of the (downward-growing) heap */ static void *StackFrame = (void *)C_HEAPSTART; /* the current stack frame */ -static void *HeapStackTop = (void *)C_HEAPSTART; /* the top of the stack */ +void *HeapStackTop = (void *)C_HEAPSTART; /* the top of the stack */ #else static unsigned char HeapMemory[HEAP_SIZE]; /* all memory - stack and heap */ static void *HeapBottom = &HeapMemory[HEAP_SIZE]; /* the bottom of the (downward-growing) heap */ diff --git a/library_surveyor.c b/library_surveyor.c index 63c2f9f..88632f8 100644 --- a/library_surveyor.c +++ b/library_surveyor.c @@ -283,18 +283,18 @@ void Cvpix(struct ParseState *Parser, struct Value *ReturnValue, struct Value ** x = Param[0]->Val->Integer; y = Param[1]->Val->Integer; ix = vpix((unsigned char *)FRAME_BUF, x, y); - Iy1 = ((ix>>16) & 0x000000FF); // Y1 - Iu1 = ((ix>>24) & 0x000000FF); // U - Iv1 = ((ix>>8) & 0x000000FF); // V + Iy1 = ((ix>>16) & 0x000000FF); // Y1 + Iu1 = ((ix>>24) & 0x000000FF); // U + Iv1 = ((ix>>8) & 0x000000FF); // V } void Cvmean(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - vmean((unsigned char *)FRAME_BUF); + vmean((unsigned char *)FRAME_BUF); Iy1 = mean[0]; Iu1 = mean[1]; Iv1 = mean[2]; -} +} // search for blob by color, index; return center point X,Y and width Z void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { @@ -331,10 +331,20 @@ void Ccompass(struct ParseState *Parser, struct Value *ReturnValue, struct Value delayMS(10); i2c_data[0] = 0x41; i2cread(0x22, (unsigned char *)i2c_data, 2, SCCB_ON); - ix = ((i2c_data[0] << 8) + i2c_data[1]) / 10; + ix = ((unsigned int)(i2c_data[0] << 8) + i2c_data[1]) / 10; ReturnValue->Val->Integer = ix; } +void Ctilt(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return reading from HMC6352 I2C compass +{ + unsigned int ix; + + ix = (unsigned int)Param[0]->Val->Integer; + if ((ix<1) || (ix>3)) + ProgramFail(NULL, "tilt(): invalid channel"); + ReturnValue->Val->Integer = tilt(ix); +} + void Canalog(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return reading from HMC6352 I2C compass { unsigned char i2c_data[3], device_id; @@ -666,7 +676,7 @@ void Cnnlearnblob (struct ParseState *Parser, struct Value *ReturnValue, struct bloby1[0], bloby2[0], imgWidth, imgHeight); nnpack8x8(ix); nndisplay(ix); -} +} /* list of all library functions and their prototypes */ struct LibraryFunction PlatformLibrary[] = @@ -698,6 +708,7 @@ struct LibraryFunction PlatformLibrary[] = { Cvblob, "int vblob(int, int)" }, { Ccompass, "int compass()" }, { Canalog, "int analog(int)" }, + { Ctilt, "int tilt(int)" }, { Cgps, "void gps()" }, { Creadi2c, "int readi2c(int, int)" }, { Creadi2c2, "int readi2c2(int, int)" }, diff --git a/platform.h b/platform.h index b91b550..01f8d23 100644 --- a/platform.h +++ b/platform.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,6 +53,7 @@ extern jmp_buf ExitBuf; # define NO_FP # define NO_CTYPE # define NO_HASH_INCLUDE +# define NO_MODULUS # include # include "../string.h" # include "../print.h"