// === GLOBALS ===
// === CODE ===
-int Bytecode_ConvertScript(tSpiderScript *Script, const char *DestFile)
+int SpiderScript_SaveBytecode(tSpiderScript *Script, const char *DestFile)
{
tStringList strings = {0};
tScript_Function *fcn;
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
{
_put32( StringList_GetString(&strings, fcn->Name, strlen(fcn->Name)) );
_put32( 0 ); // Code offset
- // TODO:
+ // TODO: Namespace
_put8( fcn->ReturnType );
if(fcn->ArgumentCount > 255) {
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);
{
tString *nextstr = str->Next;
fwrite(str->Data, str->Length, 1, fp);
- _put8(0);
+ _put8(0); // NULL separator
free(str);
str = nextstr;
}