NAME
SPVM - Fast array and numeric operation, and provide easy way to C/C++ Binding
SPVM is before 1.0 under development! I will change implementation and specification without warnings.
Curent SPVM version is 0.3 serieses. This means implementation is finshed by 30% of version 1.0.
SYNOPSIS
package MyMath {
sub sum : int ($nums : int[]) {
my $total = 0;
for (my $i = 0; $i < @$nums; $i++) {
$total += $nums->[$i];
}
return $total;
}
}
DESCRIPTION
SPVM provide fast array and numeric operation.
SPVM provide easy way to Bind C/C++ Language to Perl.
FEATURES
Fast array operation, Fast numeric operation, Static typing, Virtual machine, JIT, Pre compile
Perlish syntax, Easy way to C/C++ binding, C99 math functions
EXAMPLES
How to use SPVM from Perl
SPVM Module:
# lib/SPVM/MyMath.spvm
package MyMath {
sub sum : int ($nums : int[]) {
my $total = 0;
for (my $i = 0; $i < @$nums; $i++) {
$total += $nums->[$i];
}
return $total;
}
}
Use SPVM Module from Perl
use FindBin;
use lib "$FindBin::Bin/lib";
use SPVM 'MyMath';
# New int array
my $sp_nums = SPVM::new_int_array([3, 6, 8, 9]);
# Call subroutine
my $total = SPVM::MyMath->sum($sp_nums);
print $total . "\n";
See also SPVM::Document::PerlAPI.
C Extension using SPVM
SPVM Module:
# lib/SPVM/MyMathNative.spvm
package MyMathNative {
# Sub Declaration
native sub sum int ($nums : int[]);
}
C Source File;
// lib/SPVM/MyMathNative.inline/MyMathNative.c
#include <spvm_api.h>
int32_t SPVM__MyMathNative__sum(SPVM_API* api, SPVM_API_VALUE* args) {
// First argument
SPVM_API_OBJECT* sp_nums = args[0].object_value;
// Array length
int32_t length = api->get_array_length(api, sp_nums);
// Elements pointer
int32_t* nums = api->get_int_array_elements(api, sp_nums);
// Culcurate total
int32_t total = 0;
{
int32_t i;
for (i = 0; i < length; i++) {
total += nums[i];
}
}
return total;
}
Use Extension Module from Perl:
use FindBin;
use lib "$FindBin::Bin/lib";
# Use SPVM module
use SPVM 'MyMathNative';
# New SPVM int array
my $sp_nums = SPVM::new_int_array([3, 6, 8, 9]);
# Call SPVM subroutine
my $total = SPVM::MyMathNative->sum($sp_nums);
print $total . "\n";
See also SPVM::Document::Extension, SPVM::Document::NativeAPI.
STANDARD FUNCTIONS
print, warn, time
STANDARD MODULES
SPVM::CORE, SPVM::Byte, SPVM::Short, SPVM::Int, SPVM::Long, SPVM::Float, SPVM::Double, SPVM::Bool, SPVM::Math, SPVM::IO, SPVM::TypeUtil
PERL API
Native API
Specification
SUPPORT
If you have problems or find bugs, comment to GitHub Issue.
AUTHOR
Yuki Kimoto <kimoto.yuki@gmail.com<gt>
CONTRIBUTERS
akinomyoga (Koichi Murase)
COPYRIGHT AND LICENSE
Copyright (C) 2017-2018 by Yuki Kimoto
MIT License