SpiderScript - Moved header to directory, ready to remove from tree
[tpg/acess2.git] / Usermode / Libraries / libspiderscript.so_src / bytecode_makefile.c
index e2b5547..3c0347b 100644 (file)
@@ -18,7 +18,7 @@
 // === GLOBALS ===
 
 // === CODE ===
-int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile)
+int SpiderScript_SaveBytecode(tSpiderScript *Script, const char *DestFile)
 {
        tStringList     strings = {0};
        tScript_Function        *fcn;
@@ -42,7 +42,6 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile)
 
        fp = fopen(DestFile, "wb");
        if(!fp) return 1;
-       
        // Create header
        fwrite("SSBC\r\n\xBC\x55", 8, 1, fp);
        _put32(0);      // Function count, to be filled
@@ -57,7 +56,7 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile)
        {
                _put32( StringList_GetString(&strings, fcn->Name, strlen(fcn->Name)) );
                _put32( 0 );    // Code offset
-               // TODO: 
+               // TODO: Namespace
                _put8( fcn->ReturnType );
                
                if(fcn->ArgumentCount > 255) {
@@ -89,7 +88,13 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile)
                fcn_hdr_offset += 4+4+1+1+(4+1)*fcn->ArgumentCount;
                
                // Write code
-               if( !fcn->BCFcn )       Bytecode_ConvertFunction(fcn);
+               if( !fcn->BCFcn )
+                       Bytecode_ConvertFunction(fcn);
+               if( !fcn->BCFcn )
+               {
+                       fclose(fp);
+                       return 1;
+               }
                code = Bytecode_SerialiseFunction(fcn->BCFcn, &len, &strings);
                fwrite(code, len, 1, fp);
                free(code);
@@ -112,7 +117,7 @@ int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile)
                {
                        tString *nextstr = str->Next;
                        fwrite(str->Data, str->Length, 1, fp);
-                       _put8(0);
+                       _put8(0);       // NULL separator
                        free(str);
                        str = nextstr;
                }

UCC git Repository :: git.ucc.asn.au