Skip to content

Commit

Permalink
Pass tests/ok/stack_pass_args_to_define_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
MyNameIsTrez committed Feb 4, 2025
1 parent c2dd762 commit 2bbdbe7
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 1 deletion.
2 changes: 1 addition & 1 deletion grug
Submodule grug updated 1 files
+61 −57 grug.c
1 change: 1 addition & 0 deletions mod_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void game_fn_define_y(char *foo, char *bar);
void game_fn_define_z(char *projectile);
void game_fn_define_a2(char *sprite_path, char *projectile);
void game_fn_define_b2(char *sprite_path, char *projectile);
void game_fn_define_c2(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5, int32_t i6, int32_t i7, int32_t i8, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10);

struct d_on_fns {
void (*a)(void *globals);
Expand Down
77 changes: 77 additions & 0 deletions mod_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,83 @@
"entity_type": ""
}
]
},
"c2": {
"description": "foo",
"fields": [
{
"name": "i1",
"type": "i32"
},
{
"name": "i2",
"type": "i32"
},
{
"name": "i3",
"type": "i32"
},
{
"name": "i4",
"type": "i32"
},
{
"name": "i5",
"type": "i32"
},
{
"name": "i6",
"type": "i32"
},
{
"name": "i7",
"type": "i32"
},
{
"name": "i8",
"type": "i32"
},
{
"name": "f1",
"type": "f32"
},
{
"name": "f2",
"type": "f32"
},
{
"name": "f3",
"type": "f32"
},
{
"name": "f4",
"type": "f32"
},
{
"name": "f5",
"type": "f32"
},
{
"name": "f6",
"type": "f32"
},
{
"name": "f7",
"type": "f32"
},
{
"name": "f8",
"type": "f32"
},
{
"name": "f9",
"type": "f32"
},
{
"name": "f10",
"type": "f32"
}
]
}
},
"game_functions": {
Expand Down
72 changes: 72 additions & 0 deletions tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,45 @@ void game_fn_define_b2(char *sprite_path, char *projectile) {
game_fn_define_b2_sprite_path = sprite_path;
game_fn_define_b2_projectile = projectile;
}
static int32_t game_fn_define_c2_i1;
static int32_t game_fn_define_c2_i2;
static int32_t game_fn_define_c2_i3;
static int32_t game_fn_define_c2_i4;
static int32_t game_fn_define_c2_i5;
static int32_t game_fn_define_c2_i6;
static int32_t game_fn_define_c2_i7;
static int32_t game_fn_define_c2_i8;
static float game_fn_define_c2_f1;
static float game_fn_define_c2_f2;
static float game_fn_define_c2_f3;
static float game_fn_define_c2_f4;
static float game_fn_define_c2_f5;
static float game_fn_define_c2_f6;
static float game_fn_define_c2_f7;
static float game_fn_define_c2_f8;
static float game_fn_define_c2_f9;
static float game_fn_define_c2_f10;
void game_fn_define_c2(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5, int32_t i6, int32_t i7, int32_t i8, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10) {
ASSERT_16_BYTE_STACK_ALIGNED();
game_fn_define_c2_i1 = i1;
game_fn_define_c2_i2 = i2;
game_fn_define_c2_i3 = i3;
game_fn_define_c2_i4 = i4;
game_fn_define_c2_i5 = i5;
game_fn_define_c2_i6 = i6;
game_fn_define_c2_i7 = i7;
game_fn_define_c2_i8 = i8;
game_fn_define_c2_f1 = f1;
game_fn_define_c2_f2 = f2;
game_fn_define_c2_f3 = f3;
game_fn_define_c2_f4 = f4;
game_fn_define_c2_f5 = f5;
game_fn_define_c2_f6 = f6;
game_fn_define_c2_f7 = f7;
game_fn_define_c2_f8 = f8;
game_fn_define_c2_f9 = f9;
game_fn_define_c2_f10 = f10;
}

static void reset_call_counts(void) {
game_fn_nothing_call_count = 0;
Expand Down Expand Up @@ -4654,6 +4693,38 @@ static void ok_stack_16_byte_alignment_midway(void *on_fns, void *g, size_t reso
assert(entity_types == NULL);
}

static void ok_stack_pass_args_to_define_fn(void *on_fns, void *g, size_t resources_size, char **resources, size_t entities_size, char **entities, char **entity_types) {
(void)on_fns;

assert(game_fn_define_c2_i1 == 1);
assert(game_fn_define_c2_i2 == 2);
assert(game_fn_define_c2_i3 == 3);
assert(game_fn_define_c2_i4 == 4);
assert(game_fn_define_c2_i5 == 5);
assert(game_fn_define_c2_i6 == 6);
assert(game_fn_define_c2_i7 == 7);
assert(game_fn_define_c2_i8 == 8);
assert(game_fn_define_c2_f1 == 1.0f);
assert(game_fn_define_c2_f2 == 2.0f);
assert(game_fn_define_c2_f3 == 3.0f);
assert(game_fn_define_c2_f4 == 4.0f);
assert(game_fn_define_c2_f5 == 5.0f);
assert(game_fn_define_c2_f6 == 6.0f);
assert(game_fn_define_c2_f7 == 7.0f);
assert(game_fn_define_c2_f8 == 8.0f);
assert(game_fn_define_c2_f9 == 9.0f);
assert(game_fn_define_c2_f10 == 10.0f);

free(g);

assert(resources_size == 0);
assert(resources == NULL);

assert(entities_size == 0);
assert(entities == NULL);
assert(entity_types == NULL);
}

static void ok_string_and_on_fn(void *on_fns, void *g, size_t resources_size, char **resources, size_t entities_size, char **entities, char **entity_types) {
assert(streq(game_fn_define_p_x, "foo"));

Expand Down Expand Up @@ -5512,6 +5583,7 @@ static void add_ok_tests(void) {
ADD_TEST_OK(same_variable_name_in_different_functions, "e", 8);
ADD_TEST_OK(stack_16_byte_alignment, "d", 8);
ADD_TEST_OK(stack_16_byte_alignment_midway, "d", 8);
ADD_TEST_OK(stack_pass_args_to_define_fn, "c2", 8);
ADD_TEST_OK(string_and_on_fn, "p", 8);
ADD_TEST_OK(string_can_be_passed_to_helper_fn, "d", 8);
ADD_TEST_OK(string_eq_false, "d", 8);
Expand Down
22 changes: 22 additions & 0 deletions tests/ok/stack_pass_args_to_define_fn/input.grug
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define() c2 {
return {
.i1 = 1,
.i2 = 2,
.i3 = 3,
.i4 = 4,
.i5 = 5,
.i6 = 6,
.i7 = 7,
.i8 = 8,
.f1 = 1.0,
.f2 = 2.0,
.f3 = 3.0,
.f4 = 4.0,
.f5 = 5.0,
.f6 = 6.0,
.f7 = 7.0,
.f8 = 8.0,
.f9 = 9.0,
.f10 = 10.0,
}
}
67 changes: 67 additions & 0 deletions tests/ok/stack_pass_args_to_define_fn/input.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
section .data

global define_type
define_type: db "c2", 0

align 8
global globals_size
globals_size: dq 8

align 8
global resources_size
resources_size: dq 0

global entities_size
entities_size: dq 0

section .text

extern game_fn_define_c2

global define
define:
sub rsp, byte 0x8
mov eax, __?float32?__(10.0)
push rax
mov eax, __?float32?__(9.0)
push rax
mov eax, __?float32?__(8.0)
movd xmm7, eax
mov eax, __?float32?__(7.0)
movd xmm6, eax
mov eax, __?float32?__(6.0)
movd xmm5, eax
mov eax, __?float32?__(5.0)
movd xmm4, eax
mov eax, __?float32?__(4.0)
movd xmm3, eax
mov eax, __?float32?__(3.0)
movd xmm2, eax
mov eax, __?float32?__(2.0)
movd xmm1, eax
mov eax, __?float32?__(1.0)
movd xmm0, eax
mov eax, 8
push rax
mov eax, 7
push rax
mov eax, 6
mov r9, rax
mov eax, 5
mov r8, rax
mov eax, 4
mov rcx, rax
mov eax, 3
mov rdx, rax
mov eax, 2
mov rsi, rax
mov eax, 1
mov rdi, rax
call game_fn_define_c2 wrt ..plt
add rsp, byte 0x28
ret

global init_globals
init_globals:
mov rdi[0x0], rsi
ret

0 comments on commit 2bbdbe7

Please sign in to comment.