Skip to content

Commit

Permalink
Fixed NO_FP support
Browse files Browse the repository at this point in the history
  • Loading branch information
zik.saleeba committed Feb 10, 2011
1 parent 5986528 commit 54dc937
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cstdlib/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../picoc.h"

#ifndef BUILTIN_MINI_STDLIB
#ifndef NO_FP

static double M_EValue = 2.7182818284590452354; /* e */
static double M_LOG2EValue = 1.4426950408889634074; /* log_2 e */
Expand Down Expand Up @@ -182,4 +183,5 @@ void MathSetupFunc(void)
VariableDefinePlatformVar(NULL, "M_SQRT1_2", &FPType, (union AnyValue *)&M_SQRT1_2Value, FALSE);
}

#endif /* !NO_FP */
#endif /* !BUILTIN_MINI_STDLIB */
4 changes: 4 additions & 0 deletions cstdlib/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
{
case 'd': case 'i': ShowType = &IntType; break; /* integer decimal */
case 'o': case 'u': case 'x': case 'X': ShowType = &IntType; break; /* integer base conversions */
#ifndef NO_FP
case 'e': case 'E': ShowType = &FPType; break; /* double, exponent form */
case 'f': case 'F': ShowType = &FPType; break; /* double, fixed-point */
case 'g': case 'G': ShowType = &FPType; break; /* double, flexible format */
#endif
case 'a': case 'A': ShowType = &IntType; break; /* hexadecimal, 0x- format */
case 'c': ShowType = &IntType; break; /* character */
case 's': ShowType = CharPtrType; break; /* string */
Expand Down Expand Up @@ -257,6 +259,7 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
else
StdioOutPuts("XXX", &SOStream);
}
#ifndef NO_FP
else if (ShowType == &FPType)
{
/* show a floating point number */
Expand All @@ -265,6 +268,7 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
else
StdioOutPuts("XXX", &SOStream);
}
#endif
else if (ShowType == CharPtrType)
{
if (ThisArg->Typ->Base == TypePointer)
Expand Down
8 changes: 7 additions & 1 deletion cstdlib/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

static int ZeroValue = 0;

#ifndef NO_FP
void StdlibAtof(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->FP = atof(Param[0]->Val->Pointer);
}
#endif

void StdlibAtoi(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
Expand All @@ -20,10 +22,12 @@ void StdlibAtol(struct ParseState *Parser, struct Value *ReturnValue, struct Val
ReturnValue->Val->Integer = atol(Param[0]->Val->Pointer);
}

#ifndef NO_FP
void StdlibStrtod(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->FP = strtod(Param[0]->Val->Pointer, Param[1]->Val->Pointer);
}
#endif

void StdlibStrtol(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
Expand Down Expand Up @@ -130,10 +134,12 @@ typedef struct { \
/* all stdlib.h functions */
struct LibraryFunction StdlibFunctions[] =
{
#ifndef NO_FP
{ StdlibAtof, "float atof(char *);" },
{ StdlibStrtod, "float strtod(char *,char **);" },
#endif
{ StdlibAtoi, "int atoi(char *);" },
{ StdlibAtol, "int atol(char *);" },
{ StdlibStrtod, "float strtod(char *,char **);" },
{ StdlibStrtol, "int strtol(char *,char **,int);" },
{ StdlibStrtoul, "int strtoul(char *,char **,int);" },
{ StdlibMalloc, "void *malloc(int);" },
Expand Down
4 changes: 4 additions & 0 deletions cstdlib/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ void StdCtime(struct ParseState *Parser, struct Value *ReturnValue, struct Value
ReturnValue->Val->Pointer = ctime(Param[0]->Val->Pointer);
}

#ifndef NO_FP
void StdDifftime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->FP = difftime((time_t)Param[0]->Val->Integer, Param[1]->Val->Integer);
}
#endif

void StdGmtime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
Expand Down Expand Up @@ -88,7 +90,9 @@ struct LibraryFunction StdTimeFunctions[] =
{ StdAsctime, "char *asctime(struct tm *);" },
{ StdClock, "time_t clock();" },
{ StdCtime, "char *ctime(int *);" },
#ifndef NO_FP
{ StdDifftime, "double difftime(int, int);" },
#endif
{ StdGmtime, "struct tm *gmtime(int *);" },
{ StdGmtime_r, "struct tm *gmtime_r(int *, struct tm *);" },
{ StdLocaltime, "struct tm *localtime(int *);" },
Expand Down
4 changes: 4 additions & 0 deletions expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,11 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack
if (Parser->Mode == RunModeRun)
{
/* create a stack frame for this macro */
#ifndef NO_FP
ExpressionStackPushValueByType(Parser, StackTop, &FPType); /* largest return type there is */
#else
ExpressionStackPushValueByType(Parser, StackTop, VoidPtrType); /* largest return type there is */
#endif
ReturnValue = (*StackTop)->Val;
HeapPushStackFrame();
ParamArray = HeapAllocStack(sizeof(struct Value *) * MDef->NumParams);
Expand Down
2 changes: 2 additions & 0 deletions include.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ void IncludeInit()
#ifndef BUILTIN_MINI_STDLIB
IncludeRegister("ctype.h", NULL, &StdCtypeFunctions[0], NULL);
IncludeRegister("errno.h", &StdErrnoSetupFunc, NULL, NULL);
#ifndef NO_FP
IncludeRegister("math.h", &MathSetupFunc, &MathFunctions[0], NULL);
#endif
IncludeRegister("stdbool.h", &StdboolSetupFunc, NULL, StdboolDefs);
IncludeRegister("stdio.h", &StdioSetupFunc, &StdioFunctions[0], StdioDefs);
IncludeRegister("stdlib.h", &StdlibSetupFunc, &StdlibFunctions[0], NULL);
Expand Down
Loading

0 comments on commit 54dc937

Please sign in to comment.