diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-18 06:37:58 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | d4d33a89586b5210d1f0bc81d95fa2b640da659b (patch) | |
tree | 1502737b7a9e34493665ce88b66c2e0d80d31118 | |
parent | 04b7ba96dbabea540f96ba7f72a220f067e9aaf8 (diff) |
Cleanup on test failure
-rw-r--r-- | doc/Documentation.md | 20 | ||||
-rw-r--r-- | executor/x86_64/executor.c | 1 | ||||
-rw-r--r-- | src/bytecode/bytecode.c | 20 | ||||
-rw-r--r-- | tests/main.c | 23 |
4 files changed, 35 insertions, 29 deletions
diff --git a/doc/Documentation.md b/doc/Documentation.md index a046057..79e81aa 100644 --- a/doc/Documentation.md +++ b/doc/Documentation.md @@ -57,11 +57,11 @@ The versions in the header only changes for every release, not every change. # Bytecode strings ## Strings layout -|Type |Field |Description | -|-------|-----------------|------------------------------------------------------------------| -|u16 |Number of strings|The number of strings. | -|u32 |Strings size |The size of the strings section, in bytes. | -|String*|Strings data |Multiple strings, where the total size is defined by @Strings size| +|Type |Field |Description | +|------|-----------------|------------------------------------------------------------------| +|u16 |Number of strings|The number of strings. | +|u32 |Strings size |The size of the strings section, in bytes. | +|String|Strings data |Multiple strings, where the total size is defined by @Strings size| ## String |Type|Field|Description | @@ -77,11 +77,11 @@ The versions in the header only changes for every release, not every change. # Bytecode external functions ## External functions layout -|Type |Field |Description | -|------------------|------------------|-----------------------------------------------------------------------------------------| -|u16 |num_extern_func |The number of external functions. | -|u32 |extern_funcs_size |The size of the external functions section, in bytes. | -|External function*|External functions|Multiple external functions, where the number of functions is defined by @num_extern_func| +|Type |Field |Description | +|-----------------|------------------|-----------------------------------------------------------------------------------------| +|u16 |num_extern_func |The number of external functions. | +|u32 |extern_funcs_size |The size of the external functions section, in bytes. | +|External function|External functions|Multiple external functions, where the number of functions is defined by @num_extern_func| ## External function |Type|Field |Description | diff --git a/executor/x86_64/executor.c b/executor/x86_64/executor.c index ebe848d..fbe227a 100644 --- a/executor/x86_64/executor.c +++ b/executor/x86_64/executor.c @@ -35,6 +35,7 @@ typedef struct { The first parameter is located at 3*sizeof(usize) and the next one is at 4*sizeof(usize). Parameter starts at 3*sizeof(usize) because offset 0 is the return address, offset 1*sizeof(usize) is the saved RBP and 2*sizeof(usize) is saved RBX. + TODO: Use different offset when saving more registers, for example on Microsoft Windows. */ #define get_register_stack_offset(reg) \ (reg >= 0 ? (i32)(-reg * (int)sizeof(usize) - sizeof(usize)) : (i32)(-reg * (int)sizeof(usize) + 2*sizeof(usize))) diff --git a/src/bytecode/bytecode.c b/src/bytecode/bytecode.c index edc8dba..8daa4ce 100644 --- a/src/bytecode/bytecode.c +++ b/src/bytecode/bytecode.c @@ -107,11 +107,11 @@ static void add_intermediates(BytecodeCompilerContext *self) { static void add_strings(BytecodeCompilerContext *self) { /*doc(Bytecode strings) # Strings layout - |Type |Field |Description | - |-------|-----------------|------------------------------------------------------------------| - |u16 |Number of strings|The number of strings. | - |u32 |Strings size |The size of the strings section, in bytes. | - |String*|Strings data |Multiple strings, where the total size is defined by @Strings size| + |Type |Field |Description | + |------|-----------------|------------------------------------------------------------------| + |u16 |Number of strings|The number of strings. | + |u32 |Strings size |The size of the strings section, in bytes. | + |String|Strings data |Multiple strings, where the total size is defined by @Strings size| # String |Type|Field|Description | @@ -163,11 +163,11 @@ static void add_functions(BytecodeCompilerContext *self) { static void add_extern_functions(BytecodeCompilerContext *self) { /*doc(Bytecode external functions) # External functions layout - |Type |Field |Description | - |------------------|------------------|-----------------------------------------------------------------------------------------| - |u16 |num_extern_func |The number of external functions. | - |u32 |extern_funcs_size |The size of the external functions section, in bytes. | - |External function*|External functions|Multiple external functions, where the number of functions is defined by @num_extern_func| + |Type |Field |Description | + |-----------------|------------------|-----------------------------------------------------------------------------------------| + |u16 |num_extern_func |The number of external functions. | + |u32 |extern_funcs_size |The size of the external functions section, in bytes. | + |External function|External functions|Multiple external functions, where the number of functions is defined by @num_extern_func| # External function |Type|Field |Description | diff --git a/tests/main.c b/tests/main.c index 05725f7..3573f9c 100644 --- a/tests/main.c +++ b/tests/main.c @@ -48,6 +48,7 @@ static CHECK_RESULT int test_hash_map() { } #define FAIL_TEST(name) do { fprintf(stderr, "Test failed: %s\n", (name)); return; } while(0) +#define FAIL_TEST_CLEANUP(name) do { fprintf(stderr, "Test failed: %s\n", (name)); goto cleanup; } while(0) typedef struct { char *filepath; @@ -159,28 +160,30 @@ static void test_load(const char *filepath) { if(amal_program_add_extern_func(&program, create_buffer_view("print_extern", 12), print_extern, 0) != 0) { fprintf(stderr, "Unexpected error (alloc failure)\n"); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } if(amal_program_add_extern_func(&program, create_buffer_view("print_extern_num", 16), print_extern_num, sizeof(i64)) != 0) { fprintf(stderr, "Unexpected error (alloc failure)\n"); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } result = amal_compiler_load_file(&options, &program, filepath); if(result != AMAL_COMPILER_OK) { fprintf(stderr, "Failed to load file %s, result: %d\n", full_path, result); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } result = amal_program_run(&program); if(result != 0) { fprintf(stderr, "Failed to run the program %s, result: %d\n", full_path, result); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } - amal_program_deinit(&program); fprintf(stderr, "Test succeeded as expected: %s\n", full_path); ++num_successful_tests; + + cleanup: + amal_program_deinit(&program); free(full_path); } @@ -203,21 +206,23 @@ static void test_load_error(const char *filepath, const char *expected_error) { if(amal_program_init(&program) != 0) { fprintf(stderr, "Failed to initialize amal program\n"); - FAIL_TEST(expected_data.filepath); + FAIL_TEST_CLEANUP(expected_data.filepath); } if(amal_compiler_load_file(&options, &program, filepath) == AMAL_COMPILER_OK) { fprintf(stderr, "Successfully loaded file when it was expected to fail\n"); - FAIL_TEST(expected_data.filepath); + FAIL_TEST_CLEANUP(expected_data.filepath); } - amal_program_deinit(&program); if(expected_error && !expected_data.got_expected_error) { fprintf(stderr, "Didn't get expected error message:\n%s\n", expected_error); - FAIL_TEST(expected_data.filepath); + FAIL_TEST_CLEANUP(expected_data.filepath); } fprintf(stderr, "Test failed as expected: %s\n", expected_data.filepath); ++num_successful_tests; + + cleanup: + amal_program_deinit(&program); free(expected_data.filepath); if(expected_error) free(expected_data.expected_error); |