minor formatting, add message on how to terminate interactive mode

This commit is contained in:
Joseph Poirier 2015-06-14 15:48:18 -05:00
parent 7c21d0a54f
commit 1ff1ef9cfb
5 changed files with 70 additions and 77 deletions

View file

@ -697,7 +697,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
if (TopValue->Typ == &Parser->pc->FPType) { if (TopValue->Typ == &Parser->pc->FPType) {
/* floating point prefix arithmetic */ /* floating point prefix arithmetic */
double ResultFP = 0.0; double ResultFP = 0.0;
switch (Op) { switch (Op) {
case TokenPlus: case TokenPlus:
ResultFP = TopValue->Val->FP; ResultFP = TopValue->Val->FP;
@ -756,13 +755,10 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
int Size = TypeSize(TopValue->Typ->FromType, 0, true); int Size = TypeSize(TopValue->Typ->FromType, 0, true);
struct Value *StackValue; struct Value *StackValue;
void *ResultPtr; void *ResultPtr;
if (TopValue->Val->Pointer == NULL) if (TopValue->Val->Pointer == NULL)
ProgramFail(Parser, "invalid use of a NULL pointer"); ProgramFail(Parser, "a. invalid use of a NULL pointer");
if (!TopValue->IsLValue) if (!TopValue->IsLValue)
ProgramFail(Parser, "can't assign to this"); ProgramFail(Parser, "can't assign to this");
switch (Op) { switch (Op) {
case TokenIncrement: case TokenIncrement:
TopValue->Val->Pointer = TopValue->Val->Pointer =
@ -776,13 +772,13 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
ProgramFail(Parser, "invalid operation"); ProgramFail(Parser, "invalid operation");
break; break;
} }
ResultPtr = TopValue->Val->Pointer; ResultPtr = TopValue->Val->Pointer;
StackValue = ExpressionStackPushValueByType(Parser, StackTop, StackValue = ExpressionStackPushValueByType(Parser, StackTop,
TopValue->Typ); TopValue->Typ);
StackValue->Val->Pointer = ResultPtr; StackValue->Val->Pointer = ResultPtr;
} else } else {
ProgramFail(Parser, "invalid operation"); ProgramFail(Parser, "invalid operation");
}
break; break;
} }
} }
@ -811,8 +807,7 @@ void ExpressionPostfixOperator(struct ParseState *Parser,
break; break;
} }
ExpressionPushFP(Parser, StackTop, ResultFP); ExpressionPushFP(Parser, StackTop, ResultFP);
} } else if (IS_NUMERIC_COERCIBLE(TopValue)) {
else if (IS_NUMERIC_COERCIBLE(TopValue)) {
long ResultInt = 0; long ResultInt = 0;
long TopInt = ExpressionCoerceInteger(TopValue); long TopInt = ExpressionCoerceInteger(TopValue);
switch (Op) { switch (Op) {
@ -840,7 +835,7 @@ void ExpressionPostfixOperator(struct ParseState *Parser,
void *OrigPointer = TopValue->Val->Pointer; void *OrigPointer = TopValue->Val->Pointer;
if (TopValue->Val->Pointer == NULL) if (TopValue->Val->Pointer == NULL)
ProgramFail(Parser, "invalid use of a NULL pointer"); ProgramFail(Parser, "b. invalid use of a NULL pointer");
if (!TopValue->IsLValue) if (!TopValue->IsLValue)
ProgramFail(Parser, "can't assign to this"); ProgramFail(Parser, "can't assign to this");
@ -859,8 +854,7 @@ void ExpressionPostfixOperator(struct ParseState *Parser,
StackValue = ExpressionStackPushValueByType(Parser, StackTop, StackValue = ExpressionStackPushValueByType(Parser, StackTop,
TopValue->Typ); TopValue->Typ);
StackValue->Val->Pointer = OrigPointer; StackValue->Val->Pointer = OrigPointer;
} } else
else
ProgramFail(Parser, "invalid operation"); ProgramFail(Parser, "invalid operation");
} }
@ -1121,7 +1115,7 @@ void ExpressionInfixOperator(struct ParseState *Parser,
Pointer = BottomValue->Val->Pointer; Pointer = BottomValue->Val->Pointer;
if (Pointer == NULL) if (Pointer == NULL)
ProgramFail(Parser, "invalid use of a NULL pointer"); ProgramFail(Parser, "c. invalid use of a NULL pointer");
if (Op == TokenPlus) if (Op == TokenPlus)
Pointer = (void*)((char*)Pointer + TopInt * Size); Pointer = (void*)((char*)Pointer + TopInt * Size);
@ -1142,7 +1136,7 @@ void ExpressionInfixOperator(struct ParseState *Parser,
Pointer = BottomValue->Val->Pointer; Pointer = BottomValue->Val->Pointer;
if (Pointer == NULL) if (Pointer == NULL)
ProgramFail(Parser, "invalid use of a NULL pointer"); ProgramFail(Parser, "d. invalid use of a NULL pointer");
if (Op == TokenAddAssign) if (Op == TokenAddAssign)
Pointer = (void*)((char*)Pointer + TopInt * Size); Pointer = (void*)((char*)Pointer + TopInt * Size);

View file

@ -40,6 +40,7 @@ typedef FILE IOFILE;
#define IS_FP(v) ((v)->Typ->Base == TypeFP) #define IS_FP(v) ((v)->Typ->Base == TypeFP)
#define FP_VAL(v) ((v)->Val->FP) #define FP_VAL(v) ((v)->Val->FP)
/* ap -> AllowPointerCoercion = true | false*/
#define IS_POINTER_COERCIBLE(v, ap) ((ap) ? ((v)->Typ->Base == TypePointer) : 0) #define IS_POINTER_COERCIBLE(v, ap) ((ap) ? ((v)->Typ->Base == TypePointer) : 0)
#define POINTER_COERCE(v) ((int)(v)->Val->Pointer) #define POINTER_COERCE(v) ((int)(v)->Val->Pointer)

View file

@ -583,13 +583,11 @@ enum ParseResult ParseStatement(struct ParseState *Parser,
struct Value *VarValue; struct Value *VarValue;
struct ParseState PreState; struct ParseState PreState;
#ifdef DEBUGGER
/* if we're debugging, check for a breakpoint */ /* if we're debugging, check for a breakpoint */
if (Parser->DebugMode && Parser->Mode == RunModeRun) if (Parser->DebugMode && Parser->Mode == RunModeRun)
#ifdef DEBUGGER DebugCheckStatement(Parser);
DebugCheckStatement(Parser)
#endif #endif
;
/* take note of where we are and then grab a token to see what /* take note of where we are and then grab a token to see what
statement we have */ statement we have */

View file

@ -25,7 +25,7 @@ int main(int argc, char **argv)
printf(PICOC_VERSION " \n" printf(PICOC_VERSION " \n"
"Format: picoc <file1.c>... [- <arg1>...] : run a program (calls main() to start it)\n" "Format: picoc <file1.c>... [- <arg1>...] : run a program (calls main() to start it)\n"
" picoc -s <file1.c>... [- <arg1>...] : script mode - runs the program without calling main()\n" " picoc -s <file1.c>... [- <arg1>...] : script mode - runs the program without calling main()\n"
" picoc -i : interactive mode\n"); " picoc -i : interactive mode (Ctrl+D to exit)\n");
exit(1); exit(1);
} }

View file

@ -46,7 +46,7 @@
#define LOCAL_TABLE_SIZE (11) /* size of local variable table (can expand) */ #define LOCAL_TABLE_SIZE (11) /* size of local variable table (can expand) */
#define STRUCT_TABLE_SIZE (11) /* size of struct/union member table (can expand) */ #define STRUCT_TABLE_SIZE (11) /* size of struct/union member table (can expand) */
#define INTERACTIVE_PROMPT_START "starting picoc " PICOC_VERSION "\n" #define INTERACTIVE_PROMPT_START "starting picoc " PICOC_VERSION " (Ctrl+D to exit)\n"
#define INTERACTIVE_PROMPT_STATEMENT "picoc> " #define INTERACTIVE_PROMPT_STATEMENT "picoc> "
#define INTERACTIVE_PROMPT_LINE " > " #define INTERACTIVE_PROMPT_LINE " > "