2008-12-26 23:36:45 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "picoc.h"
|
|
|
|
|
2009-01-03 23:08:49 -05:00
|
|
|
void IntrinsicPrintInt(void)
|
|
|
|
{
|
2009-01-26 03:57:32 -05:00
|
|
|
printf("%d\n", Parameter[0]->Val->Integer);
|
2009-01-03 23:08:49 -05:00
|
|
|
}
|
|
|
|
|
2008-12-26 23:36:45 -05:00
|
|
|
void IntrinsicPrintf(void)
|
|
|
|
{
|
|
|
|
printf("IntrinsicPrintf\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicSayHello(void)
|
|
|
|
{
|
|
|
|
printf("Hello\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct IntrinsicFunction
|
|
|
|
{
|
|
|
|
void (*Func)(void);
|
|
|
|
const char *Prototype;
|
|
|
|
} Intrinsics[] =
|
|
|
|
{
|
|
|
|
{ IntrinsicSayHello, "void sayhello()" }, /* -1 */
|
|
|
|
{ IntrinsicPrintf, "void printf()" }, /* -2 */
|
2009-01-03 23:08:49 -05:00
|
|
|
{ IntrinsicPrintInt, "void printint(int)" }, /* -3 */
|
2008-12-26 23:36:45 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
void IntrinsicInit(struct Table *GlobalTable)
|
|
|
|
{
|
2009-02-01 22:27:05 -05:00
|
|
|
struct ParseState Parser;
|
2008-12-26 23:36:45 -05:00
|
|
|
int Count;
|
2009-02-01 22:27:05 -05:00
|
|
|
const char *Identifier;
|
|
|
|
struct ValueType *ReturnType;
|
|
|
|
struct Value *NewValue;
|
2008-12-26 23:36:45 -05:00
|
|
|
|
|
|
|
for (Count = 0; Count < sizeof(Intrinsics) / sizeof(struct IntrinsicFunction); Count++)
|
|
|
|
{
|
2009-02-01 22:27:05 -05:00
|
|
|
LexInit(&Parser, Intrinsics[Count].Prototype, strlen(Intrinsics[Count].Prototype), "", Count+1);
|
|
|
|
TypeParse(&Parser, &ReturnType, &Identifier);
|
|
|
|
NewValue = ParseFunctionDefinition(&Parser, ReturnType, Identifier, TRUE);
|
|
|
|
NewValue->Val->FuncDef.Intrinsic = Intrinsics[Count].Func;
|
2008-12-26 23:36:45 -05:00
|
|
|
}
|
|
|
|
}
|