2008-12-26 23:36:45 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "picoc.h"
|
|
|
|
|
2009-02-19 18:55:40 -05:00
|
|
|
void IntrinsicPrintInt(struct Value *ReturnValue, struct Value **Param)
|
2009-01-03 23:08:49 -05:00
|
|
|
{
|
2009-02-19 18:55:40 -05:00
|
|
|
printf("%d\n", Param[0]->Val->Integer);
|
2009-01-03 23:08:49 -05:00
|
|
|
}
|
|
|
|
|
2009-02-19 18:55:40 -05:00
|
|
|
void IntrinsicPrintf(struct Value *ReturnValue, struct Value **Param)
|
2008-12-26 23:36:45 -05:00
|
|
|
{
|
|
|
|
printf("IntrinsicPrintf\n");
|
|
|
|
}
|
|
|
|
|
2009-02-19 18:55:40 -05:00
|
|
|
void IntrinsicSayHello(struct Value *ReturnValue, struct Value **Param)
|
2008-12-26 23:36:45 -05:00
|
|
|
{
|
|
|
|
printf("Hello\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct IntrinsicFunction
|
|
|
|
{
|
2009-02-19 18:55:40 -05:00
|
|
|
void (*Func)(struct Value *, struct Value **);
|
2008-12-26 23:36:45 -05:00
|
|
|
const char *Prototype;
|
|
|
|
} Intrinsics[] =
|
|
|
|
{
|
2009-02-20 04:04:45 -05:00
|
|
|
{ IntrinsicSayHello, "void sayhello()" },
|
|
|
|
{ IntrinsicPrintf, "void printf(char *, ...)" },
|
|
|
|
{ IntrinsicPrintInt, "void printint(int)" },
|
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;
|
2009-02-02 06:50:55 -05:00
|
|
|
void *Tokens;
|
|
|
|
const char *IntrinsicName = StrRegister("intrinsic");
|
2008-12-26 23:36:45 -05:00
|
|
|
|
|
|
|
for (Count = 0; Count < sizeof(Intrinsics) / sizeof(struct IntrinsicFunction); Count++)
|
|
|
|
{
|
2009-02-02 06:50:55 -05:00
|
|
|
Tokens = LexAnalyse(IntrinsicName, Intrinsics[Count].Prototype, strlen(Intrinsics[Count].Prototype));
|
2009-02-18 03:19:06 -05:00
|
|
|
LexInitParser(&Parser, Tokens, IntrinsicName, Count+1, TRUE);
|
2009-02-01 22:27:05 -05:00
|
|
|
TypeParse(&Parser, &ReturnType, &Identifier);
|
|
|
|
NewValue = ParseFunctionDefinition(&Parser, ReturnType, Identifier, TRUE);
|
|
|
|
NewValue->Val->FuncDef.Intrinsic = Intrinsics[Count].Func;
|
2009-02-02 06:51:45 -05:00
|
|
|
HeapFree(Tokens);
|
2008-12-26 23:36:45 -05:00
|
|
|
}
|
|
|
|
}
|