2 * Acess2 - SpiderScript
8 #include <spiderscript.h>
12 extern tAST_Script *Parse_Buffer(tSpiderVariant *Variant, char *Buffer);
13 extern tAST_Variable *Variable_Define(tAST_BlockState *Block, int Type, const char *Name);
14 extern void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderValue *Value);
15 extern void Variable_Destroy(tAST_Variable *Variable);
19 * \brief Library Entry Point
27 * \brief Parse a script
29 tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename)
31 char cacheFilename[strlen(Filename)+6+1];
37 strcpy(cacheFilename, Filename);
38 strcat(cacheFilename, ".cache");
40 fp = fopen(Filename, "r");
45 fseek(fp, 0, SEEK_END);
47 fseek(fp, 0, SEEK_SET);
49 // Allocate and read data
50 data = malloc(fLen + 1);
51 if(!data) return NULL;
52 fLen = fread(data, 1, fLen, fp);
62 ret = malloc(sizeof(tSpiderScript));
63 ret->Variant = Variant;
65 ret->CurNamespace = NULL;
66 ret->Script = Parse_Buffer(Variant, data);
67 if( ret->Script == NULL ) {
80 printf("Total Size: "); fflush(stdout);
81 size = AST_WriteScript(NULL, ret->Script);
82 printf("0x%x bytes\n", (unsigned)size);
84 fp = fopen(cacheFilename, "wb");
88 size = AST_WriteScript(data, ret->Script);
89 fwrite(data, size, 1, fp);
98 * \brief Free a script
100 void SpiderScript_Free(tSpiderScript *Script)
102 tAST_Function *fcn = Script->Script->Functions;
103 tAST_Function *nextFcn;
104 tAST_Node *var, *nextVar;
110 AST_FreeNode( fcn->Code );
112 var = fcn->Arguments;
115 nextVar = var->NextSibling;
125 // TODO: Pass this off to AST for a proper cleanup
126 free(Script->Script);