2009-02-24 06:16:37 -05:00
|
|
|
#include "picoc.h"
|
|
|
|
|
|
|
|
void SayHello(struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
|
|
|
{
|
|
|
|
PlatformPrintf("Hello\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintInteger(struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
|
|
|
{
|
|
|
|
PlatformPrintf("%d\n", Param[0]->Val->Integer);
|
|
|
|
}
|
|
|
|
|
2009-02-28 14:57:03 -05:00
|
|
|
#ifdef UNIX_HOST
|
|
|
|
void Random(struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
|
|
|
{
|
|
|
|
ReturnValue->Val->Integer = random();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-28 15:46:02 -05:00
|
|
|
static int SomeVar = 42;
|
2009-02-28 16:08:00 -05:00
|
|
|
static int SomeArray[4];
|
2009-02-28 15:46:02 -05:00
|
|
|
void PlatformLibraryInit()
|
|
|
|
{
|
2009-02-28 16:08:00 -05:00
|
|
|
struct ValueType *IntArrayType;
|
|
|
|
|
2009-02-28 15:46:02 -05:00
|
|
|
VariableDefinePlatformVar(NULL, "somevar", &IntType, (union AnyValue *)&SomeVar, TRUE);
|
2009-02-28 16:08:00 -05:00
|
|
|
|
|
|
|
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 4, NULL);
|
|
|
|
SomeArray[0] = 12;
|
|
|
|
SomeArray[1] = 34;
|
|
|
|
SomeArray[2] = 56;
|
|
|
|
SomeArray[3] = 78;
|
|
|
|
VariableDefinePlatformVar(NULL, "somearray", IntArrayType, (union AnyValue *)&SomeArray, FALSE);
|
2009-02-28 15:46:02 -05:00
|
|
|
}
|
|
|
|
|
2009-02-24 06:16:37 -05:00
|
|
|
/* list of all library functions and their prototypes */
|
|
|
|
struct LibraryFunction PlatformLibrary[] =
|
|
|
|
{
|
|
|
|
{ SayHello, "void sayhello()" },
|
|
|
|
{ PrintInteger, "void printint(int)" },
|
2009-02-28 14:57:03 -05:00
|
|
|
#ifdef UNIX_HOST
|
2009-02-28 16:08:00 -05:00
|
|
|
{ Random, "int random()" },
|
2009-02-28 14:57:03 -05:00
|
|
|
#endif
|
2009-02-24 06:16:37 -05:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|