SPVM::ExchangeAPI(3)
π¦ SPVM::ExchangeAPI β¨ (the SPVM Exchange API, bestie)
okay so this is the manual page for SPVM::ExchangeAPI β officially filed under SPVM::ExchangeAPI(3), in User Contributed Perl Documentation, and it's basically the whole bridge between Perl-land and SPVM-land. grab a snack, we're going through all of it π
πΈ NAME πΈ
SPVM::ExchangeAPI β the SPVM Exchange API. that's it, that's the name, no cap.
π DESCRIPTION π
SPVM::ExchangeAPI is APIs to convert Perl data structures to/from SPVM data structures, and to call SPVM methods from Perl. it's literally the friend-group group chat between the two languages π«Ά
β¨ USAGE β¨
look at her go:
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;
that's the whole vibe. Perl array in, SPVM array out, and back again. iconic β¨
π LOADING SPVM CLASS π
# Load an SPVM class
use SPVM 'SomeClass';
# Load only SPVM module
use SPVM ();
The use statement loads a SPVM class. π
An SPVM class is loaded and is bound to a Perl module.
The bound Perl class name is prefixed with SPVM::. so like, Int shows up on the Perl side dressed as SPVM::Int. slay π
Exceptions:
If the SPVM module cannot be loaded, an exception is thrown. π (rude but fair)
Examples:
use SPVM 'Int';
my $int_object = SPVM::Int->new(3);
my $value = $int_object->value.
(yes, that trailing . is right there in the original, i'm not touching it π)
π«Ά SPVM FUNCTIONS π«Ά
api
my $api = SPVM::api();
Gets the global SPVM::ExchangeAPI object for this Perl interpreter. one api to rule them all, main character energy π
π FIELDS π
env
my $env = $api->env;
Gets the current execution environment. that's the world she's living in π
stack
my $stack = $api->stack;
Gets the current call stack. who called whom, the receipts π
π CLASS METHODS π
my $api = SPVM::ExchangeAPI->new(env => $env, stack => $stack);
Creates a new SPVM::ExchangeAPI object. fresh api, fresh start π¦
Options:
envβ An execution environment.envmust be aSPVM::Bulder::EnvorSPVM::BlessedObject::Classobject ofNative::Envclass.stackβ An call stack.stackmust be aSPVM::Bulder::StackorSPVM::BlessedObject::Classobject ofNative::Stackclass.
new_string
my $spvm_string = $api->new_string($string);
Converts the Perl scalar $string to an SPVM string using perlapi SvPV (perldoc.perl.org/perlapi#SvPV), and returns the object that converts it to a SPVM::BlessedObject::String object. β¨
If $string is undef, returns undef.
If $string is a SPVM::BlessedObject::String object, returns itself. (she's already that girl, no dupe needed π
)
Exceptions:
$string must be a non-reference scalar or an SPVM::BlessedObject::String object or undef. Otherwise an exception is thrown. π¨
Examples:
my $spvm_string = $api->new_string("abc");
my $spvm_string = $api->new_string("γγγ");
new_byte_array
my $spvm_array = $api->new_byte_array($array);
Converts the Perl array reference $array to an 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 Type Argument".
If $array is undef, returns undef.
If $array is a SPVM::BlessedObject::Array object, returns itself.
Exceptions:
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.$array: If it is anSPVM::BlessedObject::Arrayobject, the type must be thebyte[]type. Otherwise an exception is thrown.
Examples:
my $spvm_array = $api->new_byte_array([1, 2, 3]);
new_byte_array_unsigned
my $spvm_array = $api->new_byte_array_unsigned($array);
The same as new_byte_array method, but each element is converted by SvUV perlapi and a type cast to uint8_t in the C language. unsigned era π₯
(int8_t)(uint8_t)SvUV(perl_scalar);
new_byte_array_len
my $spvm_array= $api->new_byte_array_len($length);
Creates an SPVM byte array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object. π
Exceptions:
$length must be greater than or equal to 0. Otherwise an exception is thrown. no negative lengths, we don't do that here π
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 the binary date $binary to an SPVM byte array, and returns the object that converts it to a SPVM::BlessedObject::Array object. π
$binary is copied to an SPVM byte array by the memcpy function in the C laugnage. The length of the array is calcurated from $binary. (yes, "laugnage" and "calcurated", we keep the originals verbatim, i don't make the rules π)
Exceptions:
$binary must be a defined non-reference scalar. 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 the Perl array reference $array to an 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 Type Argument".
If $array is undef, returns undef.
If $array is a SPVM::BlessedObject::Array object, returns itself.
Exceptions:
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.$array: If it is anSPVM::BlessedObject::Arrayobject, the type must be theshort[]type. Otherwise an exception is thrown.
Examples:
my $spvm_array = $api->new_short_array([1, 2, 3]);
new_short_array_unsigned
my $spvm_array = $api->new_short_array_unsigned($array);
The same as new_short_array method, but each element is converted by SvUV perlapi and a type cast to uint16_t in the C language.
(int16_t)(uint16_t)SvUV(perl_scalar);
new_short_array_len
my $spvm_array = $api->new_short_array_len($length);
Creates an SPVM short array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object.
Exceptions:
$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 the binary date $binary to an SPVM short array, and returns the object that converts it to a SPVM::BlessedObject::Array object. π¦
$binary is copied to an SPVM short array by the memcpy function in the C laugnage. The length of the array is calcurated from $binary.
Exceptions:
$binary must be a defined non-reference scalar. Otherwise an exception is thrown.
The length of $binary must be divisible by 2. Otherwise an exception is thrown. β οΈ two-byte alignment check, don't skip it
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 the Perl array reference $array to an 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 Type Argument".
If $array is undef, returns undef.
If $array is a SPVM::BlessedObject::Array object, returns itself.
Exceptions:
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.$array: If it is anSPVM::BlessedObject::Arrayobject, the type must be theint[]type. Otherwise an exception is thrown.
Examples:
my $spvm_array = $api->new_int_array([1, 2, 3]);
new_int_array_unsigned
my $spvm_array = $api->new_int_array_unsigned($array);
The same as new_int_array method, but each element is converted by SvUV perlapi and a type cast to uint32_t in the C language.
(int32_t)(uint32_t)SvUV(perl_scalar);
new_int_array_len
my $spvm_array = $api->new_int_array_len($length);
Creates an SPVM int array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object. π
Exceptions:
$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 the binary date $binary to an SPVM int array, and returns the object that converts it to a SPVM::BlessedObject::Array object. π§
$binary is copied to an SPVM int array by the memcpy function in the C laugnage. The length of the array is calcurated from $binary.
Exceptions:
$binary must be defined. Otherwise an exception is thrown.
The length of $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 the Perl array reference $array to an 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 Type Argument". π
If $array is undef, returns undef.
Exceptions:
$array: If it is a reference, it must be an array reference. Otherwise an exception is thrown.$array: If it is anSPVM::BlessedObject::Arrayobject, the type must be thelong[]type. Otherwise an exception is thrown.
Examples:
my $spvm_array = $api->new_long_array([1, 2, 3]);
new_long_array_unsigned
my $spvm_array = $api->new_long_array_unsigned($array);
The same as new_long_array method, but each element is converted by SvUV perlapi and a type cast to uint64_t in the C language.
(int64_t)(uint64_t)SvUV(perl_scalar);
new_long_array_len
my $spvm_array = $api->new_long_array_len($length);
Creates an SPVM long array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object.
Exceptions:
$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 the binary date $binary to an SPVM long array, and returns the object that converts it to a SPVM::BlessedObject::Array object. π
$binary is copied to an SPVM long array by the memcpy function in the C laugnage. The length of the array is calcurated from $binary.
Exceptions:
$binary must be defined. Otherwise an exception is thrown.
The length of $binary must be divisible by 8. Otherwise an exception is thrown. β οΈ eight, not four, don't @ me
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);
β¦and that's where part 1 runs out, bestie β the new_float_array entry keeps going in part 2, so don't go anywhere πΈ
Okay so new_float_array converts the Perl array reference $array into an SPVM float array, and gives you back the object that converts it to an SPVM::BlessedObject::Array object. π
Each element gets converted by the conversion of "float Type Argument".
If $array is undef, you get undef back. If $array is already an SPVM::BlessedObject::Array object, it returns itself β iconic behavior, honestly.
Exceptions:
$array: if itβs a reference, it must be an array reference. Otherwise an exception gets thrown π.$array: if itβs anSPVM::BlessedObject::Arrayobject, the type must be thefloat[]type. Otherwise an exception gets 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 an SPVM float array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object. π«Ά
Exceptions:
$lengthmust be greater than or equal to0. Otherwise an exception gets 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 the binary data $binary to an SPVM float array, and returns the object that converts it to a SPVM::BlessedObject::Array object.
$binary is copied to an SPVM float array by the "memcpy" function in the C language. The length of the array is calculated from $binary.
Exceptions:
$binarymust be defined. Otherwise an exception gets thrown.- The length of
$binarymust be divisible by4. Otherwise an exception gets 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 the Perl array reference $array to an 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 Type Argument".
Exceptions:
$array: if itβs a reference, it must be an array reference. Otherwise an exception gets thrown.$array: if itβs anSPVM::BlessedObject::Arrayobject, the type must be thedouble[]type. Otherwise an exception gets 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 an SPVM double array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object.
Exceptions:
$lengthmust be greater than or equal to0. Otherwise an exception gets 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 the binary data $binary to an SPVM double array, and returns the object that converts it to a SPVM::BlessedObject::Array object.
$binary is copied to an SPVM double array by the "memcpy" function in the C language. The length of the array is calculated from $binary.
Exceptions:
$binarymust be defined. Otherwise an exception gets thrown.- The length of
$binarymust be divisible by8. Otherwise an exception gets thrown π.
Examples:
my $binary = pack('d*', 97.1, 98.2, 99.3);
my $spvm_array = $api->new_double_array_from_bin($binary);
π new_string_array π
my $spvm_array = $api->new_string_array($array);
Converts the Perl array reference $array to an SPVM string array, and returns the object that converts it to a SPVM::BlessedObject::Array object. Each element is converted by the new_string method.
If $array is undef, it returns undef. If $array is an SPVM::BlessedObject::Array object, it returns itself.
Exceptions:
$array: if itβs a reference, it must be an array reference. Otherwise an exception gets thrown.$array: if itβs anSPVM::BlessedObject::Arrayobject, the type must be thestring[]type. Otherwise an exception gets thrown π.
Examples:
my $spvm_array = $api->new_string_array(["foo", "bar", "baz"]);
my $spvm_array = $api->new_string_array(["γγ", "γγ", "γ"]);
π new_string_array_len π
my $spvm_array = $api->new_string_array_len($length);
Creates an SPVM string array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object.
Exceptions:
$lengthmust be greater than or equal to0. Otherwise an exception gets thrown.
Examples:
my $length = 10;
my $spvm_array = $api->new_string_array_len($length);
π new_object_array π
my $spvm_object_array = $api->new_object_array($type_name, $array);
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 SPVM::BlessedObject::Array object of $type_name type.
If $array is undef, it gets converted to SPVM undef. If $array is an SPVM::BlessedObject::Array object, it returns itself.
Exceptions:
- If the type name
$type_namewas parsed, but the class name could not be extracted, an exception gets thrown. $array: if itβs a reference, it must be an array reference. Otherwise an exception gets thrown.$array: if itβs anSPVM::BlessedObject::Arrayobject, the type must satisfy the type requirement. Otherwise an exception gets thrown.- If the basic type of the type
$type_nameis not found, an exception gets thrown. - The dimension of the type
$type_namemust be1. Otherwise an exception gets thrown. $type_namemust be an object array type. Otherwise an exception gets thrown π.
Examples:
my $point1 = SPVM::Point->new;
my $point2 = SPVM::Point->new;
my $spvm_array = $api->new_object_array("Point[]", [$point1, $point2]);
β new_object_array_len β
my $spvm_array = $api->new_object_array_len($type_name, $length);
Creates an SPVM object array (1-dimensional) with the type name $type_name and the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object of $type_name type.
Exceptions:
- If the type name
$type_namewas parsed, but the class name could not be extracted, an exception gets thrown. $lengthmust be greater than or equal to0. Otherwise an exception gets thrown.- If the basic type of the type
$type_nameis not found, an exception gets thrown. - The dimension of the type
$type_namemust be1. Otherwise an exception gets thrown. $type_namemust be an object array type. Otherwise an exception gets thrown π.
Examples:
my $length = 10;
my $spvm_array = $api->new_object_array("Point[]", $length);
π§ new_any_object_array π§
my $byte_array = $api->new_any_object_array(
[SPVM::Byte->new(1), SPVM::Byte>new(2), SPVM::Byte->new(3)]
);
This is the alias for the following code using the new_object_array method:
my $spvm_array = $api->new_object_array('object[]', $array);
π new_any_object_array_len π
my $spvm_array = $api->new_any_object_array_len($length);
Creates an SPVM object array with the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object of $type_name.
Exceptions:
$lengthmust be greater than or equal to0. Otherwise an exception gets thrown.
Examples:
my $length = 10;
my $spvm_array = $api->new_any_object_array("Point[]", $length);
π
new_options π
my $spvm_any_object_array = $api->new_options($options);
Converts the Perl hash reference $options to a value of the SPVM "object[]" type, and returns the object that converts it to a SPVM::BlessedObject::Array object.
Each key of $options is converted to an SPVM::BlessedObject::String object using the new_string method.
Exceptions:
- The value of
$optionsmust be anSPVM::BlessedObjectobject. Otherwise an exception gets thrown. $optionsmust be a hash reference. Otherwise an exception gets thrown π.
Examples:
my $options = $api->new_options({
x => SPVM::Int->new(1),
y => SPVM::Int->new(2)
});
π₯ new_mulnum_array π₯
my $spvm_mulnum_array = $api->new_mulnum_array($type_name, $array);
Converts the Perl array reference of hash references $array to the SPVM multi-numeric array type $type_name, and returns the object that converts it to a SPVM::BlessedObject::Array object.
Each value of the hash reference is converted by the conversion of "byte Type Argument", "short Type Argument", "int Type Argument", "long Type Argument", "float Type Argument", "double Type Argument" corresponding to the numeric type of the element of $type.
Exceptions:
- If the type name
$type_namewas parsed, but the class name could not be extracted, an exception gets thrown. - All fields of the element type of
$type_namemust be defined. Otherwise an exception gets thrown. - If the basic type of the type
$type_nameis not found, an exception gets thrown. - The dimension of the type
$type_namemust be1. Otherwise an exception gets thrown. $array: if itβs a reference, it must be an array reference. Otherwise an exception gets thrown.$array: if itβs anSPVM::BlessedObject::Arrayobject, the type must satisfy the type requirement. Otherwise an exception gets 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_len π
my $spvm_array = $api->new_mulnum_array_len($type_name, $length);
Creates an SPVM object array with the type name $type_name and the length $length, and returns the object that converts it to a SPVM::BlessedObject::Array object of $type_name.
Exceptions:
$lengthmust be greater than or equal to0. Otherwise an exception gets thrown.- If the basic type of the type
$type_nameis not found, an exception gets thrown. - The dimension of
$type_namemust be1. Otherwise an exception gets thrown π.
Examples:
my $length = 10;
my $spvm_array = $api->new_mulnum_array("Complex_2d[]", $length);
π new_mulnum_array_from_bin π
my $spvm_mulnum_array = $api->new_mulnum_array_from_bin($type_name, $binary);
Converts the binary data $binary to an SPVM multi-numeric array type $type_name, and returns the object that converts it to a SPVM::BlessedObject::Array object.
$binary is copied to an SPVM multi-numeric array by the "memcpy" function in the C language. The length of the array is calculated from $binary.
Exceptions:
- If the basic type of the type
$type_nameis not found, an exception gets thrown. - The dimension of the type
$type_namemust be1. Otherwise an exception gets thrown. $binarymust be an array reference. Otherwise an exception gets thrown π.
The length of $binary has to be divisible by the length of fields Γ the byte size of the element type. Like, evenly divide, no leftover crumbs. If it doesn't? Exception. 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);
}
π new_muldim_array
my $spvm_object_array = $api->new_muldim_array($type_name, $array);
Bestie, this takes your Perl array ref $array and converts it into a value of the SPVM multi-dimensional array type $type_name π« β then hands you back the object that converts it into a SPVM::BlessedObject::Array object.
If $array is undef, it becomes SPVM undef. Simple as that.
If $array is already a SPVM::BlessedObject::Array object, it just returns itself. Iconic, no notes. π
Exceptions:
$array: if it's a reference that isn't an array reference, an exception is thrown.$array: if it's aSPVM::BlessedObject::Arrayobject, the type has to satisfy the type requirement. Otherwise an exception is thrown.- If the bacic type of the type
$type_nameis not found, an exception is thrown. - The dimension of
$type_namemust be greater than or equal to2and less than or equal to255. Otherwise an exception is thrown. - The assignment requirement of the element to the element type of
$type_nameis checked. If it's not satisfied, 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_muldim_array("int[][]", [$object1, $object2]);
π§± new_muldim_array_len
my $spvm_array = $api->new_muldim_array_len($type_name, $length);
Builds you a whole SPVM multi-dimensional array with type name $type_name and length $length π β and returns the object that converts it to a SPVM::BlessedObject::Array object of $type_name.
Exceptions:
$lengthmust be greater than or equal to0. Otherwise an exception is thrown.- If the bacic type of the type
$type_nameis not found, an exception is thrown. - The dimension of
$type_namemust be greater than or equal to2and less than or equal to255. Otherwise an exception is thrown.
Examples:
my $length = 10;
my $spvm_array = $api->new_muldim_array("int[][]", $length);
π± get_exception
my $message = $api->get_exception();
Grabs the exception sitting in the current thread variables and gives it back to you as a SPVM::BlessedObject::String object. If nothing's set? undef. Chill. π
π set_exception
$api->set_exception($message);
Drops the message in $message into the exception slot of the current thread variables. $message gets converted to an SPVM string using the "new_string" method, iykyk.
Exceptions:
- Exceptions thrown by the
"new_string"method are thrown.
Examples:
$api->set_exception("Error");
$api->set_exception(undef);
π get_memory_blocks_count
my $count = $api->get_memory_blocks_count;
Tells you how many memory blocks the current runtime has allocated. Basically a vibe check for your memory π
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";
}
Ngl that die"Memroy leak"; is exactly how it's spelled in the original. Copy it character for character or your leak detector is a different leak detector π
π« class
my $class = $api->class($basic_type_name);
Makes a brand-new SPVM::ExchangeAPI::Class object with the class name $basic_type_name and hands it over π«Ά
Examples:
my $class = $api->class('Int');
my $spvm_object = $class->new(1);
π dump
my $dump = $api->dump($object);
Runs the dump operator on the SPVM object $object, turns it into a dumped string, and returns it. Peek behind the curtain bestie β¨
Exceptions:
$objectmust be aSPVM::BlessedObjectobject. Otherwise an exception is thrown.
π§ error
my $error = $api->new_error;
Creates a fresh SPVM::ExchangeAPI::Error object and returns it. The error id is set to 0. Clean slate energy π
π call_method
my $ret = $api->call_method($invocant, $method_name, @args);
my $ret = $api->call_method($invocant, $method_name, @args, $error);
The main character of this whole page, fr. Calls a class method or an instance method π―
- If the invocant
$invocantis a string β a class method gets called. - If the invocant
$invocantis aSPVM::BlessedObject::Classβ an instance method gets called.
Every one of the arguments in @args goes through the rules in "Argument Conversion".
The method name $method_name also accepts a static method name like "Foo::bar" π
The return value gets converted by the rules in "Return Value Conversion".
And if a SPVM::ExchangeAPI::Error object is passed as the last of the arguments, and an exception gets thrown from an SPVM method, the error code is set to the "code" field of that object. Handy.
Exceptions:
- If
$invocantis anSPVM::BlessedObject,$invocantmust be anSPVM::BlessedObject::Classobject. Otherwise an exception is thrown. - The static method call must be valid. Otherwise an exception is thrown.
- If the M method in the C class is not found, an exception is thrown.
- If too few arguments are passed to the M method in the C class, an exception is thrown.
- If too many arguments are passed to the M method in the C class, an exception is thrown.
- If argument conversion fails, an exception is thrown.
- If the calling method throws an exception, the exception is thrown.
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");
Easy Ways:
Calling class methods can be made easier using SPVM class loading feature π₯
use SPVM 'Int';
my $int_object = Int->new(4);
Instance method calls can be made easier using SPVM::BlessedObject::Class π
my $value = $int_object->value;
π§Ή destroy_runtime_permanent_vars
$api->destroy_runtime_permanent_vars;
Same as Fn#destroy_runtime_permanent_vars method. That's it, that's the whole thing. π§Ό
π·οΈ get_version_string
my $version_string = $api->get_version_string("MyClass");
Same as Fn#get_version_string method. Also that's it. π
π¬ Argument Conversion π¬
Okay so every argument you pass to the "call_method" method gets converted to an SPVM value according to its SPVM type before it ever reaches an SPVM method. Think of it as a little backstage makeover montage π§
π’ byte Type Argument
A Perl scalar becomes a value of the SPVM "byte" type via SvIV (perlapi, https://perldoc.perl.org/perlapi#SvIV) and then a type cast to "int8_t" in the C language.
(int8_t)SvIV(perl_scalar)
Exceptions:
- The argument must be a non-reference scalar. Otherwise an exception is thrown.
π’ short Type Argument
A Perl scalar becomes a value of the SPVM "short" type via SvIV (perlapi, https://perldoc.perl.org/perlapi#SvIV) and then a type cast to "int16_t" in the C language.
(int16_t)SvIV(perl_scalar)
Exceptions:
- The argument must be a non-reference scalar. Otherwise an exception is thrown.
π’ int Type Argument
A Perl scalar becomes a value of the SPVM "int" type via SvIV (perlapi, https://perldoc.perl.org/perlapi#SvIV) and then a type cast to "int32_t" in the C language.
(int32_t)SvIV(perl_scalar)
Exceptions:
- The argument must be a non-reference scalar. Otherwise an exception is thrown.
Examples:
my $int_object = SPVM::Int->new(10);
π’ long Type Argument
A Perl scalar becomes a value of the SPVM "long" type via SvIV (perlapi, https://perldoc.perl.org/perlapi#SvIV) and then a type cast to "int64_t" in the C language.
(int64_t)SvIV(perl_scalar)
Exceptions:
- The argument must be a non-reference scalar. Otherwise an exception is thrown.
Examples:
my $long_object = SPVM::Long->new(10);
π’ float Type Argument
A Perl scalar becomes a value of the SPVM "float" type via SvNV (perlapi, https://perldoc.perl.org/perlapi#SvNV) and then a type cast to "float" in the C language.
(float)SvNV(perl_scalar)
Exceptions:
- The argument must be a non-reference scalar. Otherwise an exception is thrown.
Examples:
my $float_object = SPVM::Float->new(10.5);
π’ double Type Argument
A Perl scalar becomes a value of the SPVM "double" type via SvNV (perlapi, https://perldoc.perl.org/perlapi#SvNV) and then a type cast to "double" in the C language.
(double)SvNV(perl_scalar)
Exceptions:
- The argument must be a non-reference scalar. Otherwise an exception is thrown.
Examples:
my $double_object = SPVM::Double->new(10.5);
π§΅ string Type Argument
A Perl scalar becomes a value of the SPVM "string" type via the "new_string" method β¨
Exceptions:
- Exceptions thrown by the
"new_string"method are thrown.
Examples:
my $substr = SPVM::Fn->substr("abcde", 0, 3);
π¦ Any Object Type Argument
No conversion happens. Zero. None. The argument just walks in as-is πΆββοΈ
Exceptions:
- The argument must be an
SPVM::BlessedObjectobject orundef. Otherwise an exception is thrown.
π Class Type Argument
Again, no conversion performed. Nothing to see here.
Exceptions:
- The argument must be an
SPVM::BlessedObject::Classobject that can be assigned to Z type, orundef. Otherwise an exception is thrown.
π§© Interaface Type Argument
Nope, still no conversion.
Exceptions:
- The argument must be an
SPVM::BlessedObject::Classobject that can be assigned to Z type, orundef. Otherwise an exception is thrown.
π‘ Multi-Numeric Type Argument
Multi-Numeric byte
Takes a hash reference packed with field names and their values for the multi-numeric byte type, and converts it into a value of the multi-numeric byte type π
Each field value gets converted by the conversion of "byte Type Argument".
Exceptions:
The argument has to be a hash reference, bestie. If it's not? An exception gets thrown, no cap. π
And if a field isn't found in there? Yeah, exception again. It's giving strict.
Examples:
# Converts a Perl hash reference to MyClassPoint_2b type
SPVM::MyClass->foo({x => 1, y => 2});
Multi-Numeric short Type Argument
Okay so this one takes a hash reference holding field names and their values of the multi-numeric short type, and converts the whole thing into a value of the multi-numeric short type. β¨
Every single field value gets run through the conversion described in "short Type Argument". One by one, bestie. π
Exceptions β because of course:
- The argument must be a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl hash reference to MyClassPoint_2s type
SPVM::MyClass->foo({x => 1, y => 2});
Multi-Numeric int Type Argument
Same vibe, but int-flavoured: converts a hash reference containing field names and their values of the multi-numeric int type into a value of the multi-numeric int type. π§
Each field value is converted by the conversion of "int Type Argument". Every field, individually, yes.
Exceptions:
- The argument must be a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl hash reference to MyClassPoint_2i type
SPVM::MyClass->foo({x => 1, y => 2});
Multi-Numeric long Type Argument
Now we're doing the long version, lowkey iconic: converts a hash reference containing field names and their values of the multi-numeric long type to a value of the multi-numeric long type. π¦
Each field value is converted by the conversion of "long Type Argument".
Exceptions:
- The argument must be a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl hash reference to MyClassPoint_2l type
SPVM::MyClass->foo({x => 1, y => 2});
Multi-Numeric float Type Argument
Floats, my beloved. π This converts a hash reference containing field names and their values of the multi-numeric float type to a value of the multi-numeric float type.
Each field value is converted by the conversion of "float Type Argument".
Exceptions:
- The argument must be a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl hash reference to MyClassPoint_2f type
SPVM::MyClass->foo({x => 1.2, y => 2.3});
Multi-Numeric double Type Argument
And the double one, ate as always: converts a hash reference containing field names and their values of the multi-numeric double type to a value of the multi-numeric double type. π
Each field value is converted by the conversion of "double Type Argument".
Exceptions:
- The argument must be a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl hash reference to MyClassPoint_2d type
SPVM::MyClass->foo({x => 1.2, y => 2.3});
Numeric Reference Type Argument
Now we're in reference territory β pointers, bestie, by reference energy. π
byte Reference Type Argument
A Perl reference gets converted to a value of the SPVM byte reference type. β¨
The value being pointed at gets converted to a value of the SPVM "byte" type via the conversion of "byte Type Argument".
Then, after returning from the SPVM method, that referenced value gets converted to a Perl scalar via the conversion of "byte Type Return Value". It goes both ways, it's giving main character energy. π
Exceptions:
- The argument must be a scalar reference. Otherwise an exception is thrown.
Examples:
# Converts a Perl scalar reference to byte* type
my $value = 23;
SPVM::MyClass->foo(\$value);
short Reference Type Argument
A Perl reference gets converted to a value of the SPVM short reference type. π
The referenced value gets converted to a value of the SPVM "short" type via the conversion of "short Type Argument".
After returning from the SPVM method, the referenced value gets converted to a Perl scalar via the conversion of "short Type Return Value".
Exceptions:
- The argument must be a scalar reference. Otherwise an exception is thrown.
Examples:
# Converts a Perl scalar reference to short* type
my $value = 23;
SPVM::MyClass->foo(\$value);
int Reference Type Argument
A Perl reference gets converted to a value of the SPVM int reference type. π₯
The referenced value gets converted to a value of the SPVM "int" type via the conversion of "int Type Argument".
After returning from the SPVM method, the referenced value gets converted to a Perl scalar via the conversion of "int Type Return Value".
Exceptions:
- The argument must be a scalar reference. Otherwise an exception is thrown.
Examples:
# Converts a Perl scalar reference to int* type
my $value = 23;
SPVM::MyClass->foo(\$value);
long Reference Type Argument
A Perl reference gets converted to a value of the SPVM long reference type. πΈ
The referenced value gets converted to a value of the SPVM "long" type via the conversion of "long Type Argument".
After returning from the SPVM method, the referenced value gets converted to a Perl scalar via the conversion of "long Type Return Value".
Exceptions:
- The argument must be a scalar reference. Otherwise an exception is thrown.
Examples:
# Converts a Perl scalar reference to long* type
my $value = 23;
SPVM::MyClass->foo(\$value);
float Reference Type Argument
A Perl reference gets converted to a value of the SPVM float reference type. π«Ά
The referenced value gets converted to a value of the SPVM "float" type via the conversion of "float Type Argument".
After returning from the SPVM method, the referenced value gets converted to a Perl scalar via the conversion of "float Type Return Value".
Exceptions:
- The argument must be a scalar reference. Otherwise an exception is thrown.
Examples:
# Converts a Perl scalar reference to float* type
my $value = 23.5;
SPVM::MyClass->foo(\$value);
double Reference Type Argument
A Perl reference gets converted to a value of the SPVM double reference type. π
The referenced value gets converted to a value of the SPVM "double" type via the conversion of "double Type Argument".
After returning from the SPVM method, the referenced value gets converted to a Perl scalar via the conversion of "double Type Return Value".
Exceptions:
- The argument must be a scalar reference. Otherwise an exception is thrown.
Examples:
# Converts a Perl scalar reference to double* type
my $value = 23.5;
SPVM::MyClass->foo(\$value);
Multi-Numeric Reference Type Argument
Reference-to-multi-numeric time. Yes, there's layers. Yes, it's a lot. Keep up bestie, we're slaying. πβ¨
Multi-Numeric byte Reference Type Argument
A Perl reference gets converted to an SPVM multi-numeric "byte" reference type. π¦
Each field gets converted to a value of the SPVM "byte" type via the conversion of "byte Type Argument".
After returning from the SPVM method, each field value gets converted to a Perl scalar via the conversion of "byte Type Return Value". Everybody out here getting converted.
Exceptions:
- The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Note the glow-up here: this time it's a scalar reference to a hash reference, not just a plain hash reference. Two layers, bestie. Don't mix them up or it's exception o'clock. β
Examples:
# Converts a Perl scalar reference to a hash reference to the MyClassPoint_2b* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);
Multi-Numeric short Reference Type Argument
A Perl reference gets converted to an SPVM multi-numeric "short" reference type. π
Each field gets converted to a value of the SPVM "short" type via the conversion of "short Type Argument".
After returning from the SPVM method, each field value gets converted to a Perl scalar via the conversion of "short Type Return Value".
Exceptions:
- The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl scalar reference to a hash reference to the MyClassPoint_2s* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);
Multi-Numeric int Reference Type Argument
A Perl reference gets converted to an SPVM multi-numeric "int" reference type. π₯
Each field gets converted to a value of the SPVM "int" type via the conversion of "int Type Argument".
After returning from the SPVM method, each field value gets converted to a Perl scalar via the conversion of "int Type Return Value".
Exceptions:
- The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2i* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);
Multi-Numeric long Reference Type Argument
A Perl reference gets converted to an SPVM multi-numeric "long" reference type. π
Each field gets converted to a value of the SPVM "long" type via the conversion of "long Type Argument".
After returning from the SPVM method, each field value gets converted to a Perl scalar via the conversion of "long Type Return Value".
Exceptions:
- The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2l* type
my $value = {x => 1, y => 2};
SPVM::MyClass->foo(\$value);
Multi-Numeric float Reference Type Argument
A Perl reference gets converted to an SPVM multi-numeric "float" reference type. π
Each field gets converted to a value of the SPVM "float" type via the conversion of "float Type Argument".
After returning from the SPVM method, each field value gets converted to a Perl scalar via the conversion of "float Type Return Value".
Exceptions:
- The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2f* type
my $value = {x => 1,2, y => 2.3};
SPVM::MyClass->foo(\$value);
Ngl that example is written exactly the way the docs have it β {x => 1,2, y => 2.3} β so I'm passing it to you verbatim, no edits, no fixing, periodt. π Copy it as-is.
Multi-Numeric double Reference Type Argument
A Perl reference gets converted to an SPVM multi-numeric "double" reference type. π
Each field gets converted to a value of the SPVM "double" type via the conversion of "double Type Argument".
After returning from the SPVM method, each field value gets converted to a Perl scalar via the conversion of "double Type Return Value".
Exceptions:
- The reference must be a scalar reference to a hash reference. Otherwise an exception is thrown.
- If a field is not found, an exception is thrown.
Examples:
# Converts a Perl scalar reference to a hash reference to the SPVM MyClassPoint_2d* type
my $value = {x => 1.2, y => 2.3};
SPVM::MyClass->foo(\$value);
Array Type Argument
Arrays next, bestie β buckle up. πΈ
byte[] Type Argument
π byte[] Type Argument
Your Perl array reference (or undef, bestie, undef is valid here π«Ά) gets converted into a value of the byte[] type by the new_byte_array method. That's the whole vibe.
Exceptions: literally whatever new_byte_array throws, that's what you get. No filters, no reruns. π
Examples:
# Converts a Perl array reference to the byte[] type
SPVM::MyClass->foo([1, 2, 3]);
πΈ short[] Type Argument
A Perl array reference (or undef) is converted to a value of the short[] type by the new_short_array method. Same energy, bigger numbers.
Exceptions: exceptions thrown by new_short_array are thrown. Periodt.
Examples:
# Converts a Perl array reference to the short[] type
SPVM::MyClass->foo([1, 2, 3]);
β¨ int[] Type Argument
A Perl array reference (or undef) is converted to a value of the int[] type by the new_int_array method.
Exceptions: exceptions thrown by new_int_array are thrown.
Examples:
# Converts a Perl array reference to the int[] type
SPVM::MyClass->foo([1, 2, 3]);
π₯ long[] Type Argument
A Perl array reference (or undef) is converted to a value of the long[] type by the new_long_array method.
Exceptions: exceptions thrown by new_long_array are thrown. She's consistent π
Examples:
# Converts a Perl array reference to the long[] type
SPVM::MyClass->foo([1, 2, 3]);
π¦ float[] Type Argument
A Perl array reference (or undef) is converted to a value of the float[] type by the new_float_array method.
Exceptions: exceptions thrown by new_float_array are thrown.
Examples:
# Converts a Perl array reference to float[] type
SPVM::MyClass->foo([1.2, 2.3, 3.4]);
Notice the example comment here saysfloat[]type and notthe float[]type β yes, we're keeping it exactly as written, no editing the source's little quirks. π
π§ double[] Type Argument
A Perl array reference (or undef) is converted to a value of the double[] type by the new_double_array method.
Exceptions: exceptions thrown by new_double_array are thrown.
Examples:
# Converts a Perl array reference to the double[] type
SPVM::MyClass->foo([1.2, 2.3, 3.4]);
π string[] Type Argument
A Perl array reference (or undef) is converted to a value of the string[] type by the new_string_array method.
Exceptions: exceptions thrown by new_string_array are thrown.
Examples:
# Converts a Perl array reference to the string[] type
SPVM::MyClass->foo(["γγ", "γγ", "γ"]);
Bestie the Japanese in that example is so cute, we love a multilingual icon π
π Any Object Array Type Argument
A Perl array reference (or undef) is converted to a value of the object[] type by the new_object_array method. She's the general-purpose girly of the object-array world.
Exceptions: exceptions thrown by new_object_array are thrown.
π Class Array Type Argument
A Perl array reference (or undef) is converted to a value of the class type by the new_object_array method. Yep β still new_object_array doing the work, no cap.
Exceptions: exceptions thrown by new_object_array are thrown.
π Interface Array Type Argument
A Perl array reference (or undef) is converted to a value of the interface type by the new_object_array method. Again new_object_array, she's carrying this whole section on her back π
Exceptions: exceptions thrown by new_object_array are thrown.
π Multi-Numeric Array Type Argument
A Perl array reference (or undef) is converted to a value of the multi-numeric array type by the new_mulnum_array method.
Exceptions: exceptions thrown by new_mulnum_array are thrown.
Examples:
# Converts a Perl array reference of a hash reference to the Complex_2d[] type
SPVM::MyClass->foo([{re => 1.2, im => 2.3}, {re => 3.4, im => 4.5}]);
Hash refs in, multi-numeric array out. We love a transformation arc π¦β¨
π§΅ Multi-Dimensional Array Type Argument
A Perl array reference (or undef) is converted to a value of the multi-dimensional array type by the new_muldim_array method.
Exceptions: exceptions thrown by new_muldim_array are thrown.
π Return Value Conversion
Okay so this is the reverse direction β an SPVM return value gets converted to a Perl value based on the SPVM type. Going home, bestie π π«
void Type Return Value
The SPVM void return value is converted to Perl undef. That's it, that's the whole conversion. Nothing back, ghosted π
byte Type Return Value
A value of the SPVM byte type is converted to a Perl scalar using newSViv perlapi (https://perldoc.perl.org/perlapi#newSViv).
short Type Return Value
A value of the SPVM short type is converted to a Perl scalar using newSViv perlapi (https://perldoc.perl.org/perlapi#newSViv).
int Type Return Value
A value of the SPVM float type is converted to a Perl scalar using newSViv perlapi (https://perldoc.perl.org/perlapi#newSViv).
π«Ά Yes, the original really does sayfloattype in this section about theintreturn value. We are not fixing it. Copying it verbatim is the assignment and we ate. π
long Type Return Value
A value of the SPVM float type is converted to a Perl scalar using newSViv perlapi (https://perldoc.perl.org/perlapi#newSViv).
Same situation, same energy. The source saidfloat, so we sayfloat. Don't come for me π
float Type Return Value
A value of the SPVM float type is converted to a Perl scalar using newSVnv perlapi (https://perldoc.perl.org/perlapi#newSVnv).
double Type Return Value
A value of the SPVM double type is converted to a Perl scalar using newSVnv perlapi (https://perldoc.perl.org/perlapi#newSVnv).
π string Type Return Value
- If the SPVM return value is
undef, it gets converted to Perlundef. Simple as that. - Otherwise, it's converted to a
SPVM::BlessedObject::Stringobject. Slay, now it's an actual object π
π Multi-Numeric Type Return Value
The value of the SPVM multi-numeric type gets converted to a Perl hash reference whose keys are the field names of the multi-numeric type. Iconic little mapping, honestly π
Each field value is converted by the conversion described in byte Type Return Value, short Type Return Value, int Type Return Value, long Type Return Value, float Type Return Value, and double Type Return Value β pick whichever one matches the multi-numeric type. It's a whole buffet and you just grab the right plate π
π¦ Any Object Type Return Value
- If the SPVM return value is
undef, it gets converted to Perlundef. - If the type of the return value is an array type, it becomes a
SPVM::BlessedObject::Arrayobject. - If the type of the return value is an string type, it becomes a
SPVM::BlessedObject::Stringobject. - Otherwise, it becomes a
SPVM::BlessedObject::Classobject.
Three possible glows depending on the type. Vibe check passed β
π Class Type Return Value
- If the SPVM return value is
undef, it gets converted to Perlundef. - Otherwise, it's converted to a
SPVM::BlessedObject::Classobject.
π Interface Type Return Value
- If the SPVM return value is
undef, it gets converted to Perlundef. - Otherwise, it's converted to a
SPVM::BlessedObject::Classobject.
π Array Type Return Value
- If the SPVM return value is
undef, it gets converted to Perlundef. - Otherwise, it's converted to a
SPVM::BlessedObject::Arrayobject.
π Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License
That's the whole page, bestie β we made it to the end and honestly? Iconic πβ¨π
Cute little sign-off, because the footer deserves a moment: this is from perl v5.42.2, dated 2026-02-03, and it belongs to SPVM::ExchangeAPI(3) β the user contributed perl documentation, no cap. Go forth and exchange your APIs safely π«Άππ
π¦ where this page comes from
- alpine 3.24: spvm-doc 0.990125-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms