X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FLibraries%2Flibspiderscript.so_src%2Fbytecode_makefile.c;h=5affbef0ff2f3497acf9f30a32a25ac71f69dd11;hb=f9c581641afeb556188e84428febd4011e61edc2;hp=a4c9b717ed74095384e46fc1d7c0ea91b5313995;hpb=1e45480331132c75898cbdd761ddd1fa48739e54;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libspiderscript.so_src/bytecode_makefile.c b/Usermode/Libraries/libspiderscript.so_src/bytecode_makefile.c index a4c9b717..5affbef0 100644 --- a/Usermode/Libraries/libspiderscript.so_src/bytecode_makefile.c +++ b/Usermode/Libraries/libspiderscript.so_src/bytecode_makefile.c @@ -18,14 +18,15 @@ // === GLOBALS === // === CODE === -int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile) +int SpiderScript_SaveBytecode(tSpiderScript *Script, const char *DestFile) { tStringList strings = {0}; - tAST_Function *fcn; + tScript_Function *fcn; FILE *fp; int fcn_hdr_offset = 0; int fcn_count = 0; int strtab_ofs; + int i; void _put8(uint8_t val) { @@ -52,12 +53,11 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile) fcn_hdr_offset = ftell(fp); // Create function descriptors - for(fcn = Script->Script->Functions; fcn; fcn = fcn->Next, fcn_count ++) + for(fcn = Script->Functions; fcn; fcn = fcn->Next, fcn_count ++) { - tAST_Node *arg; - _put32( StringList_GetString(&strings, fcn->Name, strlen(fcn->Name)) ); _put32( 0 ); // Code offset + // TODO: Namespace _put8( fcn->ReturnType ); if(fcn->ArgumentCount > 255) { @@ -67,19 +67,18 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile) _put8( fcn->ArgumentCount ); // Argument types? - for(arg = fcn->Arguments; arg; arg = arg->NextSibling) + for( i = 0; i < fcn->ArgumentCount; i ++ ) { - _put32( StringList_GetString(&strings, arg->DefVar.Name, strlen(arg->DefVar.Name)) ); - _put8( arg->DefVar.DataType ); + _put32( StringList_GetString(&strings, fcn->Arguments[i].Name, strlen(fcn->Arguments[i].Name)) ); + _put8( fcn->Arguments[i].Type ); } } // Put function code in - for(fcn = Script->Script->Functions; fcn; fcn = fcn->Next) + for(fcn = Script->Functions; fcn; fcn = fcn->Next) { char *code; int len, code_pos; - tBC_Function *bc_fcn; // Fix header code_pos = ftell(fp); @@ -90,10 +89,10 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile) fcn_hdr_offset += 4+4+1+1+(4+1)*fcn->ArgumentCount; // Write code - bc_fcn = Bytecode_ConvertFunction(fcn); - code = Bytecode_SerialiseFunction(bc_fcn, &len, &strings); - Bytecode_DeleteFunction(bc_fcn); + if( !fcn->BCFcn ) Bytecode_ConvertFunction(fcn); + code = Bytecode_SerialiseFunction(fcn->BCFcn, &len, &strings); fwrite(code, len, 1, fp); + free(code); } // String table @@ -109,11 +108,16 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile) string_offset += str->Length + 1; } // Data - for(str = strings.Head; str; str = str->Next) + for(str = strings.Head; str;) { + tString *nextstr = str->Next; fwrite(str->Data, str->Length, 1, fp); _put8(0); + free(str); + str = nextstr; } + strings.Head = NULL; + strings.Tail = NULL; } // Fix header @@ -122,6 +126,8 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile) _put32(strings.Count); _put32(strtab_ofs); + fclose(fp); + return 0; }