Skip to content

Commit

Permalink
Add ALIB chunk and improve object file padding
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed Apr 24, 2017
1 parent f7b07d0 commit 59f399f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/codegen/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static void do_sary( struct codegen* codegen );
static void write_sary_chunk( struct codegen* codegen, const char* chunk_name,
int index, struct list* vars );
static bool script_array( struct var* var );
static void do_alib( struct codegen* codegen );

void c_write_chunk_obj( struct codegen* codegen ) {
if ( codegen->task->library_main->format == FORMAT_LITTLE_E ) {
Expand Down Expand Up @@ -73,14 +74,7 @@ void c_write_chunk_obj( struct codegen* codegen ) {
do_mstr( codegen );
do_astr( codegen );
do_atag( codegen );
}
// NOTE: When a BEHAVIOR lump is below 32 bytes in size, the engine will not
// process it. It will consider the lump as being of unknown format, even
// though it appears to be valid, just empty. An unknown format is an error,
// and will cause the engine to halt execution of other scripts. Pad up to
// the minimum limit to avoid this situation.
while ( c_tell( codegen ) < 32 ) {
c_add_byte( codegen, 0 );
do_alib( codegen );
}
c_add_int( codegen, chunk_pos );
c_add_str( codegen, codegen->compress ? "ACSe" : "ACSE" );
Expand Down Expand Up @@ -116,6 +110,14 @@ void c_write_chunk_obj( struct codegen* codegen ) {
}
// Write dummy strings.
c_add_int( codegen, 0 );
// NOTE: When a BEHAVIOR lump is below 32 bytes in size, the engine will not
// process it. It will consider the lump as being of unknown format, even
// though it appears to be valid, just empty. An unknown format is an error,
// and will cause the engine to halt execution of other scripts. Pad up to
// the minimum limit to avoid this situation.
while ( c_tell( codegen ) < 32 ) {
c_add_byte( codegen, 0 );
}
// Write header.
c_seek( codegen, 0 );
c_add_sized( codegen, "ACS\0", 4 );
Expand Down Expand Up @@ -1136,3 +1138,8 @@ inline bool script_array( struct var* var ) {
return ( var->storage == STORAGE_LOCAL && ( var->dim ||
( ! var->ref && var->structure ) ) );
}

static void do_alib( struct codegen* codegen ) {
c_add_str( codegen, "ALIB" );
c_add_int( codegen, 0 );
}

0 comments on commit 59f399f

Please sign in to comment.