Skip to content

Commit

Permalink
Add Native::BasicType#get_basic_type_in_version_from method.
Browse files Browse the repository at this point in the history
  [New Features]
    * Add Native::BasicType#get_basic_type_in_version_from method.
  • Loading branch information
yuki-kimoto committed Jan 8, 2025
1 parent c69e22e commit 2f50f73
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[New Features]
* Add get_basic_type_in_version_from basic type native API.

* Add Native::BasicType#get_basic_type_in_version_from method.
0.990036 2024-01-07

[New Features]
Expand Down
37 changes: 37 additions & 0 deletions lib/SPVM/Native/BasicType.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,40 @@ int32_t SPVM__Native__Env__DESTROY(SPVM_ENV* env, SPVM_VALUE* stack) {

return 0;
}

int32_t SPVM__Native__BasicType__get_basic_type_in_version_from(SPVM_ENV* env, SPVM_VALUE* stack) {

int32_t error_id = 0;

void* obj_self = stack[0].oval;

void* self = env->get_pointer(env, stack, obj_self);

void* obj_runtime = env->get_field_object_by_name(env, stack, obj_self, "runtime", &error_id, __func__, FILE_NAME, __LINE__);
if (error_id) { return error_id; }

void* runtime = env->get_pointer(env, stack, obj_runtime);

void* basic_type_in_version_from = env->api->basic_type->get_basic_type_in_version_from(runtime, self);

spvm_warn("%p", basic_type_in_version_from);

void* obj_basic_type_in_version_from = NULL;
if (basic_type_in_version_from) {
void* obj_address_basic_type_in_version_from = env->new_pointer_object_by_name(env, stack, "Address", basic_type_in_version_from, &error_id, __func__, FILE_NAME, __LINE__);
if (error_id) { return error_id; }
stack[0].oval = obj_address_basic_type_in_version_from;
env->call_class_method_by_name(env, stack, "Native::BasicType", "new_with_pointer", 1, &error_id, __func__, FILE_NAME, __LINE__);
if (error_id) { return error_id; }
obj_basic_type_in_version_from = stack[0].oval;
env->set_no_free(env, stack, obj_basic_type_in_version_from, 1);

env->set_field_object_by_name(env, stack, obj_basic_type_in_version_from, "runtime", obj_runtime, &error_id, __func__, FILE_NAME, __LINE__);
if (error_id) { return error_id; }
}

stack[0].oval = obj_basic_type_in_version_from;

return 0;
}

8 changes: 8 additions & 0 deletions lib/SPVM/Native/BasicType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ C<method get_class_vars : L<Native::ClassVar|SPVM::Native::ClassVar>[] ($options
Returns class variables.
=head2 get_basic_type_in_version_from
C<method get_basic_type_in_version_from : L<Native::BasicType|SPVM::Native::BasicType> ();>
Returns the basic typeL<Native::BasicType|SPVM::Native::BasicType> object specified by C<version_from> statement.
If a memory error occurs, an exception is thrown.
=head1 Copyright & License
Copyright (c) 2023 Yuki Kimoto
Expand Down
2 changes: 2 additions & 0 deletions lib/SPVM/Native/BasicType.spvm
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,6 @@ class Native::BasicType : pointer {
return $class_vars;
}

native method get_basic_type_in_version_from : Native::BasicType ();

}
15 changes: 15 additions & 0 deletions t/02_vm/lib/SPVM/TestCase/Module/Native/BasicType.spvm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ class TestCase::Module::Native::BasicType {
}
}

# Extra:get_basic_type_in_version_from
{
my $current_rntime = Native->get_current_runtime;

my $basic_type = $current_rntime->get_basic_type_by_name("Int");

warn $basic_type->get_name;

my $basic_type_in_version_from = $basic_type->get_basic_type_in_version_from;

unless ($basic_type_in_version_from->get_name eq "SPVM") {
return 0;
}
}

return 1;
}

Expand Down

0 comments on commit 2f50f73

Please sign in to comment.