Platform libraries now require explicit #includes

git-svn-id: http://picoc.googlecode.com/svn/trunk@440 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2010-06-13 20:47:17 +00:00
parent e564b173be
commit 985e6c960f
8 changed files with 102 additions and 64 deletions

View file

@ -1,6 +1,5 @@
CC=gcc
#CFLAGS=-Wall -pedantic -g -DUNIX_HOST
CFLAGS=-Wall -pedantic -g -DSRV1_UNIX_HOST
CFLAGS=-Wall -pedantic -g -DUNIX_HOST
LIBS=-lm
TARGET = picoc

View file

@ -9,28 +9,46 @@ struct IncludeLibrary
void (*SetupFunction)(void);
struct LibraryFunction (*FuncList)[];
const char *SetupCSource;
struct IncludeLibrary *NextLib;
};
struct IncludeLibrary IncludeLibInfo[] =
struct IncludeLibrary *IncludeLibList = NULL;
/* initialise the built-in include libraries */
void IncludeInit()
{
{ "stdio.h",
&StdioSetupFunc,
&StdioFunctions,
StdioDefs },
{ "math.h",
&MathSetupFunc,
&MathFunctions,
NULL },
{ "string.h",
&StringSetupFunc,
&StringFunctions,
NULL },
{ "stdlib.h",
&StdlibSetupFunc,
&StdlibFunctions,
NULL },
{ NULL, NULL, NULL, NULL }
};
IncludeRegister("stdio.h", &StdioSetupFunc, &StdioFunctions, StdioDefs);
IncludeRegister("math.h", &MathSetupFunc, &MathFunctions, NULL);
IncludeRegister("string.h", &StringSetupFunc, &StringFunctions, NULL);
IncludeRegister("stdlib.h", &StdlibSetupFunc, &StdlibFunctions, NULL);
}
/* clean up space used by the include system */
void IncludeCleanup()
{
struct IncludeLibrary *ThisInclude = IncludeLibList;
struct IncludeLibrary *NextInclude;
while (ThisInclude != NULL)
{
NextInclude = ThisInclude->NextLib;
HeapFreeMem(ThisInclude);
ThisInclude = NextInclude;
}
}
/* register a new build-in include file */
void IncludeRegister(const char *IncludeName, void (*SetupFunction)(void), struct LibraryFunction (*FuncList)[], const char *SetupCSource)
{
struct IncludeLibrary *NewLib = HeapAllocMem(sizeof(struct IncludeLibrary));
NewLib->IncludeName = TableStrRegister(IncludeName);
NewLib->SetupFunction = SetupFunction;
NewLib->FuncList = FuncList;
NewLib->SetupCSource = SetupCSource;
NewLib->NextLib = IncludeLibList;
IncludeLibList = NewLib;
}
/* include one of a number of predefined libraries, or perhaps an actual file */
@ -39,7 +57,7 @@ void IncludeFile(char *FileName)
struct IncludeLibrary *LInclude;
/* scan for the include file name to see if it's in our list of predefined includes */
for (LInclude = &IncludeLibInfo[0]; LInclude->IncludeName != NULL; LInclude++)
for (LInclude = IncludeLibList; LInclude != NULL; LInclude = LInclude->NextLib)
{
if (strcmp(LInclude->IncludeName, FileName) == 0)
{

View file

@ -9,18 +9,19 @@ void Initialise()
VariableInit();
LexInit();
TypeInit();
IncludeInit();
#ifdef BUILTIN_MINI_STDLIB
LibraryInit(&GlobalTable, "c library", &CLibrary);
CLibraryInit();
#endif
PlatformLibraryInit();
LibraryInit(&GlobalTable, "platform library", &PlatformLibrary);
}
/* free memory */
void Cleanup()
{
PlatformCleanup();
IncludeCleanup();
ParseCleanup();
LexCleanup();
VariableCleanup();

View file

@ -291,7 +291,6 @@ extern struct ValueType *VoidPtrType;
extern char *StrEmpty;
extern struct PointerValue NULLPointer;
extern struct LibraryFunction CLibrary[];
extern struct LibraryFunction PlatformLibrary[];
extern IOFILE *CStdOut;
/* table.c */
@ -410,6 +409,9 @@ void Initialise();
void Cleanup();
/* include.c */
void IncludeInit();
void IncludeCleanup();
void IncludeRegister(const char *IncludeName, void (*SetupFunction)(void), struct LibraryFunction (*FuncList)[], const char *SetupCSource);
void IncludeFile(char *Filename);
/* stdio.c */

View file

@ -1,12 +1,13 @@
#include "../picoc.h"
void PlatformLibraryInit()
{
}
/* list of all library functions and their prototypes */
struct LibraryFunction PlatformLibrary[] =
{
{ NULL, NULL }
};
void PlatformLibraryInit()
{
LibraryInit(&GlobalTable, "platform library", &PlatformLibrary);
}

View file

@ -4,10 +4,11 @@ static int Blobcnt, Blobx1, Blobx2, Bloby1, Bloby2, Iy1, Iy2, Iu1, Iu2, Iv1, Iv2
static int GPSlat, GPSlon, GPSalt, GPSfix, GPSsat, GPSutc, Elcount, Ercount;
static int ScanVect[16], NNVect[NUM_OUTPUT];
void PlatformLibraryInit()
{
struct ValueType *IntArrayType;
struct ValueType *IntArrayType;
void SRV1SetupFunc()
{
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty);
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
@ -733,8 +734,14 @@ void Cerrormsg (struct ParseState *Parser, struct Value *ReturnValue, struct Val
LibPrintf(Parser, ReturnValue, Param, NumArgs);
}
/* list of all library functions and their prototypes */
/* nothing here because we don't add any functions until srv1.h is #included */
struct LibraryFunction PlatformLibrary[] =
{
{ NULL, NULL }
};
/* list of all library functions included with srv1.h */
struct LibraryFunction SRV1Functions[] =
{
{ Csignal, "int signal();" },
{ Cinput, "int input();" },
@ -796,3 +803,7 @@ struct LibraryFunction PlatformLibrary[] =
{ NULL, NULL }
};
void PlatformLibraryInit()
{
IncludeRegister("srv1.h", &SRV1SetupFunc, &SRV1Functions, NULL);
}

View file

@ -4,34 +4,6 @@ static int Blobcnt, Blobx1, Blobx2, Bloby1, Bloby2, Iy1, Iy2, Iu1, Iu2, Iv1, Iv2
static int GPSlat, GPSlon, GPSalt, GPSfix, GPSsat, GPSutc, Elcount, Ercount;
static int ScanVect[16], NNVect[NUM_OUTPUT];
void PlatformLibraryInit()
{
struct ValueType *IntArrayType;
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty);
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
VariableDefinePlatformVar(NULL, "blobcnt", &IntType, (union AnyValue *)&Blobcnt, FALSE);
VariableDefinePlatformVar(NULL, "blobx1", &IntType, (union AnyValue *)&Blobx1, FALSE);
VariableDefinePlatformVar(NULL, "blobx2", &IntType, (union AnyValue *)&Blobx2, FALSE);
VariableDefinePlatformVar(NULL, "bloby1", &IntType, (union AnyValue *)&Bloby1, FALSE);
VariableDefinePlatformVar(NULL, "bloby2", &IntType, (union AnyValue *)&Bloby2, FALSE);
VariableDefinePlatformVar(NULL, "lcount", &IntType, (union AnyValue *)&Elcount, FALSE);
VariableDefinePlatformVar(NULL, "rcount", &IntType, (union AnyValue *)&Ercount, FALSE);
VariableDefinePlatformVar(NULL, "y1", &IntType, (union AnyValue *)&Iy1, FALSE);
VariableDefinePlatformVar(NULL, "y2", &IntType, (union AnyValue *)&Iy2, FALSE);
VariableDefinePlatformVar(NULL, "u1", &IntType, (union AnyValue *)&Iu1, FALSE);
VariableDefinePlatformVar(NULL, "u2", &IntType, (union AnyValue *)&Iu2, FALSE);
VariableDefinePlatformVar(NULL, "v1", &IntType, (union AnyValue *)&Iv1, FALSE);
VariableDefinePlatformVar(NULL, "v2", &IntType, (union AnyValue *)&Iv2, FALSE);
VariableDefinePlatformVar(NULL, "gpslat", &IntType, (union AnyValue *)&GPSlat, FALSE);
VariableDefinePlatformVar(NULL, "gpslon", &IntType, (union AnyValue *)&GPSlon, FALSE);
VariableDefinePlatformVar(NULL, "gpsalt", &IntType, (union AnyValue *)&GPSalt, FALSE);
VariableDefinePlatformVar(NULL, "gpsfix", &IntType, (union AnyValue *)&GPSfix, FALSE);
VariableDefinePlatformVar(NULL, "gpssat", &IntType, (union AnyValue *)&GPSsat, FALSE);
VariableDefinePlatformVar(NULL, "gpsutc", &IntType, (union AnyValue *)&GPSutc, FALSE);
}
void Csignal(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // check for kbhit, return t or nil
{
if (getsignal())
@ -796,3 +768,33 @@ struct LibraryFunction PlatformLibrary[] =
{ NULL, NULL }
};
void PlatformLibraryInit()
{
struct ValueType *IntArrayType;
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty);
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
VariableDefinePlatformVar(NULL, "blobcnt", &IntType, (union AnyValue *)&Blobcnt, FALSE);
VariableDefinePlatformVar(NULL, "blobx1", &IntType, (union AnyValue *)&Blobx1, FALSE);
VariableDefinePlatformVar(NULL, "blobx2", &IntType, (union AnyValue *)&Blobx2, FALSE);
VariableDefinePlatformVar(NULL, "bloby1", &IntType, (union AnyValue *)&Bloby1, FALSE);
VariableDefinePlatformVar(NULL, "bloby2", &IntType, (union AnyValue *)&Bloby2, FALSE);
VariableDefinePlatformVar(NULL, "lcount", &IntType, (union AnyValue *)&Elcount, FALSE);
VariableDefinePlatformVar(NULL, "rcount", &IntType, (union AnyValue *)&Ercount, FALSE);
VariableDefinePlatformVar(NULL, "y1", &IntType, (union AnyValue *)&Iy1, FALSE);
VariableDefinePlatformVar(NULL, "y2", &IntType, (union AnyValue *)&Iy2, FALSE);
VariableDefinePlatformVar(NULL, "u1", &IntType, (union AnyValue *)&Iu1, FALSE);
VariableDefinePlatformVar(NULL, "u2", &IntType, (union AnyValue *)&Iu2, FALSE);
VariableDefinePlatformVar(NULL, "v1", &IntType, (union AnyValue *)&Iv1, FALSE);
VariableDefinePlatformVar(NULL, "v2", &IntType, (union AnyValue *)&Iv2, FALSE);
VariableDefinePlatformVar(NULL, "gpslat", &IntType, (union AnyValue *)&GPSlat, FALSE);
VariableDefinePlatformVar(NULL, "gpslon", &IntType, (union AnyValue *)&GPSlon, FALSE);
VariableDefinePlatformVar(NULL, "gpsalt", &IntType, (union AnyValue *)&GPSalt, FALSE);
VariableDefinePlatformVar(NULL, "gpsfix", &IntType, (union AnyValue *)&GPSfix, FALSE);
VariableDefinePlatformVar(NULL, "gpssat", &IntType, (union AnyValue *)&GPSsat, FALSE);
VariableDefinePlatformVar(NULL, "gpsutc", &IntType, (union AnyValue *)&GPSutc, FALSE);
LibraryInit(&GlobalTable, "platform library", &PlatformLibrary);
}

View file

@ -1,7 +1,7 @@
#include "../picoc.h"
void PlatformLibraryInit()
{
void UnixSetupFunc()
{
}
void Ctest (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
@ -16,10 +16,14 @@ void Clineno (struct ParseState *Parser, struct Value *ReturnValue, struct Value
}
/* list of all library functions and their prototypes */
struct LibraryFunction PlatformLibrary[] =
struct LibraryFunction UnixFunctions[] =
{
{ Ctest, "void test(int);" },
{ Clineno, "int lineno();" },
{ NULL, NULL }
};
void PlatformLibraryInit()
{
IncludeRegister("picoc_unix.h", &UnixSetupFunc, &UnixFunctions, NULL);
}