stdlib.h library in progress

git-svn-id: http://picoc.googlecode.com/svn/trunk@436 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2010-06-13 14:39:20 +00:00
parent 019731da60
commit 62ade18048

View file

@ -6,6 +6,36 @@
static int ZeroValue = 0;
static int TRUEValue = 1;
void StdlibAtof(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->FP = atof(Param[0]->Val->NativePointer);
}
void StdlibAtoi(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = atoi(Param[0]->Val->NativePointer);
}
void StdlibAtol(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = atol(Param[0]->Val->NativePointer);
}
void StdlibStrtod(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->FP = strtod(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer);
}
void StdlibStrtol(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = strtol(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
}
void StdlibStrtoul(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = strtoul(Param[0]->Val->NativePointer, Param[1]->Val->NativePointer, Param[2]->Val->Integer);
}
void StdlibMalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->NativePointer = malloc(Param[0]->Val->Integer);
@ -26,14 +56,56 @@ void StdlibFree(struct ParseState *Parser, struct Value *ReturnValue, struct Val
free(Param[0]->Val->NativePointer);
}
void StdlibRand(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = rand();
}
void StdlibSrand(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
srand(Param[0]->Val->Integer);
}
void StdlibAbort(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ProgramFail(Parser, "abort");
}
void StdlibExit(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
PlatformExit(Param[0]->Val->Integer);
}
void StdlibGetenv(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->NativePointer = getenv(Param[0]->Val->NativePointer);
}
void StdlibSystem(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
ReturnValue->Val->Integer = system(Param[0]->Val->NativePointer);
}
/* all stdlib.h functions */
struct LibraryFunction StdlibFunctions[] =
{
{ StdlibMalloc, "void *malloc(int);" },
{ StdlibCalloc, "void *calloc(int,int);" },
{ StdlibRealloc, "void *realloc(void *,int);" },
{ StdlibFree, "void free(void *);" },
{ NULL, NULL }
{ StdlibAtof, "float atof(char *);" },
{ 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);" },
{ StdlibCalloc, "void *calloc(int,int);" },
{ StdlibRealloc, "void *realloc(void *,int);" },
{ StdlibFree, "void free(void *);" },
{ StdlibRand, "int rand();" },
{ StdlibSrand, "void srand(int);" },
{ StdlibAbort, "void abort();" },
{ StdlibExit, "void exit(int);" },
{ StdlibGetenv, "char *getenv(char *);" },
{ StdlibSystem, "int system(char *);" },
{ NULL, NULL }
};
/* creates various system-dependent definitions */