diff options
Diffstat (limited to 'src/bytecode')
-rw-r--r-- | src/bytecode/bytecode.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/bytecode/bytecode.c b/src/bytecode/bytecode.c index c968743..0a2b157 100644 --- a/src/bytecode/bytecode.c +++ b/src/bytecode/bytecode.c @@ -42,20 +42,24 @@ CHECK_RESULT int buffer_append_header(Buffer *program_data) { |u8 |Major version|The major version of the bytecode. Updates in this is a breaking change. | |u8 |Minor version|The minor version of the bytecode. Updates in this are backwards compatible.| |u8 |Patch version|The patch version of the bytecode. Updates in this are only minor bug fixes.| + |u8 |Endian |Endian of the program. 0 = little endian, 1 = big endian. | The versions in the header only changes for every release, not every change. */ - const u32 magic_number = AMAL_BYTECODE_MAGIC_NUMBER; - const u8 major_version = AMAL_BYTECODE_MAJOR_VERSION; - const u8 minor_version = AMAL_BYTECODE_MINOR_VERSION; - const u8 patch_version = AMAL_BYTECODE_PATCH_VERSION; - - return_if_error(buffer_append(program_data, &magic_number, 4)); - return_if_error(buffer_append(program_data, &major_version, 1)); - return_if_error(buffer_append(program_data, &minor_version, 1)); - return_if_error(buffer_append(program_data, &patch_version, 1)); - + BytecodeHeader header; + header.magic_number = AMAL_BYTECODE_MAGIC_NUMBER; + header.major_version = AMAL_BYTECODE_MAJOR_VERSION; + header.minor_version = AMAL_BYTECODE_MINOR_VERSION; + header.patch_version = AMAL_BYTECODE_PATCH_VERSION; +#if defined(AMAL_LITTLE_ENDIAN) + header.endian = 0; +#elif defined(AMAL_BIG_ENDIAN) + header.magic_number = byteswap32(header.magic_number); + header.endian = 1; +#endif + + return_if_error(buffer_append(program_data, &header, sizeof(header))); return 0; } |