diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-09-14 01:45:31 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 35200031e88c65da6a0bde563f20d95c1dd4f464 (patch) | |
tree | b1159960ca7ba78a42f6ef203f99d2b1a1c26641 /src/bytecode | |
parent | 7d663615b2a44715e7447a40cae467d7d4e38b9c (diff) |
Use struct for bytecode header instead of pointer arithmetic
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; } |