line
stmt
bran
cond
sub
pod
time
code
1
package SPVM::ExchangeAPI;
2
3
278
278
1993
use strict;
278
580
278
9064
4
278
278
1442
use warnings;
278
589
278
6942
5
6
278
278
126582
use SPVM::ExchangeAPI::Class;
278
2588
278
16228
7
278
278
119306
use SPVM::ExchangeAPI::Error;
278
756
278
8858
8
278
278
1777
use Carp 'confess';
278
577
278
12851
9
278
278
1691
use Scalar::Util 'blessed';
278
527
278
884825
10
11
# Fields
12
sub env {
13
754
754
1
2156
my $self = shift;
14
754
50
2672
if (@_) {
15
0
0
$self->{env} = $_[0];
16
0
0
return $self;
17
}
18
else {
19
754
3319
return $self->{env};
20
}
21
}
22
23
sub stack {
24
377
377
1
1502
my $self = shift;
25
377
50
2340
if (@_) {
26
0
0
$self->{stack} = $_[0];
27
0
0
return $self;
28
}
29
else {
30
377
1889
return $self->{stack};
31
}
32
}
33
34
# Class Methods
35
sub new {
36
524
524
0
1411
my $class = shift;
37
38
524
2169
my $self = {
39
@_
40
};
41
42
524
33
3497
bless $self, ref $class || $class;
43
44
524
1648
return $self;
45
}
46
47
# Instance Methods
48
49
sub _parse_type_name {
50
12528
12528
21235
my ($self, $type_name) = @_;
51
52
12528
16683
my $basic_type_name;
53
12528
17379
my $type_dimension = 0;
54
12528
100
73187
if ($type_name =~ /^([a-zA-Z_0-9:]+)((\[\])*)$/) {
55
12514
39725
$basic_type_name = $1;
56
12514
25280
my $type_dimension_part = $2;
57
58
12514
45276
while ($type_dimension_part =~ /\[/g) {
59
12556
35568
$type_dimension++;
60
}
61
}
62
63
12528
32625
return ($basic_type_name, $type_dimension);
64
}
65
66
sub new_object_array {
67
12386
12386
1
35143
my ($self, $type_name, $array) = @_;
68
69
12386
26405
my ($basic_type_name, $type_dimension) = $self->_parse_type_name($type_name);
70
71
12386
100
28766
unless (defined $basic_type_name) {
72
2
255
confess "The type name \$type_name was parsed, but the class name could not be extracted";
73
}
74
75
12384
100
25242
unless ($type_dimension == 1) {
76
2
221
confess "The dimension of the type \$type_name must be 1";
77
}
78
79
12382
16287
my $ret;
80
12382
17645
eval { $ret = $self->_xs_new_object_array($basic_type_name, $array) };
12382
189687
81
12382
100
33003
if ($@) { confess $@ }
8
915
82
83
12374
28113
return $ret;
84
}
85
86
sub new_object_array_len {
87
20
20
1
7232
my ($self, $type_name, $length) = @_;
88
89
20
50
my ($basic_type_name, $type_dimension) = $self->_parse_type_name($type_name);
90
91
20
100
58
unless (defined $basic_type_name) {
92
2
227
confess "The type name \$type_name was parsed, but the class name could not be extracted";
93
}
94
95
18
100
41
unless ($type_dimension == 1) {
96
2
197
confess "The dimension of the type \$type_name must be 1";
97
}
98
99
16
23
my $ret;
100
16
26
eval { $ret = $self->_xs_new_object_array_len($basic_type_name, $length) };
16
410
101
16
100
59
if ($@) { confess $@ }
6
666
102
103
10
28
return $ret;
104
}
105
106
sub new_any_object_array {
107
12346
12346
1
35315
my ($self, $array) = @_;
108
109
12346
20444
my $type_name = 'object[]';
110
111
12346
26816
return $self->new_object_array($type_name, $array);
112
}
113
114
sub new_any_object_array_len {
115
4
4
1
2335
my ($self, $length) = @_;
116
117
4
18
my $type_name = 'object[]';
118
119
4
15
my $array = $self->new_object_array_len($type_name, $length);
120
121
4
18
return $array;
122
}
123
124
sub new_options {
125
11918
11918
1
29425
my ($self, $options) = @_;
126
127
11918
100
32262
unless (ref $options eq 'HASH') {
128
4
469
confess "\$options must be a hash reference";
129
}
130
131
11914
20898
my $array_ref = [];
132
11914
38821
for my $name (keys %$options) {
133
11914
27955
my $obj_name = $self->new_string($name);
134
11914
20979
my $value = $options->{$name};
135
11914
50
25421
if (defined $value) {
136
11914
100
66
77259
unless (blessed $value && $value->isa('SPVM::BlessedObject')) {
137
2
211
confess "The value of \$options must be a SPVM::BlessedObject object";
138
}
139
}
140
11912
37660
push @$array_ref, $obj_name, $value;
141
}
142
143
11912
27361
my $array = $self->new_any_object_array($array_ref);
144
145
11912
73446
return $array;
146
}
147
148
sub new_mulnum_array {
149
38
38
1
31262
my ($self, $type_name, $array) = @_;
150
151
38
110
my ($basic_type_name, $type_dimension) = $self->_parse_type_name($type_name);
152
153
38
100
130
unless (defined $basic_type_name) {
154
2
341
confess "The type name \$type_name was parsed, but the class name could not be extracted";
155
}
156
157
36
100
95
unless ($type_dimension == 1) {
158
2
200
confess "The dimension of the type \$type_name must be 1";
159
}
160
161
34
50
my $ret;
162
34
83
eval { $ret = $self->_xs_new_mulnum_array($basic_type_name, $array) };
34
1345
163
34
100
113
if ($@) { confess $@ }
8
892
164
165
26
118
return $ret;
166
}
167
168
sub new_mulnum_array_len {
169
16
16
1
8196
my ($self, $type_name, $length) = @_;
170
171
16
43
my ($basic_type_name, $type_dimension) = $self->_parse_type_name($type_name);
172
173
16
100
46
unless (defined $basic_type_name) {
174
2
239
confess "The type name \$type_name was parsed, but the class name could not be extracted";
175
}
176
177
14
100
34
unless ($type_dimension == 1) {
178
2
218
confess "The dimension of the type \$type_name must be 1";
179
}
180
181
12
18
my $ret;
182
12
17
eval { $ret = $self->_xs_new_mulnum_array_len($basic_type_name, $length) };
12
349
183
12
100
73
if ($@) { confess $@ }
6
677
184
185
6
24
return $ret;
186
}
187
188
sub new_mulnum_array_from_bin {
189
28
28
1
13528
my ($self, $type_name, $binary) = @_;
190
191
28
74
my ($basic_type_name, $type_dimension) = $self->_parse_type_name($type_name);
192
193
28
100
78
unless (defined $basic_type_name) {
194
2
215
confess "The type name \$type_name was parsed, but the class name could not be extracted";
195
}
196
197
26
100
56
unless ($type_dimension == 1) {
198
2
195
confess "The dimension of the type \$type_name must be 1";
199
}
200
24
31
my $ret;
201
24
39
eval { $ret = $self->_xs_new_mulnum_array_from_bin($basic_type_name, $binary) };
24
663
202
24
100
71
if ($@) { confess $@ }
10
1071
203
204
14
47
return $ret;
205
}
206
207
sub new_muldim_array {
208
24
24
1
4284
my ($self, $type_name, $array) = @_;
209
210
24
58
my ($basic_type_name, $type_dimension) = $self->_parse_type_name($type_name);
211
212
24
100
64
unless (defined $basic_type_name) {
213
2
262
confess "The type name \$type_name was parsed, but the class name could not be extracted";
214
}
215
216
22
100
66
97
unless ($type_dimension >= 2 && $type_dimension <= 255) {
217
2
209
confess "The dimension of the type \$type_name must be greater than or equal to 2 and less than or equal to 255";
218
}
219
220
20
31
my $ret;
221
20
31
eval { $ret = $self->_xs_new_muldim_array($basic_type_name, $type_dimension, $array) };
20
769
222
20
100
63
if ($@) { confess $@ }
6
649
223
224
14
48
return $ret;
225
}
226
227
sub new_muldim_array_len {
228
16
16
1
7023
my ($self, $type_name, $length) = @_;
229
230
16
50
my ($basic_type_name, $type_dimension) = $self->_parse_type_name($type_name);
231
232
16
100
53
unless (defined $basic_type_name) {
233
2
226
confess "The type name \$type_name was parsed, but the class name could not be extracted";
234
}
235
236
14
100
66
92
unless ($type_dimension >= 2 && $type_dimension <= 255) {
237
2
215
confess "The dimension of the type \$type_name must be greater than or equal to 2 and less than or equal to 255";
238
}
239
240
12
22
my $ret;
241
12
25
eval { $ret = $self->_xs_new_muldim_array_len($basic_type_name, $type_dimension, $length) };
12
369
242
12
100
49
if ($@) { confess $@ }
4
431
243
244
8
48
return $ret;
245
}
246
247
sub class {
248
12450
12450
1
29985
my ($self, $basic_type_name) = @_;
249
250
12450
45063
my $class = SPVM::ExchangeAPI::Class->__new(__name => $basic_type_name, __api => $self);
251
252
12450
61801
return $class;
253
}
254
255
sub new_error {
256
6
6
0
3202
my ($self) = @_;
257
258
6
49
my $error = SPVM::ExchangeAPI::Error->new(id => 0);
259
260
6
23
return $error;
261
}
262
263
# other functions is implemented in SPVM.xs
264
265
11990
100
11990
1
44554
sub new_string { my $ret; eval { $ret = &_xs_new_string(@_) }; if ($@) { confess $@ } $ret}
11990
19196
11990
86381
11990
30633
4
755
11986
20989
266
21482
50
21482
0
30841
sub new_address_object { my $ret; eval { $ret = &_xs_new_address_object(@_) }; if ($@) { confess $@ } $ret}
21482
30679
21482
154985
21482
53258
0
0
21482
107408
267
40
100
40
1
19803
sub new_byte_array { my $ret; eval { $ret = &_xs_new_byte_array(@_) }; if ($@) { confess $@ } $ret}
40
91
40
1409
40
154
4
499
36
102
268
14
100
14
1
4380
sub new_byte_array_unsigned { my $ret; eval { $ret = &_xs_new_byte_array_unsigned(@_) }; if ($@) { confess $@ } $ret}
14
24
14
403
14
64
4
451
10
26
269
8
100
8
1
4125
sub new_byte_array_len { my $ret; eval { $ret = &_xs_new_byte_array_len(@_) }; if ($@) { confess $@ } $ret}
8
19
8
227
8
31
2
315
6
23
270
18
100
18
1
8229
sub new_byte_array_from_bin { my $ret; eval { $ret = &_xs_new_byte_array_from_bin(@_) }; if ($@) { confess $@ } $ret}
18
34
18
422
18
96
4
458
14
56
271
32
100
32
1
12385
sub new_short_array { my $ret; eval { $ret = &_xs_new_short_array(@_) }; if ($@) { confess $@ } $ret}
32
64
32
972
32
129
4
445
28
88
272
14
100
14
1
4326
sub new_short_array_unsigned { my $ret; eval { $ret = &_xs_new_short_array_unsigned(@_) }; if ($@) { confess $@ } $ret}
14
22
14
370
14
48
4
473
10
32
273
8
100
8
1
4123
sub new_short_array_len { my $ret; eval { $ret = &_xs_new_short_array_len(@_) }; if ($@) { confess $@ } $ret}
8
30
8
175
8
32
2
239
6
17
274
12
100
12
1
5784
sub new_short_array_from_bin { my $ret; eval { $ret = &_xs_new_short_array_from_bin(@_) }; if ($@) { confess $@ } $ret}
12
20
12
288
12
48
6
687
6
18
275
42
100
42
1
19352
sub new_int_array { my $ret; eval { $ret = &_xs_new_int_array(@_) }; if ($@) { confess $@ } $ret}
42
81
42
1294
42
157
4
537
38
150
276
14
100
14
1
4269
sub new_int_array_unsigned { my $ret; eval { $ret = &_xs_new_int_array_unsigned(@_) }; if ($@) { confess $@ } $ret}
14
22
14
391
14
51
4
469
10
25
277
8
100
8
1
4063
sub new_int_array_len { my $ret; eval { $ret = &_xs_new_int_array_len(@_) }; if ($@) { confess $@ } $ret}
8
15
8
190
8
29
2
261
6
18
278
14
100
14
1
192089
sub new_int_array_from_bin { my $ret; eval { $ret = &_xs_new_int_array_from_bin(@_) }; if ($@) { confess $@ } $ret}
14
35
14
8913
14
67
6
692
8
31
279
32
100
32
1
11821
sub new_long_array { my $ret; eval { $ret = &_xs_new_long_array(@_) }; if ($@) { confess $@ } $ret}
32
63
32
980
32
128
4
463
28
128
280
14
100
14
1
4275
sub new_long_array_unsigned { my $ret; eval { $ret = &_xs_new_long_array_unsigned(@_) }; if ($@) { confess $@ } $ret}
14
24
14
389
14
43
4
465
10
32
281
8
100
8
1
4151
sub new_long_array_len { my $ret; eval { $ret = &_xs_new_long_array_len(@_) }; if ($@) { confess $@ } $ret}
8
17
8
169
8
33
2
252
6
26
282
14
100
14
1
111293
sub new_long_array_from_bin { my $ret; eval { $ret = &_xs_new_long_array_from_bin(@_) }; if ($@) { confess $@ } $ret}
14
36
14
17274
14
76
6
680
8
33
283
32
100
32
1
11986
sub new_double_array { my $ret; eval { $ret = &_xs_new_double_array(@_) }; if ($@) { confess $@ } $ret}
32
61
32
999
32
119
4
465
28
89
284
8
100
8
1
4079
sub new_double_array_len { my $ret; eval { $ret = &_xs_new_double_array_len(@_) }; if ($@) { confess $@ } $ret}
8
16
8
229
8
33
2
240
6
16
285
12
100
12
1
216757
sub new_double_array_from_bin { my $ret; eval { $ret = &_xs_new_double_array_from_bin(@_) }; if ($@) { confess $@ } $ret}
12
30
12
17582
12
89
6
663
6
30
286
34
100
34
1
13454
sub new_float_array { my $ret; eval { $ret = &_xs_new_float_array(@_) }; if ($@) { confess $@ } $ret}
34
72
34
1011
34
124
4
442
30
82
287
8
100
8
1
4167
sub new_float_array_len { my $ret; eval { $ret = &_xs_new_float_array_len(@_) }; if ($@) { confess $@ } $ret}
8
15
8
186
8
31
2
236
6
17
288
14
100
14
1
507182
sub new_float_array_from_bin { my $ret; eval { $ret = &_xs_new_float_array_from_bin(@_) }; if ($@) { confess $@ } $ret}
14
42
14
11642
14
75
6
698
8
35
289
22
100
22
1
12486
sub new_string_array { my $ret; eval { $ret = &_xs_new_string_array(@_) }; if ($@) { confess $@ } $ret}
22
44
22
1313
22
429
4
784
18
65
290
8
100
8
1
4072
sub new_string_array_len { my $ret; eval { $ret = &_xs_new_string_array_len(@_) }; if ($@) { confess $@ } $ret}
8
17
8
178
8
32
2
256
6
15
291
6
100
6
1
1318
sub dump { my $ret; eval { $ret = &_xs_dump(@_) }; if ($@) { confess $@ } $ret}
6
27
6
157
6
25
2
239
4
25
292
6
50
6
1
54
sub get_exception { my $ret; eval { $ret = &_xs_get_exception(@_) }; if ($@) { confess $@ } $ret}
6
14
6
120
6
19
0
0
6
18
293
22
100
22
1
4531
sub set_exception { my $ret; eval { $ret = &_xs_set_exception(@_) }; if ($@) { confess $@ } $ret}
22
46
22
763
22
157
2
231
20
70
294
548
50
548
1
9302
sub get_memory_blocks_count { my $ret; eval { $ret = &_xs_get_memory_blocks_count(@_) }; if ($@) { confess $@ } $ret}
548
1323
548
21062
548
2460
0
0
548
1837
295
142143
100
142143
1
191650
sub call_method { my $ret; eval { $ret = &_xs_call_method(@_) }; if ($@) { confess $@ } $ret}
142143
186761
142143
21841445
142143
600369
156
18893
141987
310293
296
297
1;
298
299
=encoding utf8
300
301
=head1 Name
302
303
SPVM::ExchangeAPI - SPVM Exchange API
304
305
=head1 Description
306
307
C is APIs to convert Perl data structures to/from SPVM data structures, and to call SPVM methods from Perl.
308
309
=head1 Usage
310
311
use SPVM ();
312
my $api = SPVM::api();
313
my $spvm_int_array = $api->new_int_array([1, 2, 3]);
314
my $perl_array_ref = $spvm_int_array->to_array;
315
316
my $spvm_string = $api->new_string("abc");
317
my $perl_string = $spvm_string->to_string;
318
319
use SPVM 'Int';
320
my $int_object = Int->new(4);
321
my $value = $int_object->value;
322
323
=head1 Fields
324
325
=head2 env
326
327
my $env = $api->env;
328
329
Gets the current execution environment.
330
331
=head2 stack
332
333
my $stack = $api->stack;
334
335
Gets the current call stack.
336
337
=head1 Class Methods
338
339
my $api = SPVM::ExchangeAPI->new(env => $env, stack => $stack);
340
341
Creates a new L object.
342
343
Options:
344
345
=over 2
346
347
=item C
348
349
An execution environment.
350
351
C must be a L or L object of the L class.
352
353
=item C
354
355
An call stack.
356
357
C must be a L or L object of the L class.
358
359
=back
360
361
=head2 new_string
362
363
my $spvm_string = $api->new_string($string);
364
365
Converts the Perl scalar $string to a SPVM string using perlapi L, and returns the object that converts it to a L object.
366
367
If $string is undef, returns undef.
368
369
If $string is a L object, returns itself.
370
371
Exceptions:
372
373
$string must be a non-reference scalar or a SPVM::BlessedObject::String object or undef. Otherwise an exception is thrown.
374
375
Examples:
376
377
my $spvm_string = $api->new_string("abc");
378
379
my $spvm_string = $api->new_string("あいう");
380
381
=head2 new_byte_array
382
383
my $spvm_array = $api->new_byte_array($array);
384
385
Converts the Perl array reference $array to a SPVM byte array, and returns the object that converts it to a L object.
386
387
Each element is converted by the conversion of L"byte Type Argument">.
388
389
If $array is undef, returns undef.
390
391
If $array is a L object, returns itself.
392
393
Exceptions:
394
395
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
396
397
$array: If it is a SPVM::BlessedObject::Array object, the type must be the byte[] type. Otherwise an exception is thrown.
398
399
Examples:
400
401
my $spvm_array = $api->new_byte_array([1, 2, 3]);
402
403
=head2 new_byte_array_unsigned
404
405
my $spvm_array = $api->new_byte_array_unsigned($array);
406
407
The same as the L"new_byte_array"> method, but each element is converted by the L perlapi and a type cast to C in the C language.
408
409
(int8_t)(uint8_t)SvUV(perl_scalar);
410
411
=head2 new_byte_array_len
412
413
my $spvm_array= $api->new_byte_array_len($length);
414
415
Creates a SPVM byte array with the length $length, and returns the object that converts it to a L object.
416
417
Exceptions:
418
419
$length must be greater than or equal to 0. Otherwise an exception is thrown.
420
421
Examples:
422
423
my $length = 10;
424
my $spvm_array = $api->new_byte_array_len($length);
425
426
=head2 new_byte_array_from_bin
427
428
my $spvm_array = $api->new_byte_array_from_bin($binary);
429
430
Converts the binary date $binary to a SPVM byte array, and returns the object that converts it to a L object.
431
432
$binary is copied to a SPVM byte array by the C function in the C laugnage. The length of the array is calcurated from $binary.
433
434
Exceptions:
435
436
$binary must be a defined non-reference scalar. Otherwise an exception is thrown.
437
438
Examples:
439
440
my $binary = pack('c*', 97, 98, 99);
441
my $spvm_array = $api->new_byte_array_from_bin($binary);
442
443
my $string = "abc";
444
my $spvm_array = $api->new_byte_array_from_bin($string);
445
446
my $string = "あいう";
447
my $spvm_array = $api->new_byte_array_from_bin($string);
448
449
=head2 new_short_array
450
451
my $spvm_array = $api->new_short_array($array);
452
453
Converts the Perl array reference $array to a SPVM short array, and returns the object that converts it to a L object.
454
455
Each element is converted by the conversion of L"short Type Argument">.
456
457
If $array is undef, returns undef.
458
459
If $array is a L object, returns itself.
460
461
Exceptions:
462
463
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
464
465
$array: If it is a SPVM::BlessedObject::Array object, the type must be the short[] type. Otherwise an exception is thrown.
466
467
Examples:
468
469
my $spvm_array = $api->new_short_array([1, 2, 3]);
470
471
=head2 new_short_array_unsigned
472
473
my $spvm_array = $api->new_short_array_unsigned($array);
474
475
The same as the L"new_short_array"> method, but each element is converted by the L perlapi and a type cast to C in the C language.
476
477
(int16_t)(uint16_t)SvUV(perl_scalar);
478
479
=head2 new_short_array_len
480
481
my $spvm_array = $api->new_short_array_len($length);
482
483
Creates a SPVM short array with the length $length, and returns the object that converts it to a L object.
484
485
Exceptions:
486
487
$length must be greater than or equal to 0. Otherwise an exception is thrown.
488
489
Examples:
490
491
my $length = 10;
492
my $spvm_array = $api->new_short_array_len($length);
493
494
=head2 new_short_array_from_bin
495
496
my $spvm_array = $api->new_short_array_from_bin($binary);
497
498
Converts the binary date $binary to a SPVM short array, and returns the object that converts it to a L object.
499
500
$binary is copied to a SPVM short array by the C function in the C laugnage. The length of the array is calcurated from $binary.
501
502
Exceptions:
503
504
$binary must be a defined non-reference scalar. Otherwise an exception is thrown.
505
506
The length of $binary must be divisible by 2. Otherwise an exception is thrown.
507
508
Examples:
509
510
my $binary = pack('s*', 97, 98, 99);
511
my $spvm_array = $api->new_short_array_from_bin($binary);
512
513
=head2 new_int_array
514
515
my $spvm_array = $api->new_int_array($array);
516
517
Converts the Perl array reference $array to a SPVM int array, and returns the object that converts it to a L object.
518
519
Each element is converted by the conversion of L"int Type Argument">.
520
521
If $array is undef, returns undef.
522
523
If $array is a L object, returns itself.
524
525
Exceptions:
526
527
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
528
529
$array: If it is a SPVM::BlessedObject::Array object, the type must be the int[] type. Otherwise an exception is thrown.
530
531
Examples:
532
533
my $spvm_array = $api->new_int_array([1, 2, 3]);
534
535
=head2 new_int_array_unsigned
536
537
my $spvm_array = $api->new_int_array_unsigned($array);
538
539
The same as the L"new_int_array"> method, but each element is converted by the L perlapi and a type cast to C in the C language.
540
541
(int32_t)(uint32_t)SvUV(perl_scalar);
542
543
=head2 new_int_array_len
544
545
my $spvm_array = $api->new_int_array_len($length);
546
547
Creates a SPVM int array with the length $length, and returns the object that converts it to a L object.
548
549
Exceptions:
550
551
$length must be greater than or equal to 0. Otherwise an exception is thrown.
552
553
Examples:
554
555
my $length = 10;
556
my $spvm_array = $api->new_int_array_len($length);
557
558
=head2 new_int_array_from_bin
559
560
my $spvm_array = $api->new_int_array_from_bin($binary);
561
562
Converts the binary date $binary to a SPVM int array, and returns the object that converts it to a L object.
563
564
$binary is copied to a SPVM int array by the C function in the C laugnage. The length of the array is calcurated from $binary.
565
566
Exceptions:
567
568
$binary must be defined. Otherwise an exception is thrown.
569
570
The length of $binary must be divisible by 4. Otherwise an exception is thrown.
571
572
Examples:
573
574
my $binary = pack('l*', 97, 98, 99);
575
my $spvm_array = $api->new_int_array_from_bin($binary);
576
577
=head2 new_long_array
578
579
my $spvm_array = $api->new_long_array($array);
580
581
Converts the Perl array reference $array to a SPVM long array, and returns the object that converts it to a L object. Each element is converted by the conversion of L"long Type Argument">.
582
583
If $array is undef, returns undef.
584
585
Exceptions:
586
587
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
588
589
$array: If it is a SPVM::BlessedObject::Array object, the type must be the long[] type. Otherwise an exception is thrown.
590
591
Examples:
592
593
my $spvm_array = $api->new_long_array([1, 2, 3]);
594
595
=head2 new_long_array_unsigned
596
597
my $spvm_array = $api->new_long_array_unsigned($array);
598
599
The same as the L"new_long_array"> method, but each element is converted by the L perlapi and a type cast to C in the C language.
600
601
(int64_t)(uint64_t)SvUV(perl_scalar);
602
603
=head2 new_long_array_len
604
605
my $spvm_array = $api->new_long_array_len($length);
606
607
Creates a SPVM long array with the length $length, and returns the object that converts it to a L object.
608
609
Exceptions:
610
611
$length must be greater than or equal to 0. Otherwise an exception is thrown.
612
613
Examples:
614
615
my $length = 10;
616
my $spvm_array = $api->new_long_array_len($length);
617
618
=head2 new_long_array_from_bin
619
620
my $spvm_array = $api->new_long_array_from_bin($binary);
621
622
Converts the binary date $binary to a SPVM long array, and returns the object that converts it to a L object.
623
624
$binary is copied to a SPVM long array by the C function in the C laugnage. The length of the array is calcurated from $binary.
625
626
Exceptions:
627
628
$binary must be defined. Otherwise an exception is thrown.
629
630
The length of $binary must be divisible by 8. Otherwise an exception is thrown.
631
632
Examples:
633
634
my $binary = pack('q*', 97, 98, 99);
635
my $spvm_array = $api->new_long_array_from_bin($binary);
636
637
=head2 new_float_array
638
639
my $spvm_array = $api->new_float_array($array);
640
641
Converts the Perl array reference $array to a SPVM float array, and returns the object that converts it to a L object.
642
643
Each element is converted by the conversion of L"float Type Argument">.
644
645
If $array is undef, returns undef.
646
647
If $array is a L object, returns itself.
648
649
Exceptions:
650
651
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
652
653
$array: If it is a SPVM::BlessedObject::Array object, the type must be the float[] type. Otherwise an exception is thrown.
654
655
Examples:
656
657
my $spvm_array = $api->new_float_array([1, 2, 3]);
658
659
=head2 new_float_array_len
660
661
my $spvm_array = $api->new_float_array_len($length);
662
663
Creates a SPVM float array with the length $length, and returns the object that converts it to a L object.
664
665
Exceptions:
666
667
$length must be greater than or equal to 0. Otherwise an exception is thrown.
668
669
Examples:
670
671
my $length = 10;
672
my $spvm_array = $api->new_float_array_len($length);
673
674
=head2 new_float_array_from_bin
675
676
my $spvm_array = $api->new_float_array_from_bin($binary);
677
678
Converts the binary date $binary to a SPVM float array, and returns the object that converts it to a L object.
679
680
$binary is copied to a SPVM float array by the C function in the C laugnage. The length of the array is calcurated from $binary.
681
682
Exceptions:
683
684
$binary must be defined. Otherwise an exception is thrown.
685
686
The length of $binary must be divisible by 4. Otherwise an exception is thrown.
687
688
Examples:
689
690
my $binary = pack('f*', 97.1, 98.2, 99.3);
691
my $spvm_array = $api->new_float_array_from_bin($binary);
692
693
=head2 new_double_array
694
695
my $spvm_array = $api->new_double_array($array);
696
697
Converts the Perl array reference $array to a SPVM double array, and returns the object that converts it to a L object.
698
699
Each element is converted by the conversion of L"double Type Argument">.
700
701
Exceptions:
702
703
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
704
705
$array: If it is a SPVM::BlessedObject::Array object, the type must be the double[] type. Otherwise an exception is thrown.
706
707
Examples:
708
709
my $spvm_array = $api->new_double_array([1, 2, 3]);
710
711
=head2 new_double_array_len
712
713
my $spvm_array = $api->new_double_array_len($length);
714
715
Creates a SPVM double array with the length $length, and returns the object that converts it to a L object.
716
717
Exceptions:
718
719
$length must be greater than or equal to 0. Otherwise an exception is thrown.
720
721
Examples:
722
723
my $length = 10;
724
my $spvm_array = $api->new_double_array_len($length);
725
726
=head2 new_double_array_from_bin
727
728
my $spvm_array = $api->new_double_array_from_bin($binary);
729
730
Converts the binary date $binary to a SPVM double array, and returns the object that converts it to a L object.
731
732
$binary is copied to a SPVM double array by the C function in the C laugnage. The length of the array is calcurated from $binary.
733
734
Exceptions:
735
736
$binary must be defined. Otherwise an exception is thrown.
737
738
The length of $binary must be divisible by 8. Otherwise an exception is thrown.
739
740
Examples:
741
742
my $binary = pack('d*', 97.1, 98.2, 99.3);
743
my $spvm_array = $api->new_double_array_from_bin($binary);
744
745
=head2 new_string_array
746
747
my $spvm_array = $api->new_string_array($array);
748
749
Converts the Perl array reference $array to a SPVM string array, and returns the object that converts it to a L object. Each element is converted by the L"new_string"> method.
750
751
If $array is undef, returns undef.
752
753
If $array is a L object, returns itself.
754
755
Exceptions:
756
757
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
758
759
$array: If it is a SPVM::BlessedObject::Array object, the type must be the string[] type. Otherwise an exception is thrown.
760
761
Examples:
762
763
my $spvm_array = $api->new_string_array(["foo", "bar", "baz"]);
764
765
my $spvm_array = $api->new_string_array(["あい", "うえ", "お"]);
766
767
=head2 new_string_array_len
768
769
my $spvm_array = $api->new_string_array_len($length);
770
771
Creates a SPVM string array with the length $length, and returns the object that converts it to a L object.
772
773
Exceptions:
774
775
$length must be greater than or equal to 0. Otherwise an exception is thrown.
776
777
Examples:
778
779
my $length = 10;
780
my $spvm_array = $api->new_string_array_len($length);
781
782
=head2 new_object_array
783
784
my $spvm_object_array = $api->new_object_array($type_name, $array);
785
786
Converts the Perl array reference $array to a value of the SPVM object array(1-dimensional) type $type_name, and returns the object that converts it to a L object of $type_name type.
787
788
If $array is undef, it is converted to SPVM undef.
789
790
If $array is a L object, returns itself.
791
792
Exceptions:
793
794
If the type name $type_name was parsed, but the class name could not be extracted, an exception is thrown.
795
796
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
797
798
$array: If it is a SPVM::BlessedObject::Array object, the type must be assignable. Otherwise an exception is thrown.
799
800
If the bacic type of the type $type_name is not found, an exception is thrown.
801
802
The dimension of the type $type_name must be 1. Otherwise an exception is thrown.
803
804
$type_name must be an object array type. Otherwise an exception is thrown.
805
806
Examples:
807
808
my $point1 = SPVM::Point->new;
809
my $point2 = SPVM::Point->new;
810
my $spvm_array = $api->new_object_array("Point[]", [$point1, $point2]);
811
812
=head2 new_object_array_len
813
814
my $spvm_array = $api->new_object_array_len($type_name, $length);
815
816
Creates a SPVM object array(1-dimensional) with the type name $type_name and the length $length, and returns the object that converts it to a L object of $type_name type.
817
818
Exceptions:
819
820
If the type name $type_name was parsed, but the class name could not be extracted, an exception is thrown.
821
822
$length must be greater than or equal to 0. Otherwise an exception is thrown.
823
824
If the bacic type of the type $type_name is not found, an exception is thrown.
825
826
The dimension of the type $type_name must be 1. Otherwise an exception is thrown.
827
828
$type_name must be an object array type. Otherwise an exception is thrown.
829
830
Examples:
831
832
my $length = 10;
833
my $spvm_array = $api->new_object_array("Point[]", $length);
834
835
=head2 new_any_object_array
836
837
my $byte_array = $api->new_any_object_array(
838
[SPVM::Byte->new(1), SPVM::Byte>new(2), SPVM::Byte->new(3)]
839
);
840
841
The alias for the following code using the L"new_object_array"> method.
842
843
my $spvm_array = $api->new_object_array('object[]', $array);
844
845
=head2 new_any_object_array_len
846
847
my $spvm_array = $api->new_any_object_array_len($length);
848
849
Creates a SPVM object array with the length $length, and returns the object that converts it to a L object of $type_name.
850
851
Exceptions:
852
853
$length must be greater than or equal to 0. Otherwise an exception is thrown.
854
855
Examples:
856
857
my $length = 10;
858
my $spvm_array = $api->new_any_object_array("Point[]", $length);
859
860
=head2 new_options
861
862
my $spvm_any_object_array = $api->new_options($options);
863
864
Converts the Perl hash reference $options to a value of the SPVM C type, and returns the object that converts it to a L object.
865
866
Each key of $options is converted to a L object using the L"new_string"> method.
867
868
Exceptions:
869
870
The value of $options must be a L object. Otherwise an exception is thrown.
871
872
$options must be a hash reference. Otherwise an exception is thrown.
873
874
Examples:
875
876
my $options = $api->new_options({
877
x => SPVM::Int->new(1),
878
y => SPVM::Int->new(2)
879
});
880
881
=head2 new_mulnum_array
882
883
my $spvm_mulnum_array = $api->new_mulnum_array($type_name, $array);
884
885
Converts the Perl array reference of a hash references $array to the SPVM multi-numeric array type $type_name, and returns the object that converts it to a L object.
886
887
Each value of the hash reference is coverted by the conversion of L"byte Type Argument">, L"short Type Argument">, L"int Type Argument">, L"long Type Argument">, L"float Type Argument">, L"double Type Argument"> corresponding to the numeric type of the the element of $type.
888
889
Exceptions:
890
891
If the type name $type_name was parsed, but the class name could not be extracted, an exception is thrown.
892
893
All fields of the element type of $type_name must be defined. Otherwise an exception is thrown.
894
895
If the bacic type of the type $type_name is not found, an exception is thrown.
896
897
The dimension of the type $type_name must be 1. Otherwise an exception is thrown.
898
899
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
900
901
$array: If it is a SPVM::BlessedObject::Array object, the type must be assignable. Otherwise an exception is thrown.
902
903
Examples:
904
905
my $values = [
906
{x => 0, y => 1, z => 2},
907
{x => 3, y => 4, z => 5},
908
{x => 6, y => 7, z => 8},
909
];
910
my $spvm_mulnum_array = $api->new_mulnum_array("TestCase::Point_3i[]", $values);
911
912
=head2 new_mulnum_array_len
913
914
my $spvm_array = $api->new_mulnum_array_len($type_name, $length);
915
916
Creates a SPVM object array with the type name $type_name and the length $length, and returns the object that converts it to a L object of $type_name.
917
918
Exceptions:
919
920
$length must be greater than or equal to 0. Otherwise an exception is thrown.
921
922
If the bacic type of the type $type_name is not found, an exception is thrown.
923
924
The dimension of $type_name must be 1. Otherwise an exception is thrown.
925
926
Examples:
927
928
my $length = 10;
929
my $spvm_array = $api->new_mulnum_array("Complex_2d[]", $length);
930
931
=head2 new_mulnum_array_from_bin
932
933
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin($type_name, $binary);
934
935
Converts the binary data $binary to a SPVM multi-numeric array type $type_name, and returns the object that converts it to a L object.
936
937
$binary is copied to a SPVM multi-numeric array by the C function in the C laugnage. The length of the array is calcurated from $binary.
938
939
Exceptions:
940
941
If the bacic type of the type $type_name is not found, an exception is thrown.
942
943
The dimension of the type $type_name must be 1. Otherwise an exception is thrown.
944
945
$binary must be an array reference. Otherwise an exception is thrown.
946
947
The length of $binary must be divisible by the length of fields * the byte size of the element type. Otherwise an exception is thrown.
948
949
Examples:
950
951
# new_mulnum_array_from_bin - byte
952
{
953
my $binary = pack('c9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
954
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3b[]", $binary);
955
}
956
957
# new_mulnum_array_from_bin - short
958
{
959
my $binary = pack('s9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
960
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3s[]", $binary);
961
}
962
963
# new_mulnum_array_from_bin - int
964
{
965
my $binary = pack('l9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
966
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3i[]", $binary);
967
}
968
969
# new_mulnum_array_from_bin - long
970
{
971
my $binary = pack('q9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
972
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3l[]", $binary);
973
}
974
975
# new_mulnum_array_from_bin - float
976
{
977
my $binary = pack('f9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
978
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3f[]", $binary);
979
}
980
981
# new_mulnum_array_from_bin - double
982
{
983
my $binary = pack('d9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
984
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3d[]", $binary);
985
}
986
987
=head2 new_muldim_array
988
989
my $spvm_object_array = $api->new_muldim_array($type_name, $array);
990
991
Converts the Perl array reference $array to a value of the SPVM multi-dimensional array type $type_name, and returns the object that converts it to a L object.
992
993
If $array is undef, it is converted to SPVM undef.
994
995
If $array is a L object, returns itself.
996
997
Exceptions:
998
999
If $array is a reference other than the array reference, an exception is thrown.
1000
1001
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.
1002
1003
$array: If it is a SPVM::BlessedObject::Array object, the type must be assignable. Otherwise an exception is thrown.
1004
1005
If the bacic type of the type $type_name is not found, an exception is thrown.
1006
1007
The dimension of $type_name must be greater than or equal to 2 and less than or equal to 255. Otherwise an exception is thrown.
1008
1009
The assignability of the element to the element type of $type_name is checked. If it is not assignable, an exception is thrown.
1010
1011
Examples:
1012
1013
my $object1 = $api->new_int_array([1, 2, 3]);
1014
my $object2 = $api->new_int_array([4, 5, 6]);
1015
my $objects = $api->new_muldim_array("int[][]", [$object1, $object2]);
1016
1017
=head2 new_muldim_array_len
1018
1019
my $spvm_array = $api->new_muldim_array_len($type_name, $length);
1020
1021
Creates a SPVM multi-dimentional array with the type name $type_name and the length $length, and returns the object that converts it to a L object of $type_name.
1022
1023
Exceptions:
1024
1025
$length must be greater than or equal to 0. Otherwise an exception is thrown.
1026
1027
If the bacic type of the type $type_name is not found, an exception is thrown.
1028
1029
The dimension of $type_name must be greater than or equal to 2 and less than or equal to 255. Otherwise an exception is thrown.
1030
1031
Examples:
1032
1033
my $length = 10;
1034
my $spvm_array = $api->new_muldim_array("int[][]", $length);
1035
1036
=head2 get_exception
1037
1038
my $message = $api->get_exception();
1039
1040
Returns the exception of the current thread variables as a L object.
1041
1042
If the exception is not set, undef is returned.
1043
1044
=head2 set_exception
1045
1046
$api->set_exception($message);
1047
1048
Sets a message given by $message to the exception of the current thread variables.
1049
1050
$message is converted to the SPVM string using the L"new_string"> method.
1051
1052
Exceptions:
1053
1054
Exceptions thrown by the L"new_string"> method are thrown.
1055
1056
Examples:
1057
1058
$api->set_exception("Error");
1059
$api->set_exception(undef);
1060
1061
=head2 get_memory_blocks_count
1062
1063
my $count = $api->get_memory_blocks_count();
1064
1065
Returns the count of the memory blocks allocated by the current call stack.
1066
1067
Examples:
1068
1069
# First Memory Blocks Count
1070
my $start_memory_blocks_count = $api->get_memory_blocks_count();
1071
1072
# Processing
1073
# ...
1074
1075
# Last Memory Blocks Count
1076
my $end_memory_blocks_count = $api->get_memory_blocks_count();
1077
1078
unless ($end_memory_blocks_count == $start_memory_blocks_count) {
1079
die"Memroy leak";
1080
}
1081
1082
=head2 class
1083
1084
my $class = $api->class($basic_type_name);
1085
1086
Creates a new L object with the class name $basic_type_name, and returns it.
1087
1088
Examples:
1089
1090
my $class = $api->class('Int');
1091
my $spvm_object = $class->new(1);
1092
1093
=head2 dump
1094
1095
my $dump = $api->dump($object);
1096
1097
Converts the SPVM object $object to a dumped string using the L operator, and returns it.
1098
1099
Exceptions:
1100
1101
$object must be a SPVM::BlessedObject object. Otherwise an exception is thrown.
1102
1103
=head2 error
1104
1105
my $error = $api->new_error;
1106
1107
Creates a new L object, and returns it.
1108
1109
The error id is set to 0.
1110
1111
=head2 call_method
1112
1113
my $ret = $api->call_method($invocant, $method_name, @args);
1114
1115
my $ret = $api->call_method($invocant, $method_name, @args, $error);
1116
1117
Calls a class method or an instance method. If the invocant $invocant is a string, a class method is called. If the invocant $invocant is a L, an instance method is called.
1118
1119
Each of the arguments @args are converted by the rule of L"Argument Conversion">.
1120
1121
The method name $method_name allows a static method name such as C.
1122
1123
The return value is converted by the rule of L"Return Value Conversion">.
1124
1125
If a L object is passed to the last of the arguments, and if an exception is thrown from a SPVM method, the error code is set to the C field of the object.
1126
1127
Exceptions:
1128
1129
If $invocant is a SPVM::BlessedObject, $invocant must be a SPVM::BlessedObject::Class object. Otherwise an exception is thrown.
1130
1131
The static method call must be valid. Otherwise an exception is thrown.
1132
1133
If the M method in the C class is not found, an exception is thrown.
1134
1135
If too few arguments are passed to the M method in the C class, an exception is thrown.
1136
1137
If too many arguments are passed to the M method in the C class, an exception is thrown.
1138
1139
If the L fails, an exception is thrown.
1140
1141
If the calling method throws an exception, the exception is thrown.
1142
1143
Examples:
1144
1145
# Class method call
1146
my $obj_int = $api->call_method("Int", "new", 1);
1147
1148
# Instance method call
1149
$api->call_method($obj_int, "set_value", 5);
1150
my $value = $api->call_method($obj_int, "value");
1151
1152
# Call static instance method
1153
$api->call_method($object, "Foo::value");
1154
1155
Easy Ways:
1156
1157
Calling class methods can be made easier using the L feature.
1158
1159
use SPVM 'Int';
1160
my $int_object = Int->new(4);
1161
1162
Instance method calls can be made easier using L.
1163
1164
my $value = $int_object->value;
1165
1166
=head1 Argument Conversion
1167
1168
Each argument passed to the L"call_method"> method are converted to a SPVM value according to the SPVM type before it passed to a SPVM method.
1169
1170
=head2 byte Type Argument
1171
1172
A Perl scalar is converted to a value of the SPVM C type by the L perlapi and a type cast to C in the C language.
1173
1174
(int8_t)SvIV(perl_scalar)
1175
1176
Exceptions:
1177
1178
The argument must be a non-reference scalar. Otherwise an exception is thrown.
1179
1180
=head2 short Type Argument
1181
1182
A Perl scalar is converted to a value of the SPVM C type by the L perlapi and a type cast to C in the C language.
1183
1184
(int16_t)SvIV(perl_scalar)
1185
1186
Exceptions:
1187
1188
The argument must be a non-reference scalar. Otherwise an exception is thrown.
1189
1190
=head2 int Type Argument
1191
1192
A Perl scalar is converted to a value of the SPVM C type by the L perlapi and a type cast to C in the C language.
1193
1194
(int32_t)SvIV(perl_scalar)
1195
1196
Exceptions:
1197
1198
The argument must be a non-reference scalar. Otherwise an exception is thrown.
1199
1200
Examples:
1201
1202
my $int_object = SPVM::Int->new(10);
1203
1204
=head2 long Type Argument
1205
1206
A Perl scalar is converted to a value of the SPVM C type by the L perlapi and a type cast to C in the C language.
1207
1208
(int64_t)SvIV(perl_scalar)
1209
1210
Exceptions:
1211
1212
The argument must be a non-reference scalar. Otherwise an exception is thrown.
1213
1214
Examples:
1215
1216
my $long_object = SPVM::Long->new(10);
1217
1218
=head2 float Type Argument
1219
1220
A Perl scalar is converted to a value of the SPVM C type by the L perlapi and a type cast to C in the C language.
1221
1222
(float)SvNV(perl_scalar)
1223
1224
Exceptions:
1225
1226
The argument must be a non-reference scalar. Otherwise an exception is thrown.
1227
1228
Examples:
1229
1230
my $float_object = SPVM::Float->new(10.5);
1231
1232
=head2 double Type Argument
1233
1234
A Perl scalar is converted to a value of the SPVM C type by the L perlapi and a type cast to C in the C language.
1235
1236
(double)SvNV(perl_scalar)
1237
1238
Exceptions:
1239
1240
The argument must be a non-reference scalar. Otherwise an exception is thrown.
1241
1242
Examples:
1243
1244
my $double_object = SPVM::Double->new(10.5);
1245
1246
=head2 string Type Argument
1247
1248
A Perl scalar is converted to a value of the SPVM C type by the L"new_string"> method.
1249
1250
Exceptions:
1251
1252
Exceptions thrown by the L"new_string"> method are thrown.
1253
1254
Examples:
1255
1256
my $substr = SPVM::Fn->substr("abcde", 0, 3);
1257
1258
=head2 Any Object Type Argument
1259
1260
No conversion is performed.
1261
1262
Exceptions:
1263
1264
The argument must be a SPVM::BlessedObject object or undef. Otherwise an exception is thrown.
1265
1266
=head2 Class Type Argument
1267
1268
No conversion is performed.
1269
1270
Exceptions:
1271
1272
The argument must be a SPVM::BlessedObject::Class object of a Z assignable type or undef. Otherwise an exception is thrown.
1273
1274
=head2 Interaface Type Argument
1275
1276
No conversion is performed.
1277
1278
Exceptions:
1279
1280
The argument must be a SPVM::BlessedObject::Class object of a Z assignable type or undef. Otherwise an exception is thrown.
1281
1282
=head2 Multi-Numeric Type Argument
1283
1284
=head3 Multi-Numeric byte
1285
1286
Converts a hash reference containing field names and its values of the multi-numeric byte type to a value of the multi-numeric byte type.
1287
1288
Each field value is coverted by the conversion of L"byte Type Argument">.
1289
1290
Exceptions:
1291
1292
The argument must be a hash reference. Otherwise an exception is thrown.
1293
1294
If a field is not found, an exception is thrown.
1295
1296
Examples:
1297
1298
# Converts a Perl hash reference to MyClassPoint_2b type
1299
SPVM::MyClass->foo({x => 1, y => 2});
1300
1301
=head3 Multi-Numeric short Type Argument
1302
1303
Converts a hash reference containing field names and its values of the multi-numeric short type to a value of the multi-numeric short type.
1304
1305
Each field value is coverted by the conversion of L"short Type Argument">.
1306
1307
Exceptions:
1308
1309
The argument must be a hash reference. Otherwise an exception is thrown.
1310
1311
If a field is not found, an exception is thrown.
1312
1313
Examples:
1314
1315
# Converts a Perl hash reference to MyClassPoint_2s type
1316
SPVM::MyClass->foo({x => 1, y => 2});
1317
1318
=head3 Multi-Numeric int Type Argument
1319
1320
Converts a hash reference containing field names and its values of the multi-numeric int type to a value of the multi-numeric int type.
1321
1322
Each field value is coverted by the conversion of L"int Type Argument">.
1323
1324
Exceptions:
1325
1326
The argument must be a hash reference. Otherwise an exception is thrown.
1327
1328
If a field is not found, an exception is thrown.
1329
1330
Examples:
1331
1332
# Converts a Perl hash reference to MyClassPoint_2i type
1333
SPVM::MyClass->foo({x => 1, y => 2});
1334
1335
=head3 Multi-Numeric long Type Argument
1336
1337
Converts a hash reference containing field names and its values of the multi-numeric long type to a value of the multi-numeric long type.
1338
1339
Each field value is coverted by the conversion of L"long Type Argument">.
1340
1341
Exceptions:
1342
1343
The argument must be a hash reference. Otherwise an exception is thrown.
1344
1345
If a field is not found, an exception is thrown.
1346
1347
Examples:
1348
1349
# Converts a Perl hash reference to MyClassPoint_2l type
1350
SPVM::MyClass->foo({x => 1, y => 2});
1351
1352
=head3 Multi-Numeric float Type Argument
1353
1354
Converts a hash reference containing field names and its values of the multi-numeric float type to a value of the multi-numeric float type.
1355
1356
Each field value is coverted by the conversion of L"float Type Argument">.
1357
1358
Exceptions:
1359
1360
The argument must be a hash reference. Otherwise an exception is thrown.
1361
1362
If a field is not found, an exception is thrown.
1363
1364
Examples:
1365
1366
# Converts a Perl hash reference to MyClassPoint_2f type
1367
SPVM::MyClass->foo({x => 1.2, y => 2.3});
1368
1369
=head3 Multi-Numeric double Type Argument
1370
1371
Converts a hash reference containing field names and its values of the multi-numeric double type to a value of the multi-numeric double type.
1372
1373
Each field value is coverted by the conversion of L"double Type Argument">.
1374
1375
Exceptions:
1376
1377
The argument must be a hash reference. Otherwise an exception is thrown.
1378
1379
If a field is not found, an exception is thrown.
1380
1381
Examples:
1382
1383
# Converts a Perl hash reference to MyClassPoint_2d type
1384
SPVM::MyClass->foo({x => 1.2, y => 2.3});
1385
1386
=head2 Numeric Reference Type Argument
1387
1388
=head3 byte Reference Type Argument
1389
1390
A Perl reference is converted to a value of the SPVM byte reference type.
1391
1392
The referenced value is converted to a value of the SPVM C type by the conversion of L"byte Type Argument">.
1393
1394
After returning from the SPVM method, the referenced value is converted to a Perl scalar by the conversion of L"byte Type Return Value">
1395
1396
Exceptions:
1397
1398
The argument must be a scalar reference. Otherwise an exception is thrown.
1399
1400
Examples:
1401
1402
# Converts a Perl scalar reference to byte* type
1403
my $value = 23;
1404
SPVM::MyClass->foo(\$value);
1405
1406
=head3 short Reference Type Argument
1407
1408
A Perl reference is converted to a value of the SPVM short reference type.
1409
1410
The referenced value is converted to a value of the SPVM C type by the conversion of L"short Type Argument">.
1411
1412
After returning from the SPVM method, the referenced value is converted to a Perl scalar by the conversion of L"short Type Return Value">
1413
1414
Exceptions:
1415
1416
The argument must be a scalar reference. Otherwise an exception is thrown.
1417
1418
Examples:
1419
1420
# Converts a Perl scalar reference to short* type
1421
my $value = 23;
1422
SPVM::MyClass->foo(\$value);
1423
1424
=head3 int Reference Type Argument
1425
1426
A Perl reference is converted to a value of the SPVM int reference type.
1427
1428
The referenced value is converted to a value of the SPVM C type by the conversion of L"int Type Argument">.
1429
1430
After returning from the SPVM method, the referenced value is converted to a Perl scalar by the conversion of L"int Type Return Value">
1431
1432
Exceptions:
1433
1434
The argument must be a scalar reference. Otherwise an exception is thrown.
1435
1436
Examples:
1437
1438
# Converts a Perl scalar reference to int* type
1439
my $value = 23;
1440
SPVM::MyClass->foo(\$value);
1441
1442
=head3 long Reference Type Argument
1443
1444
A Perl reference is converted to a value of the SPVM long reference type.
1445
1446
The referenced value is converted to a value of the SPVM C type by the conversion of L"long Type Argument">.
1447
1448
After returning from the SPVM method, the referenced value is converted to a Perl scalar by the conversion of L"long Type Return Value">
1449
1450
Exceptions:
1451
1452
The argument must be a scalar reference. Otherwise an exception is thrown.
1453
1454
Examples:
1455
1456
# Converts a Perl scalar reference to long* type
1457
my $value = 23;
1458
SPVM::MyClass->foo(\$value);
1459
1460
=head3 float Reference Type Argument
1461
1462
A Perl reference is converted to a value of the SPVM float reference type.
1463
1464
The referenced value is converted to a value of the SPVM C type by the conversion of L"float Type Argument">.
1465
1466
After returning from the SPVM method, the referenced value is converted to a Perl scalar by the conversion of L"float Type Return Value">
1467
1468
Exceptions:
1469
1470
The argument must be a scalar reference. Otherwise an exception is thrown.
1471
1472
Examples:
1473
1474
# Converts a Perl scalar reference to float* type
1475
my $value = 23.5;
1476
SPVM::MyClass->foo(\$value);
1477
1478
=head3 double Reference Type Argument
1479
1480
A Perl reference is converted to a value of the SPVM double reference type.
1481
1482
The referenced value is converted to a value of the SPVM C type by the conversion of L"double Type Argument">.
1483
1484
After returning from the SPVM method, the referenced value is converted to a Perl scalar by the conversion of L"double Type Return Value">
1485
1486
Exceptions:
1487
1488
The argument must be a scalar reference. Otherwise an exception is thrown.
1489
1490
Examples:
1491
1492
# Converts a Perl scalar reference to double* type
1493
my $value = 23.5;
1494
SPVM::MyClass->foo(\$value);
1495
1496
=head2 Multi-Numeric Reference Type Argument
1497
1498
=head3 Multi-Numeric byte Reference Type Argument
1499
1500
A Perl reference is converted to a SPVM multi-numeric C reference type.
1501
1502
Each field is converted to a value of the SPVM C type by the conversion of L"byte Type Argument">.
1503
1504
After returning from the SPVM method, each field value is converted to a Perl scalar by the conversion of L"byte Type Return Value">.
1505
1506
Exceptions:
1507
1508
The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
1509
1510
If a field is not found, an exception is thrown.
1511
1512
Examples:
1513
1514
# Converts a Perl scalar reference to a hash reference to the MyClassPoint_2b* type
1515
my $value = {x => 1, y => 2};
1516
SPVM::MyClass->foo(\$value);
1517
1518
=head3 Multi-Numeric short Reference Type Argument
1519
1520
A Perl reference is converted to a SPVM multi-numeric C reference type.
1521
1522
Each field is converted to a value of the SPVM C type by the conversion of L"short Type Argument">.
1523
1524
After returning from the SPVM method, each field value is converted to a Perl scalar by the conversion of L"short Type Return Value">.
1525
1526
Exceptions:
1527
1528
The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
1529
1530
If a field is not found, an exception is thrown.
1531
1532
Examples:
1533
1534
# Converts a Perl scalar reference to a hash reference to the MyClassPoint_2s* type
1535
my $value = {x => 1, y => 2};
1536
SPVM::MyClass->foo(\$value);
1537
1538
=head3 Multi-Numeric int Reference Type Argument
1539
1540
A Perl reference is converted to a SPVM multi-numeric C reference type.
1541
1542
Each field is converted to a value of the SPVM C type by the conversion of L"int Type Argument">.
1543
1544
After returning from the SPVM method, each field value is converted to a Perl scalar by the conversion of L"int Type Return Value">.
1545
1546
Exceptions:
1547
1548
The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
1549
1550
If a field is not found, an exception is thrown.
1551
1552
Examples:
1553
1554
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2i* type
1555
my $value = {x => 1, y => 2};
1556
SPVM::MyClass->foo(\$value);
1557
1558
=head3 Multi-Numeric long Reference Type Argument
1559
1560
A Perl reference is converted to a SPVM multi-numeric C reference type.
1561
1562
Each field is converted to a value of the SPVM C type by the conversion of L"long Type Argument">.
1563
1564
After returning from the SPVM method, each field value is converted to a Perl scalar by the conversion of L"long Type Return Value">.
1565
1566
Exceptions:
1567
1568
The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
1569
1570
If a field is not found, an exception is thrown.
1571
1572
Examples:
1573
1574
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2l* type
1575
my $value = {x => 1, y => 2};
1576
SPVM::MyClass->foo(\$value);
1577
1578
=head3 Multi-Numeric float Reference Type Argument
1579
1580
A Perl reference is converted to a SPVM multi-numeric C reference type.
1581
1582
Each field is converted to a value of the SPVM C type by the conversion of L"float Type Argument">.
1583
1584
After returning from the SPVM method, each field value is converted to a Perl scalar by the conversion of L"float Type Return Value">.
1585
1586
Exceptions:
1587
1588
The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
1589
1590
If a field is not found, an exception is thrown.
1591
1592
Examples:
1593
1594
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2f* type
1595
my $value = {x => 1,2, y => 2.3};
1596
SPVM::MyClass->foo(\$value);
1597
1598
=head3 Multi-Numeric double Reference Type Argument
1599
1600
A Perl reference is converted to a SPVM multi-numeric C reference type.
1601
1602
Each field is converted to a value of the SPVM C type by the conversion of L"double Type Argument">.
1603
1604
After returning from the SPVM method, each field value is converted to a Perl scalar by the conversion of L"double Type Return Value">.
1605
1606
Exceptions:
1607
1608
The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
1609
1610
If a field is not found, an exception is thrown.
1611
1612
Examples:
1613
1614
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2d* type
1615
my $value = {x => 1.2, y => 2.3};
1616
SPVM::MyClass->foo(\$value);
1617
1618
=head2 Array Type Argument
1619
1620
=head3 byte[] Type Argument
1621
1622
A Perl array reference(or undef) is converted to a value of the C type by the L"new_byte_array"> method.
1623
1624
Exceptions:
1625
1626
Exceptions thrown by the L"new_byte_array"> method are thrown.
1627
1628
Examples:
1629
1630
# Converts a Perl array reference to the byte[] type
1631
SPVM::MyClass->foo([1, 2, 3]);
1632
1633
=head3 short[] Type Argument
1634
1635
A Perl array reference(or undef) is converted to a value of the C type by the L"new_short_array"> method.
1636
1637
Exceptions:
1638
1639
Exceptions thrown by the L"new_short_array"> method are thrown.
1640
1641
Examples:
1642
1643
# Converts a Perl array reference to the short[] type
1644
SPVM::MyClass->foo([1, 2, 3]);
1645
1646
=head3 int[] Type Argument
1647
1648
A Perl array reference(or undef) is converted to a value of the C type by the L"new_int_array"> method.
1649
1650
Exceptions:
1651
1652
Exceptions thrown by the L"new_int_array"> method are thrown.
1653
1654
Examples:
1655
1656
# Converts a Perl array reference to the int[] type
1657
SPVM::MyClass->foo([1, 2, 3]);
1658
1659
=head3 long[] Type Argument
1660
1661
A Perl array reference(or undef) is converted to a value of the C type by the L"new_long_array"> method.
1662
1663
Exceptions:
1664
1665
Exceptions thrown by the L"new_long_array"> method are thrown.
1666
1667
Examples:
1668
1669
# Converts a Perl array reference to the long[] type
1670
SPVM::MyClass->foo([1, 2, 3]);
1671
1672
=head3 float[] Type Argument
1673
1674
A Perl array reference(or undef) is converted to a value of the C type by the L"new_float_array"> method.
1675
1676
Exceptions:
1677
1678
Exceptions thrown by the L"new_float_array"> method are thrown.
1679
1680
Examples:
1681
1682
# Converts a Perl array reference to float[] type
1683
SPVM::MyClass->foo([1.2, 2.3, 3.4]);
1684
1685
=head3 double[] Type Argument
1686
1687
A Perl array reference(or undef) is converted to a value of the C type by the L"new_double_array"> method.
1688
1689
Exceptions:
1690
1691
Exceptions thrown by the L"new_double_array"> method are thrown.
1692
1693
Examples:
1694
1695
# Converts a Perl array reference to the double[] type
1696
SPVM::MyClass->foo([1.2, 2.3, 3.4]);
1697
1698
=head3 string[] Type Argument
1699
1700
A Perl array reference(or undef) is converted to a value of the C type by the L"new_string_array"> method.
1701
1702
Exceptions:
1703
1704
Exceptions thrown by the L"new_string_array"> method are thrown.
1705
1706
Examples:
1707
1708
# Converts a Perl array reference to the string[] type
1709
SPVM::MyClass->foo(["あい", "うえ", "お"]);
1710
1711
=head3 Any Object Array Type Argument
1712
1713
A Perl array reference(or undef) is converted to a value of the C type by the L"new_object_array"> method.
1714
1715
Exceptions:
1716
1717
Exceptions thrown by the L"new_object_array"> method are thrown.
1718
1719
=head3 Class Array Type Argument
1720
1721
A Perl array reference(or undef) is converted to a value of the class type by the L"new_object_array"> method.
1722
1723
Exceptions:
1724
1725
Exceptions thrown by the L"new_object_array"> method are thrown.
1726
1727
=head3 Interface Array Type Argument
1728
1729
A Perl array reference(or undef) is converted to a value of the interface type by the L"new_object_array"> method.
1730
1731
Exceptions:
1732
1733
Exceptions thrown by the L"new_object_array"> method are thrown.
1734
1735
=head3 Multi-Numeric Array Type Argument
1736
1737
A Perl array reference(or undef) is converted to a value of the multi-numeric array type by the L"new_mulnum_array"> method.
1738
1739
Exceptions:
1740
1741
Exceptions thrown by the L"new_mulnum_array"> method are thrown.
1742
1743
Examples:
1744
1745
# Converts a Perl array reference of a hash reference to the Complex_2d[] type
1746
SPVM::MyClass->foo([{re => 1.2, im => 2.3}, {re => 3.4, im => 4.5}]);
1747
1748
=head3 Multi-Dimensional Array Type Argument
1749
1750
A Perl array reference(or undef) is converted to a value of the multi-dimensional array type by the L"new_muldim_array"> method.
1751
1752
Exceptions:
1753
1754
Exceptions thrown by the L"new_muldim_array"> method are thrown.
1755
1756
=head1 Return Value Conversion
1757
1758
A SPVM return value is converted to a Perl value according to the SPVM type.
1759
1760
=head2 void Type Return Value
1761
1762
The SPVM void return value is converted to Perl undef.
1763
1764
=head2 byte Type Return Value
1765
1766
A value of the SPVM byte type is converted to a Perl scalar using the L perlapi.
1767
1768
=head2 short Type Return Value
1769
1770
A value of the SPVM short type is converted to a Perl scalar using the L perlapi.
1771
1772
=head2 int Type Return Value
1773
1774
A value of the SPVM float type is converted to a Perl scalar using the L perlapi.
1775
1776
=head2 long Type Return Value
1777
1778
A value of the SPVM float type is converted to a Perl scalar using the L perlapi.
1779
1780
=head2 float Type Return Value
1781
1782
A value of the SPVM float type is converted to a Perl scalar using the L perlapi.
1783
1784
=head2 double Type Return Value
1785
1786
A value of the SPVM double type is converted to a Perl scalar using the L perlapi.
1787
1788
=head2 string Type Return Value
1789
1790
If the SPVM return value is undef, it is converted to Perl undef.
1791
1792
Otherwise it is converted to a L object.
1793
1794
=head2 Multi-Numeric Type Return Value
1795
1796
The value of the SPVM multi-numeric type is converted to a Perl hash reference that has the field names of the multi-numeric type as the keys.
1797
1798
Each field value is converted by the conversion of L"byte Type Return Value">, L"short Type Return Value">, L"int Type Return Value">, L"long Type Return Value">, L"float Type Return Value">, L"double Type Return Value"> according to the multi-numeric type.
1799
1800
=head2 Any Object Type Return Value
1801
1802
If the SPVM return value is undef, it is converted to Perl undef.
1803
1804
If the type of the return value is an array type, it is converted to a L object.
1805
1806
If the type of the return value is an string type, it is converted to a L object.
1807
1808
Otherwise it is converted to a L object.
1809
1810
=head2 Class Type Return Value
1811
1812
If the SPVM return value is undef, it is converted to Perl undef.
1813
1814
Otherwise it is converted to a L object.
1815
1816
=head2 Interface Type Return Value
1817
1818
If the SPVM return value is undef, it is converted to Perl undef.
1819
1820
Otherwise it is converted to a L object.
1821
1822
=head2 Array Type Return Value
1823
1824
If the SPVM return value is undef, it is converted to Perl undef.
1825
1826
Otherwise it is converted to a L object.
1827
1828
=head1 Copyright & License
1829
1830
Copyright (c) 2023 Yuki Kimoto
1831
1832
MIT License