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");
46 ret = malloc(sizeof(tSpiderScript));
47 ret->Variant = Variant;
49 fseek(fp, 0, SEEK_END);
51 fseek(fp, 0, SEEK_SET);
53 // Allocate and read data
54 data = malloc(fLen + 1);
55 if(!data) return NULL;
56 fread(data, fLen, 1, fp);
61 ret->CurNamespace = NULL;
62 ret->Script = Parse_Buffer(Variant, data);
63 if( ret->Script == NULL ) {
76 printf("Total Size: "); fflush(stdout);
77 size = AST_WriteScript(NULL, ret->Script);
78 printf("0x%x bytes\n", (unsigned)size);
80 fp = fopen(cacheFilename, "wb");
84 size = AST_WriteScript(data, ret->Script);
85 fwrite(data, size, 1, fp);
94 * \brief Free a script
96 void SpiderScript_Free(tSpiderScript *Script)
98 tAST_Function *fcn = Script->Script->Functions;
99 tAST_Function *nextFcn;
100 tAST_Node *var, *nextVar;
106 AST_FreeNode( fcn->Code );
108 var = fcn->Arguments;
111 nextVar = var->NextSibling;
121 // TODO: Pass this off to AST for a proper cleanup
122 free(Script->Script);