SPVM - Static Perl Virtual Machine. Fast calcuration & Easy C/C++ Binding
SPVM Module:
# lib/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 = MyMath->sum($sp_nums); print $total . "\n";
SPVM is Static Perl Virtual Machine. Provide fast calcuration & easy C/C++ Binding.
Features:
Fast culcuration, Fast array operation, Small memory
Perl syntax, Static typing, Switch syntax, Have language specification
Enum, Type inference, Anon subroutine, Variable captures
Array initialization,
Reference count GC, Weaken reference, Module system
Exception, Package variable
Object oriented, Inteface, Value type, Value array type, Reference type
Easy way to C/C++ binding, Automatically Perl binding, C99 math functions
Dynamic linking, Subroutine precompile, AOT compile(create exe file)
Native API(C level api), C99 standard
See also SPVM::Document::PerlAPI.
# lib/MyMathNative.spvm package MyMathNative { # Sub Declaration native sub sum int ($nums : int[]); }
C Source File;
// lib/MyMathNative.native/MyMathNative.c #include <spvm_native.h> int32_t SPVM_NATIVE_MyMathNative__sum(SPVM_ENV* env, SPVM_VALUE* stack) { // First argument void* sp_nums = stack[0].oval; // Array length int32_t length = env->get_array_length(env, sp_nums); // Elements pointer int32_t* nums = env->get_int_array_elements(env, sp_nums); // Culcurate total int32_t total = 0; { int32_t i; for (i = 0; i < length; i++) { total += nums[i]; } } // Return value is set to stack[0] stack[0].ival = total; // If function success, return SPVM_SUCCESS return SPVM_SUCCESS; }
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 = MyMathNative->sum($sp_nums); print $total . "\n";
See also SPVM::Document::Extension, SPVM::Document::NativeInterface.
SPVM::Document::Functions
print, warn, time
SPVM::CORE, SPVM::Byte, SPVM::Short, SPVM::Int, SPVM::Long, SPVM::Float, SPVM::Double, SPVM::Bool
SPVM::Document::PerlAPI
SPVM::Document::NativeInterface
SPVM::Document::Language
SPVM is before 1.0 under development! I will change implementation and specification without warnings.
If you have problems or find bugs, comment to GitHub Issue.
SPVM(GitHub).
Yuki Kimoto <kimoto.yuki@gmail.com<gt>
moti<lt>motohiko.ave@gmail.com<gt>
akinomyoga, NAGAYASU Shinya, Reini Urban, chromatic, Kazutake Hiramatsu
MIT License
Copyright (c) [2018] [Yuki Kimoto]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 POD Error
The following errors were encountered while parsing the POD:
=back without =over
To install SPVM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPVM
CPAN shell
perl -MCPAN -e shell install SPVM
For more information on module installation, please visit the detailed CPAN module installation guide.