2 * Acess2 - SpiderScript
8 #include <spiderscript.h>
11 #include "bytecode_gen.h"
14 extern int Parse_Buffer(tSpiderScript *Script, const char *Buffer, const char *Filename);
15 extern tAST_Variable *Variable_Define(tAST_BlockState *Block, int Type, const char *Name);
16 extern void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderValue *Value);
17 extern void Variable_Destroy(tAST_Variable *Variable);
21 * \brief Library Entry Point
29 * \brief Parse a script
31 tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename)
33 char cacheFilename[strlen(Filename)+6+1];
39 strcpy(cacheFilename, Filename);
40 strcat(cacheFilename, ".cache");
42 fp = fopen(Filename, "r");
47 fseek(fp, 0, SEEK_END);
49 fseek(fp, 0, SEEK_SET);
51 // Allocate and read data
52 data = malloc(fLen + 1);
53 if(!data) return NULL;
54 fLen = fread(data, 1, fLen, fp);
64 ret = malloc(sizeof(tSpiderScript));
65 ret->Variant = Variant;
66 ret->Functions = NULL;
67 ret->LastFunction = NULL;
69 ret->CurNamespace = NULL;
70 if( Parse_Buffer(ret, data, Filename) ) {
83 printf("Total Size: "); fflush(stdout);
84 size = AST_WriteScript(NULL, ret);
85 printf("0x%x bytes\n", (unsigned)size);
87 fp = fopen(cacheFilename, "wb");
91 size = AST_WriteScript(data, ret);
92 fwrite(data, size, 1, fp);
100 int SpiderScript_SaveBytecode(tSpiderScript *Script, const char *DestFile)
102 return Bytecode_ConvertScript(Script, DestFile);
106 * \brief Free a script
108 void SpiderScript_Free(tSpiderScript *Script)
110 tScript_Function *fcn = Script->Functions;
111 tScript_Function *nextFcn;
116 if(fcn->ASTFcn) AST_FreeNode( fcn->ASTFcn );
117 if(fcn->BCFcn) Bytecode_DeleteFunction( fcn->BCFcn );