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:
parent
e564b173be
commit
985e6c960f
3
Makefile
3
Makefile
|
@ -1,6 +1,5 @@
|
||||||
CC=gcc
|
CC=gcc
|
||||||
#CFLAGS=-Wall -pedantic -g -DUNIX_HOST
|
CFLAGS=-Wall -pedantic -g -DUNIX_HOST
|
||||||
CFLAGS=-Wall -pedantic -g -DSRV1_UNIX_HOST
|
|
||||||
LIBS=-lm
|
LIBS=-lm
|
||||||
|
|
||||||
TARGET = picoc
|
TARGET = picoc
|
||||||
|
|
58
include.c
58
include.c
|
@ -9,28 +9,46 @@ struct IncludeLibrary
|
||||||
void (*SetupFunction)(void);
|
void (*SetupFunction)(void);
|
||||||
struct LibraryFunction (*FuncList)[];
|
struct LibraryFunction (*FuncList)[];
|
||||||
const char *SetupCSource;
|
const char *SetupCSource;
|
||||||
|
struct IncludeLibrary *NextLib;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IncludeLibrary IncludeLibInfo[] =
|
struct IncludeLibrary *IncludeLibList = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/* initialise the built-in include libraries */
|
||||||
|
void IncludeInit()
|
||||||
{
|
{
|
||||||
{ "stdio.h",
|
IncludeRegister("stdio.h", &StdioSetupFunc, &StdioFunctions, StdioDefs);
|
||||||
&StdioSetupFunc,
|
IncludeRegister("math.h", &MathSetupFunc, &MathFunctions, NULL);
|
||||||
&StdioFunctions,
|
IncludeRegister("string.h", &StringSetupFunc, &StringFunctions, NULL);
|
||||||
StdioDefs },
|
IncludeRegister("stdlib.h", &StdlibSetupFunc, &StdlibFunctions, NULL);
|
||||||
{ "math.h",
|
}
|
||||||
&MathSetupFunc,
|
|
||||||
&MathFunctions,
|
/* clean up space used by the include system */
|
||||||
NULL },
|
void IncludeCleanup()
|
||||||
{ "string.h",
|
{
|
||||||
&StringSetupFunc,
|
struct IncludeLibrary *ThisInclude = IncludeLibList;
|
||||||
&StringFunctions,
|
struct IncludeLibrary *NextInclude;
|
||||||
NULL },
|
|
||||||
{ "stdlib.h",
|
while (ThisInclude != NULL)
|
||||||
&StdlibSetupFunc,
|
{
|
||||||
&StdlibFunctions,
|
NextInclude = ThisInclude->NextLib;
|
||||||
NULL },
|
HeapFreeMem(ThisInclude);
|
||||||
{ NULL, NULL, NULL, NULL }
|
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 */
|
/* include one of a number of predefined libraries, or perhaps an actual file */
|
||||||
|
@ -39,7 +57,7 @@ void IncludeFile(char *FileName)
|
||||||
struct IncludeLibrary *LInclude;
|
struct IncludeLibrary *LInclude;
|
||||||
|
|
||||||
/* scan for the include file name to see if it's in our list of predefined includes */
|
/* 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)
|
if (strcmp(LInclude->IncludeName, FileName) == 0)
|
||||||
{
|
{
|
||||||
|
|
3
picoc.c
3
picoc.c
|
@ -9,18 +9,19 @@ void Initialise()
|
||||||
VariableInit();
|
VariableInit();
|
||||||
LexInit();
|
LexInit();
|
||||||
TypeInit();
|
TypeInit();
|
||||||
|
IncludeInit();
|
||||||
#ifdef BUILTIN_MINI_STDLIB
|
#ifdef BUILTIN_MINI_STDLIB
|
||||||
LibraryInit(&GlobalTable, "c library", &CLibrary);
|
LibraryInit(&GlobalTable, "c library", &CLibrary);
|
||||||
CLibraryInit();
|
CLibraryInit();
|
||||||
#endif
|
#endif
|
||||||
PlatformLibraryInit();
|
PlatformLibraryInit();
|
||||||
LibraryInit(&GlobalTable, "platform library", &PlatformLibrary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free memory */
|
/* free memory */
|
||||||
void Cleanup()
|
void Cleanup()
|
||||||
{
|
{
|
||||||
PlatformCleanup();
|
PlatformCleanup();
|
||||||
|
IncludeCleanup();
|
||||||
ParseCleanup();
|
ParseCleanup();
|
||||||
LexCleanup();
|
LexCleanup();
|
||||||
VariableCleanup();
|
VariableCleanup();
|
||||||
|
|
4
picoc.h
4
picoc.h
|
@ -291,7 +291,6 @@ extern struct ValueType *VoidPtrType;
|
||||||
extern char *StrEmpty;
|
extern char *StrEmpty;
|
||||||
extern struct PointerValue NULLPointer;
|
extern struct PointerValue NULLPointer;
|
||||||
extern struct LibraryFunction CLibrary[];
|
extern struct LibraryFunction CLibrary[];
|
||||||
extern struct LibraryFunction PlatformLibrary[];
|
|
||||||
extern IOFILE *CStdOut;
|
extern IOFILE *CStdOut;
|
||||||
|
|
||||||
/* table.c */
|
/* table.c */
|
||||||
|
@ -410,6 +409,9 @@ void Initialise();
|
||||||
void Cleanup();
|
void Cleanup();
|
||||||
|
|
||||||
/* include.c */
|
/* include.c */
|
||||||
|
void IncludeInit();
|
||||||
|
void IncludeCleanup();
|
||||||
|
void IncludeRegister(const char *IncludeName, void (*SetupFunction)(void), struct LibraryFunction (*FuncList)[], const char *SetupCSource);
|
||||||
void IncludeFile(char *Filename);
|
void IncludeFile(char *Filename);
|
||||||
|
|
||||||
/* stdio.c */
|
/* stdio.c */
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#include "../picoc.h"
|
#include "../picoc.h"
|
||||||
|
|
||||||
void PlatformLibraryInit()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* list of all library functions and their prototypes */
|
/* list of all library functions and their prototypes */
|
||||||
struct LibraryFunction PlatformLibrary[] =
|
struct LibraryFunction PlatformLibrary[] =
|
||||||
{
|
{
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void PlatformLibraryInit()
|
||||||
|
{
|
||||||
|
LibraryInit(&GlobalTable, "platform library", &PlatformLibrary);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 GPSlat, GPSlon, GPSalt, GPSfix, GPSsat, GPSutc, Elcount, Ercount;
|
||||||
static int ScanVect[16], NNVect[NUM_OUTPUT];
|
static int ScanVect[16], NNVect[NUM_OUTPUT];
|
||||||
|
|
||||||
void PlatformLibraryInit()
|
|
||||||
{
|
|
||||||
struct ValueType *IntArrayType;
|
struct ValueType *IntArrayType;
|
||||||
|
|
||||||
|
|
||||||
|
void SRV1SetupFunc()
|
||||||
|
{
|
||||||
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty);
|
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty);
|
||||||
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
||||||
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, 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);
|
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[] =
|
struct LibraryFunction PlatformLibrary[] =
|
||||||
|
{
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
/* list of all library functions included with srv1.h */
|
||||||
|
struct LibraryFunction SRV1Functions[] =
|
||||||
{
|
{
|
||||||
{ Csignal, "int signal();" },
|
{ Csignal, "int signal();" },
|
||||||
{ Cinput, "int input();" },
|
{ Cinput, "int input();" },
|
||||||
|
@ -796,3 +803,7 @@ struct LibraryFunction PlatformLibrary[] =
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void PlatformLibraryInit()
|
||||||
|
{
|
||||||
|
IncludeRegister("srv1.h", &SRV1SetupFunc, &SRV1Functions, NULL);
|
||||||
|
}
|
||||||
|
|
|
@ -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 GPSlat, GPSlon, GPSalt, GPSfix, GPSsat, GPSutc, Elcount, Ercount;
|
||||||
static int ScanVect[16], NNVect[NUM_OUTPUT];
|
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
|
void Csignal(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // check for kbhit, return t or nil
|
||||||
{
|
{
|
||||||
if (getsignal())
|
if (getsignal())
|
||||||
|
@ -796,3 +768,33 @@ struct LibraryFunction PlatformLibrary[] =
|
||||||
{ NULL, NULL }
|
{ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../picoc.h"
|
#include "../picoc.h"
|
||||||
|
|
||||||
void PlatformLibraryInit()
|
void UnixSetupFunc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,14 @@ void Clineno (struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
||||||
}
|
}
|
||||||
|
|
||||||
/* list of all library functions and their prototypes */
|
/* list of all library functions and their prototypes */
|
||||||
struct LibraryFunction PlatformLibrary[] =
|
struct LibraryFunction UnixFunctions[] =
|
||||||
{
|
{
|
||||||
{ Ctest, "void test(int);" },
|
{ Ctest, "void test(int);" },
|
||||||
{ Clineno, "int lineno();" },
|
{ Clineno, "int lineno();" },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void PlatformLibraryInit()
|
||||||
|
{
|
||||||
|
IncludeRegister("picoc_unix.h", &UnixSetupFunc, &UnixFunctions, NULL);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue