New NO_FP compile option allows removal of all floating point support
git-svn-id: http://picoc.googlecode.com/svn/trunk@101 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
93a6a0e9d0
commit
e94767ba98
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall -g #-DDEBUG_LEXER #-DDEBUG_HEAP -DDEBUG_LEXER
|
||||
CFLAGS=-Wall -g #-DNO_FP #-DDEBUG_LEXER #-DDEBUG_HEAP
|
||||
LIBS=-lm
|
||||
|
||||
TARGET = picoc
|
||||
|
|
|
@ -87,9 +87,10 @@ void IntrinsicPrintf(struct Value *ReturnValue, struct Value **Param, int NumArg
|
|||
switch (*FPos)
|
||||
{
|
||||
case 's': FormatType = CharPtrType; break;
|
||||
case 'd': FormatType = &IntType; break;
|
||||
case 'c': FormatType = &CharType; break;
|
||||
case 'd': case 'c': FormatType = &IntType; break;
|
||||
#ifndef NO_FP
|
||||
case 'f': FormatType = &FPType; break;
|
||||
#endif
|
||||
case '%': fputc('%', stdout); FormatType = NULL; break;
|
||||
case '\0': FPos--; FormatType = NULL; break;
|
||||
default: putchar(*FPos); FormatType = NULL; break;
|
||||
|
@ -123,7 +124,9 @@ void IntrinsicPrintf(struct Value *ReturnValue, struct Value **Param, int NumArg
|
|||
}
|
||||
case 'd': IntrinsicPrintInt(NextArg->Val->Integer, stdout); break;
|
||||
case 'c': fputc(NextArg->Val->Integer, stdout); break;
|
||||
#ifndef NO_FP
|
||||
case 'f': IntrinsicPrintFP(NextArg->Val->FP, stdout); break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +202,9 @@ void IntrinsicHostVPrintf(const char *Format, va_list Args)
|
|||
case 's': fputs(va_arg(Args, char *), stdout); break;
|
||||
case 'd': IntrinsicPrintInt(va_arg(Args, int), stdout); break;
|
||||
case 'c': fputc(va_arg(Args, int), stdout); break;
|
||||
#ifndef NO_FP
|
||||
case 'f': IntrinsicPrintFP(va_arg(Args, double), stdout); break;
|
||||
#endif
|
||||
case '%': fputc('%', stdout); break;
|
||||
case '\0': FPos--; break;
|
||||
}
|
||||
|
|
14
lex.c
14
lex.c
|
@ -36,10 +36,14 @@ static struct ReservedWord ReservedWords[] =
|
|||
{ "continue", TokenContinue, NULL },
|
||||
{ "default", TokenDefault, NULL },
|
||||
{ "do", TokenDo, NULL },
|
||||
#ifndef NO_FP
|
||||
{ "double", TokenDoubleType, NULL },
|
||||
#endif
|
||||
{ "else", TokenElse, NULL },
|
||||
{ "enum", TokenEnumType, NULL },
|
||||
#ifndef NO_FP
|
||||
{ "float", TokenFloatType, NULL },
|
||||
#endif
|
||||
{ "for", TokenFor, NULL },
|
||||
{ "if", TokenIf, NULL },
|
||||
{ "int", TokenIntType, NULL },
|
||||
|
@ -80,18 +84,21 @@ enum LexToken LexCheckReservedWord(const char *Word)
|
|||
return TokenNone;
|
||||
}
|
||||
|
||||
/* skip a comment - used while scanning */
|
||||
/* get a numeric constant - used while scanning */
|
||||
enum LexToken LexGetNumber(struct LexState *Lexer, struct Value *Value)
|
||||
{
|
||||
int Result = 0;
|
||||
#ifndef NO_FP
|
||||
double FPResult;
|
||||
double FPDiv;
|
||||
#endif
|
||||
|
||||
for (; Lexer->Pos != Lexer->End && isdigit(*Lexer->Pos); Lexer->Pos++)
|
||||
Result = Result * 10 + (*Lexer->Pos - '0');
|
||||
|
||||
Value->Typ = &IntType;
|
||||
Value->Val->Integer = Result;
|
||||
#ifndef NO_FP
|
||||
if (Lexer->Pos == Lexer->End || *Lexer->Pos != '.')
|
||||
return TokenIntegerConstant;
|
||||
|
||||
|
@ -110,6 +117,9 @@ enum LexToken LexGetNumber(struct LexState *Lexer, struct Value *Value)
|
|||
}
|
||||
|
||||
return TokenFPConstant;
|
||||
#else
|
||||
return TokenIntegerConstant;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* get a reserved word or identifier - used while scanning */
|
||||
|
@ -435,7 +445,9 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I
|
|||
case TokenIdentifier: LexValue.Typ = NULL; break;
|
||||
case TokenIntegerConstant: LexValue.Typ = &IntType; break;
|
||||
case TokenCharacterConstant: LexValue.Typ = &CharType; break;
|
||||
#ifndef NO_FP
|
||||
case TokenFPConstant: LexValue.Typ = &FPType; break;
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
|
4
parse.c
4
parse.c
|
@ -237,12 +237,14 @@ int ParseValue(struct ParseState *Parser, struct Value **Result)
|
|||
return Success;
|
||||
}
|
||||
|
||||
#ifndef NO_FP
|
||||
struct Value *ParsePushFP(struct ParseState *Parser, double NewFP)
|
||||
{
|
||||
struct Value *Val = VariableAllocValueFromType(Parser, &FPType, FALSE);
|
||||
Val->Val->FP = NewFP;
|
||||
return Val;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct Value *ParsePushInt(struct ParseState *Parser, int NewInt)
|
||||
{
|
||||
|
@ -327,6 +329,7 @@ int ParseExpression(struct ParseState *Parser, struct Value **Result)
|
|||
|
||||
if (Parser->Mode == RunModeRun)
|
||||
{
|
||||
#ifndef NO_FP
|
||||
if (CurrentValue->Typ->Base == TypeFP || TotalValue->Typ->Base == TypeFP)
|
||||
{ /* floating point expression */
|
||||
double FPTotal, FPCurrent, FPResult;
|
||||
|
@ -368,6 +371,7 @@ int ParseExpression(struct ParseState *Parser, struct Value **Result)
|
|||
TotalValue = ParsePushFP(Parser, FPResult);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{ /* integer expression */
|
||||
int IntX, IntY, IntResult;
|
||||
|
||||
|
|
6
picoc.h
6
picoc.h
|
@ -93,7 +93,9 @@ enum BaseType
|
|||
{
|
||||
TypeVoid, /* no type */
|
||||
TypeInt, /* integer */
|
||||
#ifndef NO_FP
|
||||
TypeFP, /* floating point */
|
||||
#endif
|
||||
TypeChar, /* a single character - acts like an integer except in machine memory access */
|
||||
TypeFunction, /* a function */
|
||||
TypeMacro, /* a macro */
|
||||
|
@ -150,7 +152,9 @@ union AnyValue
|
|||
unsigned char Character;
|
||||
short ShortInteger;
|
||||
int Integer;
|
||||
#ifndef NO_FP
|
||||
double FP;
|
||||
#endif
|
||||
char *Identifier;
|
||||
struct ArrayValue Array;
|
||||
struct PointerValue Pointer;
|
||||
|
@ -217,7 +221,9 @@ extern struct Table GlobalTable;
|
|||
extern struct StackFrame *TopStackFrame;
|
||||
extern struct ValueType IntType;
|
||||
extern struct ValueType CharType;
|
||||
#ifndef NO_FP
|
||||
extern struct ValueType FPType;
|
||||
#endif
|
||||
extern struct ValueType VoidType;
|
||||
extern struct ValueType FunctionType;
|
||||
extern struct ValueType MacroType;
|
||||
|
|
6
type.c
6
type.c
|
@ -5,7 +5,9 @@ struct ValueType UberType;
|
|||
struct ValueType IntType;
|
||||
struct ValueType CharType;
|
||||
struct ValueType WordType;
|
||||
#ifndef NO_FP
|
||||
struct ValueType FPType;
|
||||
#endif
|
||||
struct ValueType VoidType;
|
||||
struct ValueType FunctionType;
|
||||
struct ValueType MacroType;
|
||||
|
@ -91,7 +93,9 @@ void TypeInit()
|
|||
{
|
||||
UberType.DerivedTypeList = NULL;
|
||||
TypeAddBaseType(&IntType, TypeInt, sizeof(int));
|
||||
#ifndef NO_FP
|
||||
TypeAddBaseType(&FPType, TypeFP, sizeof(double));
|
||||
#endif
|
||||
TypeAddBaseType(&VoidType, TypeVoid, 0);
|
||||
TypeAddBaseType(&FunctionType, TypeFunction, sizeof(int));
|
||||
TypeAddBaseType(&MacroType, TypeMacro, sizeof(int));
|
||||
|
@ -180,7 +184,9 @@ void TypeParse(struct ParseState *Parser, struct ValueType **Typ, char **Identif
|
|||
{
|
||||
case TokenIntType: case TokenLongType: case TokenShortType: *Typ = &IntType; break;
|
||||
case TokenCharType: *Typ = &CharType; break;
|
||||
#ifndef NO_FP
|
||||
case TokenFloatType: case TokenDoubleType: *Typ = &FPType; break;
|
||||
#endif
|
||||
case TokenVoidType: *Typ = &VoidType; break;
|
||||
|
||||
case TokenStructType: case TokenUnionType:
|
||||
|
|
Loading…
Reference in a new issue