Name

SPVM::ExchangeAPI - SPVM Exchange API

Description

SPVM::ExchangeAPI is APIs to convert Perl data structures to/from SPVM data structures, and to call SPVM methods from Perl.

Usage

use SPVM ();
my $api = SPVM::api();
my $spvm_int_array = $api->new_int_array([1, 2, 3]);
my $perl_array_ref = $spvm_int_array->to_array;

my $spvm_string = $api->new_string("abc");
my $perl_string = $spvm_string->to_string;

use SPVM 'Int';
my $int_object = Int->new(4);
my $value = $int_object->value;

Fields

env

my $env = $api->env;

Gets the current execution environment.

stack

my $stack = $api->stack;

Gets the current call stack.

Class Methods

my $api = SPVM::ExchangeAPI->new(env => $env, stack => $stack);

Creates a new SPVM::ExchangeAPI object.

Options:

env

An execution environment.

env must be a SPVM::Bulder::Env or SPVM::BlessedObject::Class object of the Env class.

stack

An call stack.

stack must be a SPVM::Bulder::Stack or SPVM::BlessedObject::Class object of the Stack class.

new_byte_array

my $spvm_array = $api->new_byte_array($array);

Converts a Perl array reference specified by the $array to a SPVM byte array and returns the object that converts it to a SPVM::BlessedObject::Array object.

Each element is converted by the conversion of "byte Argument/".

If the $array is undef, returns undef.

If the $array is a reference except for an array reference, an exception is thrown.

If the $array is a SPVM::BlessedObject::Array object, the assignability to the byte[] type is checked. If it is assignable, returns itself, othewise an exception is thrown.

Examples:

my $spvm_array = $api->new_byte_array([1, 2, 3]);

new_byte_array_len

my $spvm_array= $api->new_byte_array_len($length);

Creates a SPVM byte array with the $length and returns the object that converts it to a SPVM::BlessedObject::Array object.

The $length must be greater than or equal to 0. Otherwise an exception is thrown.

Examples:

my $length = 10;
my $spvm_array = $api->new_byte_array_len($length);

new_byte_array_from_bin

my $spvm_array = $api->new_byte_array_from_bin($binary);

Converts a binary date specifed by the $binary to a SPVM byte array and returns the object that converts it to a SPVM::BlessedObject::Array object.

The binary data is interpreted as 8-bit signed integer. The length of the array is calcurated from the $binary.

The $binary must be defined. Otherwise an exception is thrown.

Examples:

my $binary = pack('c*', 97, 98, 99);
my $spvm_array = $api->new_byte_array_from_bin($binary);

my $string = "abc";
my $spvm_array = $api->new_byte_array_from_bin($string);

my $string = "あいう";
my $spvm_array = $api->new_byte_array_from_bin($string);

new_short_array

my $spvm_array = $api->new_short_array($array);

Converts a Perl array reference specified by the $array to a SPVM short array and returns the object that converts it to a SPVM::BlessedObject::Array object. Each element is converted by the conversion of "short Argument/".

If the $array is undef, returns undef.

If the $array is a reference except for an array reference, an exception is thrown.

If the $array is a SPVM::BlessedObject::Array object, the assignability to the short[] type is checked. If it is assignable, returns itself, othewise an exception is thrown.

Examples:

my $spvm_array = $api->new_short_array([1, 2, 3]);

new_short_array_len

my $spvm_array = $api->new_short_array_len($length);

Creates a SPVM short array with the $length and returns the object that converts it to a SPVM::BlessedObject::Array object.

The $length must be greater than or equal to 0. Otherwise an exception is thrown.

Examples:

my $length = 10;
my $spvm_array = $api->new_short_array_len($length);

new_short_array_from_bin

my $spvm_array = $api->new_short_array_from_bin($binary);

Converts a binary date specifed by the $binary to a SPVM short array and returns the object that converts it to a SPVM::BlessedObject::Array object.

The binary data is interpreted as 16-bit signed integer. The length of the array is calcurated from the $binary.

The $binary must be defined. Otherwise an exception is thrown.

The length of the $binary must be divisible by 2. Otherwise an exception is thrown.

Examples:

my $binary = pack('s*', 97, 98, 99);
my $spvm_array = $api->new_short_array_from_bin($binary);

new_int_array

my $spvm_array = $api->new_int_array($array);

Converts a Perl array reference specified by the $array to a SPVM int array and returns the object that converts it to a SPVM::BlessedObject::Array object. Each element is converted by the conversion of "int Argument/".

If the $array is undef, returns undef.

If the $array is a reference except for an array reference, an exception is thrown.

If the $array is a SPVM::BlessedObject::Array object, the assignability to the int[] type is checked. If it is assignable, returns itself, othewise an exception is thrown.

Examples:

my $spvm_array = $api->new_int_array([1, 2, 3]);

new_int_array_len

my $spvm_array = $api->new_int_array_len($length);

Creates a SPVM int array with the $length and returns the object that converts it to a SPVM::BlessedObject::Array object.

The $length must be greater than or equal to 0. Otherwise an exception is thrown.

Examples:

my $length = 10;
my $spvm_array = $api->new_int_array_len($length);

new_int_array_from_bin

my $spvm_array = $api->new_int_array_from_bin($binary);

Converts a binary date specifed by the $binary to a SPVM int array and returns the object that converts it to a SPVM::BlessedObject::Array object.

The binary data is interpreted as 32-bit signed integer. The length of the array is calcurated from the $binary.

The $binary must be defined. Otherwise an exception is thrown.

The length of the $binary must be divisible by 4. Otherwise an exception is thrown.

Examples:

my $binary = pack('l*', 97, 98, 99);
my $spvm_array = $api->new_int_array_from_bin($binary);

new_long_array

my $spvm_array = $api->new_long_array($array);

Converts a Perl array reference specified by the $array to a SPVM long array and returns the object that converts it to a SPVM::BlessedObject::Array object. Each element is converted by the conversion of "long Argument/".

If the $array is undef, returns undef.

If the $array is a reference except for an array reference, an exception is thrown.

If the $array is a SPVM::BlessedObject::Array object, the assignability to the long[] type is checked. If it is assignable, returns itself, othewise an exception is thrown.

Examples:

my $spvm_array = $api->new_long_array([1, 2, 3]);

new_long_array_len

my $spvm_array = $api->new_long_array_len($length);

Creates a SPVM byte array with the $length and returns the object that converts it to a SPVM::BlessedObject::Array object.

The $length must be greater than or equal to 0. Otherwise an exception is thrown.

Examples:

my $length = 10;
my $spvm_array = $api->new_long_array_len($length);

new_long_array_from_bin

my $spvm_array = $api->new_long_array_from_bin($binary);

Converts a binary date specifed by the $binary to a SPVM long array and returns the object that converts it to a SPVM::BlessedObject::Array object.

The binary data is interpreted as 64-bit signed integer. The length of the array is calcurated from the $binary.

The $binary must be defined. Otherwise an exception is thrown.

The length of the $binary must be divisible by 8. Otherwise an exception is thrown.

Examples:

my $binary = pack('q*', 97, 98, 99);
my $spvm_array = $api->new_long_array_from_bin($binary);

new_float_array

my $spvm_array = $api->new_float_array($array);

Converts a Perl array reference specified by the $array to a SPVM float array and returns the object that converts it to a SPVM::BlessedObject::Array object. Each element is converted by the conversion of "float Argument/".

If the $array is undef, returns undef.

If the $array is a reference except for an array reference, an exception is thrown.

If the $array is a SPVM::BlessedObject::Array object, the assignability to the float[] type is checked. If it is assignable, returns itself, othewise an exception is thrown.

Examples:

my $spvm_array = $api->new_float_array([1, 2, 3]);

new_float_array_len

my $spvm_array = $api->new_float_array_len($length);

Creates a SPVM byte array with the $length and returns the object that converts it to a SPVM::BlessedObject::Array object.

The $length must be greater than or equal to 0. Otherwise an exception is thrown.

Examples:

my $length = 10;
my $spvm_array = $api->new_float_array_len($length);

new_float_array_from_bin

my $spvm_array = $api->new_float_array_from_bin($binary);

Converts a binary date specifed by the $binary to a SPVM float array and returns the object that converts it to a SPVM::BlessedObject::Array object.

The binary data is interpreted as 32-bit floating point. The length of the array is calcurated from the $binary.

The $binary must be defined. Otherwise an exception is thrown.

The length of the $binary must be divisible by 4. Otherwise an exception is thrown.

Examples:

my $binary = pack('f*', 97.1, 98.2, 99.3);
my $spvm_array = $api->new_float_array_from_bin($binary);

new_double_array

my $spvm_array = $api->new_double_array($array);

Converts a Perl array reference specified by the $array to a SPVM double array and returns the object that converts it to a SPVM::BlessedObject::Array object. Each element is converted by the conversion of "double Argument/".

If the $array is undef, returns undef.

If the $array is a reference except for an array reference, an exception is thrown.

If the $array is a SPVM::BlessedObject::Array object, the assignability to the double[] type is checked. If it is assignable, returns itself, othewise an exception is thrown.

Examples:

my $spvm_array = $api->new_double_array([1, 2, 3]);

new_double_array_len

my $spvm_array = $api->new_double_array_len($length);

Creates a SPVM byte array with the $length and returns the object that converts it to a SPVM::BlessedObject::Array object.

The $length must be greater than or equal to 0. Otherwise an exception is thrown.

Examples:

my $length = 10;
my $spvm_array = $api->new_double_array_len($length);

new_double_array_from_bin

my $spvm_array = $api->new_double_array_from_bin($binary);

Converts a binary date specifed by the $binary to a SPVM double array and returns the object that converts it to a SPVM::BlessedObject::Array object.

The binary data is interpreted as 64-bit floating point. The length of the array is calcurated from the $binary.

The $binary must be defined. Otherwise an exception is thrown.

The length of the $binary must be divisible by 8. Otherwise an exception is thrown.

Examples:

my $binary = pack('d*', 97.1, 98.2, 99.3);
my $spvm_array = $api->new_double_array_from_bin($binary);

new_string

my $spvm_string = $api->new_string($string);

Converts a Perl scalar specified by the $string to a SPVM string using perlapi SvPV, and returns the object that converts it to a SPVM::BlessedObject::String object.

If the $string is undef, it is converted to SPVM undef.

The $string can't be a reference. If so, an exception is thrown.

If the $string is a SPVM::BlessedObject::String object, the assignability to the string type is checked. If it is assignable, returns itself, othewise an exception is thrown.

Examples:

my $spvm_string = $api->new_string("abc");

my $spvm_string = $api->new_string("あいう");

new_any_object_array

my $byte_array = $api->new_any_object_array(
  [SPVM::Byte->new(1), SPVM::Byte>new(2), SPVM::Byte->new(3)]
);

The alias for the following code using the "new_object_array" method.

my $spvm_array = $api->new_object_array('object[]', $array);

new_options

my $spvm_any_object_array = $api->new_options($options_hash_ref);

Converts a Perl hash reference specified by the $options_hash_ref to a SPVM object[] value, and returns the object that converts it to a SPVM::BlessedObject::Array object.

Each key of the $options_hash_ref is converted to a SPVM::BlessedObject::String object using the "new_string" method.

The value of the $options_hash_ref must be a SPVM::BlessedObject object. Otherwise an exception is thrown.

The $options must be a hash reference. Otherwise an exception is thrown.

Examples:

my $options = $api->new_options({
  x => SPVM::Int->new(1),
  y => SPVM::Int->new(2)
});

new_object_array

my $spvm_object_array = $api->new_object_array($type_name, $array);

Converts a Perl array reference specified by the $array to a SPVM value of the type specified by the $type_name, and returns the object that converts it to a SPVM::BlessedObject::Array object.

If the $array is undef, it is converted to SPVM undef.

If the $array is a SPVM::BlessedObject::Array object, the assignability to the $type is checked. If it is assignable, returns itself, othewise an exception is thrown.

If the $array is an array reference except for an array reference, an exception is thrown.

If the bacic type of the $type_name type is not found, an exception is thrown.

The dimension of the $type_name must be greater than or equal to 1 and less than or equal to 255. Otherwise an exception is thrown.

The assignability of the element to the element type of the $type is checked. If it is not assignable, an exception is thrown.

Examples:

my $object1 = $api->new_int_array([1, 2, 3]);
my $object2 = $api->new_int_array([4, 5, 6]);
my $objects = $api->new_object_array("int[][]", [$object1, $object2]);

new_mulnum_array

my $spvm_mulnum_array = $api->new_mulnum_array($type_name, $array);

Converts a Perl array reference of hash references specified by the $array to a SPVM multi-numeric array specified by the $type_name and returns the object that converts it to a SPVM::BlessedObject::Array object.

Each element of the $array must be a hash reference. Otherwise an exception is thrown.

All fields of the element type of the $type_name must be defined. Otherwise an exception is thrown.

Each value of the hash reference is coverted by the conversion of "byte Argument", "short Argument", "int Argument", "long Argument", "float Argument", "double Argument" corresponding to the numeric type of the the element of the $type.

If the bacic type of the $type_name type is not found, an exception is thrown.

The dimension of the $type_name type must be 1. Otherwise an exception is thrown.

The $array must be an array reference. Otherwise an exception is thrown.

Examples:

my $values = [
  {x => 0, y => 1, z => 2},
  {x => 3, y => 4, z => 5},
  {x => 6, y => 7, z => 8},
];
my $spvm_mulnum_array = $api->new_mulnum_array("TestCase::Point_3i[]", $values);

new_mulnum_array_from_bin

my $spvm_mulnum_array = $api->new_mulnum_array_from_bin($type_name, $binary);

Converts a binary data specified by the $binary to a SPVM multi-numeric array specified by the $type_name and returns the object that converts it to a SPVM::BlessedObject::Array object.

If the bacic type of the $type_name type is not found, an exception is thrown.

The dimension of the $type_name type must be 1. Otherwise an exception is thrown.

The $binary must be an array reference. Otherwise an exception is thrown.

The length of the $binary must be divisible by the length of fields * the byte size of the element type. Otherwise an exception is thrown.

Examples:

# new_mulnum_array_from_bin - byte
{
  my $binary = pack('c9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
  my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3b[]", $binary);
}

# new_mulnum_array_from_bin - short
{
  my $binary = pack('s9', (0, 1, 2), (3, 4, 5), (6, 7, 8);;
  my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3s[]", $binary);
}

# new_mulnum_array_from_bin - int
{
  my $binary = pack('l9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
  my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3i[]", $binary);
}

# new_mulnum_array_from_bin - long
{
  my $binary = pack('q9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
  my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3l[]", $binary);
}

# new_mulnum_array_from_bin - float
{
  my $binary = pack('f9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
  my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3f[]", $binary);
}

# new_mulnum_array_from_bin - double
{
  my $binary = pack('d9', (0, 1, 2), (3, 4, 5), (6, 7, 8));
  my $spvm_mulnum_array = $api->new_mulnum_array_from_bin("TestCase::Point_3d[]", $binary);
}

get_exception

my $message = $api->get_exception();

Returns the exception of the current thread variables as a SPVM::BlessedObject::String object.

If the exception is not set, undef is returned.

set_exception

$api->set_exception($message);

Sets a message given by the $message to the exception of the current thread variables.

The $message is converted to the SPVM string using the "new_string" method.

Examples:

$api->set_exception("Error");
$api->set_exception(undef);

get_memory_blocks_count

my $count = $api->get_memory_blocks_count();

Returns the count of memory blocks on the current execution environment.

Examples:

# First Memory Blocks Count
my $start_memory_blocks_count = $api->get_memory_blocks_count();

# Processing
# ...

# Last Memory Blocks Count
my $end_memory_blocks_count = $api->get_memory_blocks_count();

unless ($end_memory_blocks_count == $start_memory_blocks_count) {
  die"Memroy leak";
}

call_method

my $ret = $api->call_method($invocant, $method_name, @args);

Calls a class method or an instance method. If the $invocant is a string, a class method is called. If the $invocant is a SPVM::BlessedObject::Class, an instance method is called.

The @args are converted by the rule of "Argument Conversion".

The $method_name allows static method name such as Foo::bar.

The return value is converted by the rule of "Return Value Conversion".

Argument Types:

$invocant : string|SPVM::BlessedObject

$method_name : string

@args : the list of the SPVM::BlessedObject object of the argument types of the method (See also "Argument Conversion")

Return Type:

SPVM::BlessedObject of the return type of the method (See also "Return Value Conversion")

Exceptions:

The exception message thrown by SPVM.

The $invocant must be a SPVM::BlessedObject::Class object

The static method call must be valid.

The \"%s\" method in the \"%s\" class is not found.

Too few arguments are passed to the \"%s\" method in the \"%s\" class.

Too many arguments are passed to the \"%s\" method in the \"%s\" class.

The %dth argument of the \"%s\" method in the \"%s\" class must be an interger reference

The %dth argument of the \"%s\" method in the \"%s\" class must be a floating-point reference

The %dth argument of the \"%s\" method in the \"%s\" class must be a scalar reference of a hash reference

The %dth argument of the \"%s\" field in the \"%s\" class is not found

The %dth argument of the \"%s\" method in the \"%s\" class must be a number

The %dth argument of the \"%s\" method in the \"%s\" class must be a SPVM::BlessedObject::String object

The %dth argument of the \"%s\" method in the \"%s\" class must be a SPVM::BlessedObject object

The %dth argument of the \"%s\" method in the \"%s\" class must be assinged to the argument type

The %dth argument of the \"%s\" method in the \"%s\" class must be a SPVM::BlessedObject::Class object

The \"%s\" field in the %dth argument must be defined. The field is defined in the \"%s\" class

The %dth argument of the \"%s\" method in the \"%s\" class must be a hash reference

The object must be assigned to the %s type of the %dth argument of the \"%s\" method in the \"%s\" class

The %dth argument of the \"%s\" method in the \"%s\" class must be a SPVM::BlessedObject::Array object

Examples:

# Class method call
my $obj_int = $api->call_method("Int", "new", 1);

# Instance method call
$api->call_method($obj_int, "set_value", 5);
my $value = $api->call_method($obj_int, "value");

# Call static instance method
$api->call_method($object, "Foo::value");

class

my $class = $api->class($class_name);

Creates a new SPVM::ExchangeAPI::Class object with the $class_name and returns it.

Examples:

my $class = $api->class('Int');
my $spvm_object = $class->new(1);

dump

my $dump = $api->dump($object);

Converts the SPVM object specified by the $object to a dumped string using the dump operator and returns it.

The $object must be a SPVM::BlessedObject object. Otherwise an exception is thrown.

Argument Conversion

The arguments in the "call_method" are converted to the values of SPVM in the following rules.

byte Argument

If the SPVM argument type is byte, the following coversion is performed.

A Perl scalar is converted to a value of the SPVM byte type using the SvIV perlapi and a type cast to int8_t in the C language.

(int8_t)SvIV(perl_scalar)

short Argument

If the SPVM argument type is short, the following coversion is performed.

A Perl scalar is converted to a value of the SPVM short type using the SvIV perlapi and a type cast to int16_t in the C language.

(int16_t)SvIV(perl_scalar)

int Argument

If the SPVM argument type is int, the following coversion is performed.

A Perl scalar is converted to a value of the SPVM int type using the SvIV perlapi and a type cast to int32_t in the C language.

(int32_t)SvIV(perl_scalar)

long Argument

If the SPVM argument type is long, the following coversion is performed.

A Perl scalar is converted to a value of the SPVM long type using the SvIV perlapi and a type cast to int64_t in the C language.

(int64_t)SvIV(perl_scalar)

float Argument

If the SPVM argument type is float, the following coversion is performed.

A Perl scalar is converted to a value of the SPVM float type using the SvNV perlapi and a type cast to float in the C language.

(float)SvNV(perl_scalar)

double Argument

If the SPVM argument type is double, the following coversion is performed.

A Perl scalar is converted to a value of the SPVM double type using the SvNV perlapi and a type cast to double in the C language.

(double)SvNV(perl_scalar)

string Argument

If the SPVM argument type is string, the Perl scalar is converted by the following rule.

If the Perl scalar is undef, it is converted to SPVM undef.

Else if the Perl scalar is a SPVM::BlessedObject::String object, it is converted to the owned SPVM string.

Else if the Perl scalar is a reference, an exception is thrown.

Othwerwise the Perl scalar is converted to a SPVM string using perlapi SvPV.

Examples:

SPVM::MyClass->foo($api->new_string("あいう"));

SPVM::MyClass->foo("あいう");

SPVM::MyClass->foo(undef);

Class Argument

No conversion occurs.

Perl can have SPVM class object itself as a object which inherits SPVM::BlessedObject::Class. This object is created by a contructor such as SPVM::Int->new, SPVM::MyClassClass->new.

If the value is Perl undef, it is converted to SPVM undef.

If class name is different, an exception will occur.

Examples:

# Converts a Perl scalar to class type
my $value = SPVM::Int->new(5);
SPVM::MyClass->foo($value);

Any Object Argument

Perl can have SPVM object itself as a SPVM::BlessedObject object. This object is created by a contructor or functions of exchange API such as SPVM::Int->new, SPVM::MyClassClass->new, $api->new_int_array.

If the value is Perl undef, it is converted to SPVM undef.

Examples:

# Converts a Perl scalar to any object type
my $value = SPVM::Int->new(5);
SPVM::MyClass->foo($value);

Array Argument

byte[] Argument

If the SPVM argument type is byte[], a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of the byte[] type.

Each element is converted to a value of the byte type by the conversion of "byte Argument".

Examples:

# Converts a Perl array reference to byte[] type
SPVM::MyClass->foo([1, 2, 3]);

short[] Argument

If the SPVM argument type is short[], a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of the short[] type.

Each element is converted to a value of the short type by the conversion of "short Argument".

Examples:

# Converts a Perl array reference to short[] type
SPVM::MyClass->foo([1, 2, 3]);

int[] Argument

If the SPVM argument type is int[], a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of the int[] type.

Each element is converted to a value of the int type by the conversion of "int Argument". Perl undef is coverted to SPVM undef.

Examples:

# Converts a Perl array reference to int[] type
SPVM::MyClass->foo([1, 2, 3]);

long[] Argument

If the SPVM argument type is int[], a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of the long[] type.

Each element is converted to a value of the long type by the conversion of "long Argument". Perl undef is coverted to SPVM undef.

Examples:

# Converts a Perl array reference to long[] type
SPVM::MyClass->foo([1, 2, 3]);

float[] Argument

If the SPVM argument type is float[], a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of the float[] type.

Each element is converted to a value of the float type by the conversion of "float Argument". Perl undef is coverted to SPVM undef.

Examples:

# Converts a Perl array reference to float[] type
SPVM::MyClass->foo([1.2, 2.3, 3.4]);

double[] Argument

If the SPVM argument type is double[], a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of the double[] type.

Each element is converted to a value of the double type by the conversion of "double Argument". Perl undef is coverted to SPVM undef.

Examples:

# Converts a Perl array reference to double[] type
SPVM::MyClass->foo([1.2, 2.3, 3.4]);

string[] Argument

If the SPVM argument type is string[], a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of the string[] type.

Each element is converted to string value by the conversion of "string Argument". Perl undef is coverted to SPVM undef.

Examples:

# Converts a Perl array reference to string[] type
SPVM::MyClass->foo(["あい", "うえ", "お"]);

Multi-Numeric Array Argument

If the SPVM argument type is a multi-numeric Array, a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array object of of a multi-numeric type.

Each element which is a hash reference is converted to multi-numeric type by the conversion of "Multi-Numeric Argument". Perl undef is coverted to SPVM undef.

Examples:

# Converts a Perl array reference of a hash reference to Complex_2d[] type
SPVM::MyClass->foo([{re => 1.2, im => 2.3}, {re => 3.4, im => 4.5}]);

Other Array Argument

If the SPVM argument type is a other array type of the above, a Perl value is converted by the following rule.

Perl undef is coverted to SPVM undef.

A Perl array reference is converted to a SPVM::BlessedObject::Array of the corresponding array type.

Multi-Numeric Argument

If the SPVM argument type is a multi-numeric type, a Perl value is converted by the following rule.

Multi-Numeric byte

If the argument type is a multi-numeric byte type, the argument is hash reference is converted to a value of SPVM multi-numeric byte type. If the argument is different from a hash reference, an exception will occur. Each field is converted to a value of the byte type by the conversion of "byte Argument".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl hash reference to MyClassPoint_2b type
SPVM::MyClass->foo({x => 1, y => 2});

Multi-Numeric short Argument

If the argument type is a multi-numeric short type, the argument is hash reference is converted to a value of SPVM multi-numeric short type. If the argument is different from a hash reference, an exception will occur. Each field is converted to a value of the short type by the conversion of "short Argument".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl hash reference to MyClassPoint_2s type
SPVM::MyClass->foo({x => 1, y => 2});

Multi-Numeric int Argument

If the argument type is a multi-numeric int type, the argument is hash reference is converted to a value of SPVM multi-numeric int type. If the argument is different from a hash reference, an exception will occur. Each field is converted to a value of the int type by the conversion of "int Argument".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl hash reference to MyClassPoint_2i type
SPVM::MyClass->foo({x => 1, y => 2});

Multi-Numeric long Argument

If the argument type is a multi-numeric long type, the argument is hash reference is converted to a value of SPVM multi-numeric long type. If the argument is different from a hash reference, an exception will occur. Each field is converted to a value of the long type by the conversion of "long Argument".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl hash reference to MyClassPoint_2l type
SPVM::MyClass->foo({x => 1, y => 2});

Multi-Numeric float Argument

If the argument type is a multi-numeric float type, the argument is hash reference is converted to a value of SPVM multi-numeric float type. If the argument is different from a hash reference, an exception will occur. Each field is converted to a value of the float type by the conversion of "float Argument".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl hash reference to MyClassPoint_2f type
SPVM::MyClass->foo({x => 1.2, y => 2.3});

Multi-Numeric double Argument

If the argument type is a multi-numeric double type, the argument is hash reference is converted to a value of SPVM multi-numeric double type. If the argument is different from a hash reference, an exception will occur. Each field is converted to a value of the double type by the conversion of "double Argument".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl hash reference to MyClassPoint_2d type
SPVM::MyClass->foo({x => 1.2, y => 2.3});

Numeric Reference Argument

byte Reference Argument

If the SPVM argument type is the byte reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM value of the byte reference type.

The value must be a scalar reference of a non-reference scalar. Otherwise an exception will occur.

The value is converted to a SPVM value of the byte type by the conversion of "byte Argument".

The value set by SPVM is converted to a Perl scalar by the conversion of "byte Return Value"

Examples:

# Converts a Perl scalar reference to byte* type
my $value = 23;
SPVM::MyClass->foo(\$value);

short Reference Argument

If the SPVM argument type is the short reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM value of the short reference type.

The value must be a scalar reference of a non-reference scalar. Otherwise an exception will occur.

The value is converted to a SPVM value of the short type by the conversion of "short Argument".

The value set by SPVM is converted to a Perl scalar by the conversion of "short Return Value"

Examples:

# Converts a Perl scalar reference to short* type
my $value = 23;
SPVM::MyClass->foo(\$value);

int Reference Argument

If the SPVM argument type is the int reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM value of the int reference type.

The value must be a scalar reference of a non-reference scalar. Otherwise an exception will occur.

The value is converted to a SPVM value of the int type by the conversion of "int Argument".

The value set by SPVM is converted to a Perl scalar by the conversion of "int Return Value"

Examples:

# Converts a Perl scalar reference to int* type
my $value = 23;
SPVM::MyClass->foo(\$value);

long Reference Argument

If the SPVM argument type is the long reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM value of the long reference type.

The value must be a scalar reference of a non-reference scalar. Otherwise an exception will occur.

The value is converted to a SPVM value of the long type by the conversion of "long Argument".

The value set by SPVM is converted to a Perl scalar by the conversion of "long Return Value"

Examples:

# Converts a Perl scalar reference to long* type
my $value = 23;
SPVM::MyClass->foo(\$value);

float Reference Argument

If the SPVM argument type is the float reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM value of the float reference type.

The value must be a scalar reference of a non-reference scalar. Otherwise an exception will occur.

The value is converted to a SPVM value of the float type by the conversion of "float Argument".

The value set by SPVM is converted to a Perl scalar by the conversion of "float Return Value"

Examples:

# Converts a Perl scalar reference to float* type
my $value = 23.5;
SPVM::MyClass->foo(\$value);

double Reference Argument

If the SPVM argument type is the double reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM value of the double reference type.

The value must be a scalar reference of a non-reference scalar. Otherwise an exception will occur.

The value is converted to a SPVM value of the double type by the conversion of "double Argument".

The value set by SPVM is converted to a Perl scalar by the conversion of "double Return Value"

Examples:

# Converts a Perl scalar reference to double* type
my $value = 23.5;
SPVM::MyClass->foo(\$value);

Multi-Numeric Reference Argument

Multi-Numeric byte Reference Argument

If the SPVM argument type is multi-numeric byte reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM multi-numeric byte reference type.

The reference must be a scalar reference of a hash reference. Otherwise an exception will occur.

Each value of the hash is converted to a value of the byte type by the conversion of "byte Argument".

Each hash value set by SPVM is converted to a Perl number by the conversion of "byte Return Value".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl scalar reference of a hash reference to MyClassPoint_2b* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);

Multi-Numeric short Reference Argument

If the SPVM argument type is multi-numeric short reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM multi-numeric short reference type.

The reference must be a scalar reference of a hash reference. Otherwise an exception will occur.

Each value of the hash is converted to a value of the short type by the conversion of "short Argument".

Each hash value set by SPVM is converted to a Perl number by the conversion of "short Return Value".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl scalar reference of a hash reference to MyClassPoint_2s* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);

Multi-Numeric int Reference Argument

If the SPVM argument type is multi-numeric int reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM multi-numeric int reference type.

The reference must be a scalar reference of a hash reference. Otherwise an exception will occur.

Each value of the hash is converted to a value of the int type by the conversion of "int Argument".

Each hash value set by SPVM is converted to a Perl number by the conversion of "int Return Value".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl scalar reference of a hash reference to SPVM MyClassPoint_2i* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);

Multi-Numeric long Reference Argument

If the SPVM argument type is multi-numeric long reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM multi-numeric long reference type.

The reference must be a scalar reference of a hash reference. Otherwise an exception will occur.

Each value of the hash is converted to a value of the long type by the conversion of "long Argument".

Each hash value set by SPVM is converted to a Perl number by the conversion of "long Return Value".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl scalar reference of a hash reference to SPVM MyClassPoint_2l* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);

Multi-Numeric float Reference Argument

If the SPVM argument type is multi-numeric float reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM multi-numeric float reference type.

The reference must be a scalar reference of a hash reference. Otherwise an exception will occur.

Each value of the hash is converted to a value of the float type by the conversion of "float Argument".

Each hash value set by SPVM is converted to a Perl number by the conversion of "float Return Value".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl scalar reference of a hash reference to SPVM MyClassPoint_2f* type
my $value = {x => 1,2, y => 2.3};
SPVM::MyClass->foo(\$value);

Multi-Numeric double Reference Argument

If the SPVM argument type is multi-numeric double reference type, a Perl value is converted by the following rule.

A Perl reference is converted to a SPVM multi-numeric double reference type.

The reference must be a scalar reference of a hash reference. Otherwise an exception will occur.

Each value of the hash is converted to a value of the double type by the conversion of "double Argument".

Each hash value set by SPVM is converted to a Perl number by the conversion of "double Return Value".

If a field is not specified, an exception will occur.

Examples:

# Converts a Perl scalar reference of a hash reference to SPVM MyClassPoint_2d* type
my $value = {x => 1.2, y => 2.3};
SPVM::MyClass->foo(\$value);

Return Value Conversion

A SPVM return value is converted to a Perl value by the following rule.

void Return Value

If the SPVM return type is the void type, the following conversion is performed.

SPVM void return value is converted to Perl undef.

byte Return Value

If the SPVM return type is the long type, the following conversion is performed.

The SPVM byte value is converted to a Perl scalar using the newSViv perlapi.

short Return Value

If the SPVM return type is the long type, the following conversion is performed.

The SPVM short value is converted to a Perl scalar using the newSViv perlapi.

int Return Value

If the SPVM return type is the int type, the following conversion is performed.

The SPVM float value is converted to a Perl scalar using the newSViv perlapi.

long Return Value

If the SPVM return type is the long type, the following conversion is performed.

The SPVM float value is converted to a Perl scalar using the newSViv perlapi.

float Return Value

If the SPVM return type is the float type, the following conversion is performed.

The SPVM float value is converted to a Perl scalar using the newSVnv perlapi.

double Return Value

If the SPVM return type is the double type, the following conversion is performed.

The SPVM double value is converted to a Perl scalar using the newSVnv perlapi.

string Return Value

If the SPVM return type is the string type, the following conversion is performed.

If SPVM return value is undef, it is converted to Perl undef.

Otherwise a SPVM string is converted to a Perl SPVM::BlessedObject::String object.

Multi-Numeric Return Value

If the SPVM return type is an multi-numeric type, the following conversion is performed.

The SPVM multi-numeric value is converted to Perl hash reference that has the field names of the multi-numeric type as the keys.

Each numeric field is converted by the rules of "byte Return Value", "short Return Value", "int Return Value", "long Return Value", "float Return Value", "double Return Value".

Array Return Value

If the SPVM return type is an array type, the following conversion is performed.

If SPVM return value is undef, it is converted to Perl undef.

Otherwise a SPVM array is converted to a Perl SPVM::BlessedObject::Array object.

Class Return Value

If the SPVM return type is a class type, the following conversion is performed.

If SPVM return value is undef, it is converted to Perl undef.

Otherwise a SPVM object is converted to a Perl SPVM::BlessedObject::Class object.