| 1 | package SPVM::Native::MethodCall; | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | 1; | ||
| 6 | |||
| 7 | =head1 Name | ||
| 8 | |||
| 9 | SPVM::Native::MethodCall - Method Call | ||
| 10 | |||
| 11 | =head1 Description | ||
| 12 | |||
| 13 | The Native::MethodCall class of L<SPVM> has methods to call methods. | ||
| 14 | |||
| 15 | =head1 Usage | ||
| 16 | |||
| 17 | use Native::MethodCall; | ||
| 18 | |||
| 19 | my $class_method_call = Native::MethodCall->new_class_method("Point", "new"); | ||
| 20 | |||
| 21 | my $point = (Point)$class_method_call->call([(object)1, 2]); | ||
| 22 | |||
| 23 | say $point->x; | ||
| 24 | |||
| 25 | say $point->y; | ||
| 26 | |||
| 27 | =head1 Class Methods | ||
| 28 | |||
| 29 | =head2 new_class_method_with_env_stack | ||
| 30 | |||
| 31 | C<static method new_class_method_with_env_stack : L<Native::MethodCall|SPVM::Native::MethodCall> ($env : L<Native::Env|SPVM::Native::Env>, $stack : L<Native::Stack|SPVM::Native::Stack>, $basic_type_name : string, $method_name : string);> | ||
| 32 | Creates a class method call given the runtime environment $env, the runtime stck $stack, the basic type name $basic_type_name and the method name $method_name and returns it. | ||
| 33 | |||
| 34 | If $env is not given, $env is set to the current runtime environment. | ||
| 35 | |||
| 36 | If $stack is not given, $stack is set to the current runtime environment. | ||
| 37 | |||
| 38 | =head2 new_instance_method_static_with_env_stack | ||
| 39 | |||
| 40 | C<static method new_instance_method_static_with_env_stack : L<Native::MethodCall|SPVM::Native::MethodCall> ($env : L<Native::Env|SPVM::Native::Env>, $stack : L<Native::Stack|SPVM::Native::Stack>, $basic_type_name : string, $method_name : string);> | ||
| 41 | |||
| 42 | Creates a instance method call given the runtime environment $env, the runtime stck $stack, the basic type name $basic_type_name and the method name $method_name, and returns it. | ||
| 43 | |||
| 44 | If $env is not given, $env is set to the current runtime environment. | ||
| 45 | |||
| 46 | If $stack is not given, $stack is set to the current runtime environment. | ||
| 47 | |||
| 48 | =head2 new_instance_method_with_env_stack | ||
| 49 | |||
| 50 | C<static method new_instance_method_with_env_stack : L<Native::MethodCall|SPVM::Native::MethodCall> ($env : L<Native::Env|SPVM::Native::Env>, $stack : L<Native::Stack|SPVM::Native::Stack>, $instance : object, $method_name : string);> | ||
| 51 | |||
| 52 | Creates a instance method call given the runtime environment $env, the runtime stck $stack, the instance $instance and the method name $method_name, and returns it. | ||
| 53 | |||
| 54 | If $env is not given, $env is set to the current runtime environment. | ||
| 55 | |||
| 56 | If $stack is not given, $stack is set to the current runtime environment. | ||
| 57 | |||
| 58 | =head2 new_class_method | ||
| 59 | |||
| 60 | C<static method new_class_method : L<Native::MethodCall|SPVM::Native::MethodCall> ($basic_type_name : string, $method_name : string);> | ||
| 61 | |||
| 62 | Calls L</"new_class_method_with_env_stack"> method given $env to undef and $stack to undef, and returns its return value. | ||
| 63 | |||
| 64 | Creates a class method call given the basic type name $basic_type_name and the method name $method_name and returns it. | ||
| 65 | |||
| 66 | =head2 new_instance_method_static | ||
| 67 | |||
| 68 | C<static method new_instance_method_static : L<Native::MethodCall|SPVM::Native::MethodCall> ($basic_type_name : string, $method_name : string);> | ||
| 69 | |||
| 70 | Calls L</"new_instance_method_static_with_env_stack"> method given $env to undef and $stack to undef, and returns its return value. | ||
| 71 | |||
| 72 | =head2 new_instance_method | ||
| 73 | |||
| 74 | C<static method new_instance_method : L<Native::MethodCall|SPVM::Native::MethodCall> ($instance : object, $method_name : string);> | ||
| 75 | |||
| 76 | Calls L</"new_instance_method_with_env_stack"> method given $env to undef and $stack to undef, and returns its return value. | ||
| 77 | |||
| 78 | =head2 call_class_method | ||
| 79 | |||
| 80 | C<static method call_class_method : void ($basic_type_name : string, $method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef);> | ||
| 81 | |||
| 82 | Calls a class method given the basic type name $basic_type_name, the method name $method_name, and the arguments $args. | ||
| 83 | |||
| 84 | =head2 call_instance_method_static | ||
| 85 | |||
| 86 | C<static method call_instance_method_static : object ($basic_type_name : string, $method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef);> | ||
| 87 | |||
| 88 | Calls a instance method given the basic type name $basic_type_name, the method name $method_name, and the arguments $args. | ||
| 89 | |||
| 90 | =head2 call_instance_method | ||
| 91 | |||
| 92 | C<static method call_instance_method : object ($method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef);> | ||
| 93 | |||
| 94 | Calls a instance method given the method name $method_name, and the arguments $args. The first argument in $args must be an instance. | ||
| 95 | |||
| 96 | =head2 new_proto_with_method_name | ||
| 97 | |||
| 98 | C<static method new_proto_with_method_name : object ($proto : object, $method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef)> | ||
| 99 | |||
| 100 | Calls L</"call_class_method"> method given the class name of $proto, the method name $method_name, $args, and $error_id_ref and its return value. | ||
| 101 | |||
| 102 | Exceptions: | ||
| 103 | |||
| 104 | The prototype object $proto must be defined. Otherwise an exception is thrown. | ||
| 105 | |||
| 106 | Exceptions thrown by L</"call_class_method"> method could be thrown. | ||
| 107 | |||
| 108 | =head2 new_proto | ||
| 109 | |||
| 110 | C<static method new_proto : object ($proto : object, $args : object[] = undef, $error_id_ref : int[] = undef);> | ||
| 111 | |||
| 112 | Same as L</"new_proto_with_method_name"> method, but $method_name is set to C<"new">. | ||
| 113 | |||
| 114 | =head1 Instance Methods | ||
| 115 | |||
| 116 | =head2 call | ||
| 117 | |||
| 118 | C<method call : object ($args : object[] = undef, $error_id_ref : int[] = undef);> | ||
| 119 | |||
| 120 | Calls a method with arguments and returns the return value. | ||
| 121 | |||
| 122 | =head2 get_exception | ||
| 123 | |||
| 124 | C<method get_exception : string ();> | ||
| 125 | |||
| 126 | Gets the excetpion on the runtime enviroment and runtime stack owned by this instance. | ||
| 127 | |||
| 128 | =head2 set_exception | ||
| 129 | |||
| 130 | C<method set_exception : void ($exception : string);> | ||
| 131 | |||
| 132 | Sets the excetpion on the runtime enviroment and runtime stack owned by this instance to the string $exception. | ||
| 133 | |||
| 134 | =head2 Arguments | ||
| 135 | |||
| 136 | Each argument must be an object type. The following conversion is perfromed. | ||
| 137 | |||
| 138 | # Numeric types | ||
| 139 | Byte -> byte | ||
| 140 | Short -> short | ||
| 141 | Int -> int | ||
| 142 | Long -> long | ||
| 143 | Float -> float | ||
| 144 | Double -> double | ||
| 145 | |||
| 146 | # Multi-Numeric types | ||
| 147 | byte[] -> multi-numeric byte | ||
| 148 | short[] -> multi-numeric short | ||
| 149 | int[] -> multi-numeric int | ||
| 150 | long[] -> multi-numeric long | ||
| 151 | float[] -> multi-numeric float | ||
| 152 | double[] -> multi-numeric double | ||
| 153 | |||
| 154 | # Numeric reference types | ||
| 155 | byte[] -> byte* | ||
| 156 | short[] -> short* | ||
| 157 | int[] -> int* | ||
| 158 | long[] -> long* | ||
| 159 | float[] -> float* | ||
| 160 | double[] -> double* | ||
| 161 | |||
| 162 | # Multi-Numeric reference types | ||
| 163 | byte[] -> multi-numeric byte reference | ||
| 164 | short[] -> multi-numeric short reference | ||
| 165 | int[] -> multi-numeric int reference | ||
| 166 | long[] -> multi-numeric long reference | ||
| 167 | float[] -> multi-numeric float reference | ||
| 168 | double[] -> multi-numeric double reference | ||
| 169 | |||
| 170 | If the type of an argument cannot be assigned, an exception is thrown. | ||
| 171 | |||
| 172 | =head3 Return Value | ||
| 173 | |||
| 174 | If the type of the return value is a numeric type, it is converted to a numeric object. | ||
| 175 | |||
| 176 | byte -> Byte | ||
| 177 | short -> Short | ||
| 178 | int -> Int | ||
| 179 | long -> Long | ||
| 180 | float -> Float | ||
| 181 | double -> Double | ||
| 182 | |||
| 183 | |||
| 184 | If the type of the return value is a multi-numeric type, it is converted to a numeric array. | ||
| 185 | |||
| 186 | multi-numeric byte type -> byte[] | ||
| 187 | multi-numeric short type -> short[] | ||
| 188 | multi-numeric int type -> int[] | ||
| 189 | multi-numeric long type -> long[] | ||
| 190 | multi-numeric float type -> float[] | ||
| 191 | multi-numeric double type -> double[] | ||
| 192 | |||
| 193 | =head1 Copyright & License | ||
| 194 | |||
| 195 | Copyright (c) 2023 Yuki Kimoto | ||
| 196 | |||
| 197 | MIT License | ||
| 198 |