From 3a75d5bcdc01f4a3af17f53214e7a8288c631463 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 25 Dec 2024 08:31:18 -0600 Subject: [PATCH] allow array references in areturn --- c/execute.c | 2 +- c/frame.c | 3 ++- p/TestArray.java | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 p/TestArray.java diff --git a/c/execute.c b/c/execute.c index f0befe2..c9c8366 100644 --- a/c/execute.c +++ b/c/execute.c @@ -80,7 +80,7 @@ void op_anewarray(struct vm * vm, uint32_t index) void op_areturn(struct vm * vm) { - assert(vm->current_frame->return_type == 'L'); + assert(vm->current_frame->return_type == 'L' || vm->current_frame->return_type == '['); vm_method_return(vm); } diff --git a/c/frame.c b/c/frame.c index 5b4fc2e..2e50dab 100644 --- a/c/frame.c +++ b/c/frame.c @@ -321,7 +321,8 @@ void vm_method_return(struct vm * vm) case 'I': [[fallthrough]]; case 'L': [[fallthrough]]; case 'S': [[fallthrough]]; - case 'Z': + case 'Z': [[fallthrough]]; + case '[': { uint32_t value = operand_stack_pop_u32(old_frame); operand_stack_push_u32(vm->current_frame, value); diff --git a/p/TestArray.java b/p/TestArray.java new file mode 100644 index 0000000..1bf9af2 --- /dev/null +++ b/p/TestArray.java @@ -0,0 +1,17 @@ +package p; + +class TestArray { + static char[] test() { + char[] a = {'a', 'b', 'c', 'd'}; + return a; + } + + static char test2(char[] c) { + return (char)((int)(c[0]) * 2); + } + + public static void main() { + char[] a = test(); + test2(a); + } +}