Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e1d5def

Browse files
committed
Support reference in method arguments
1 parent 7d71178 commit e1d5def

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

‎classfile.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ class_info_t get_class_info(FILE *class_file)
2727
*/
2828
uint16_t get_number_of_parameters(method_t *method)
2929
{
30-
/* Type descriptors have the length ( + #params + ) + return type */
31-
return strlen(method->descriptor) - 3;
30+
uint16_t num_param = 0;
31+
for (size_t i = 1; method->descriptor[i] != ')'; ++i) {
32+
/* if type is reference, skip class name */
33+
if (method->descriptor[i] == 'L') {
34+
while (method->descriptor[++i] != ';')
35+
;
36+
}
37+
num_param++;
38+
}
39+
return num_param;
3240
}
3341

3442
/**

‎stack.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ void *pop_ref(stack_frame_t *stack)
8686
void pop_to_local(stack_frame_t *stack, local_variable_t *locals)
8787
{
8888
stack_entry_type_t type = stack->store[stack->size - 1].type;
89-
/* convert to integer */
89+
/* push value from stack to locals */
9090
if (type >= STACK_ENTRY_BYTE && type <= STACK_ENTRY_LONG) {
91-
int64_t value = pop_int(stack);
92-
locals->entry.long_value = value;
91+
locals->entry.long_value = pop_int(stack);
9392
locals->type = STACK_ENTRY_LONG;
93+
} else if (type == STACK_ENTRY_REF) {
94+
locals->entry.ptr_value = pop_ref(stack);
95+
locals->type = STACK_ENTRY_REF;
9496
}
9597
}
9698

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /