SPVM - SPVM Language
SPVM is not yet 1.0 release. It is quite often changed without warnings until I feel that the implementation is good enough.
SPVM
Creating SPVM Module:
# lib/SPVM/MyMath.spvm class MyMath { static method sum : int ($nums : int[]) { my $total = 0; for (my $i = 0; $i < @$nums; $i++) { $total += $nums->[$i]; } return $total; } }
Calling SPVM methods from Perl:
# sum.pl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use SPVM 'MyMath'; # Call method my $total = SPVM::MyMath->sum([3, 6, 8, 9]); print "$total\n";
SPVM (Static Perl Virtual Machine) is a perl-ish static typed programing language. SPVM provides fast calculation, fast array operations, easy C/C++ binding, and creating executable files.
If you load SVPM module from Perl, use the following syntax.
use SPVM 'Foo';
Suppose the following SPVM/Foo.spvm is placed on a module search path.
SPVM/Foo.spvm
# SPVM/Foo.spvm class Foo { static method sum : int ($x1 : int, $x2 : int) { return $x1 + $x2; } }
If you load SPVM Foo::Bar module, do the following.
Foo::Bar
use SPVM 'Foo::Bar';
Suppose the following SPVM/Foo/Bar.spvm is placed on a module search path.
SPVM/Foo/Bar.spvm
# SPVM/Foo/Bar.spvm class Foo::Bar { static method sum : int ($x1 : int, $x2 : int) { return $x1 + $x2; } }
use SPVM MODULE_NAME compile the SPVM module and the dependent modules.
use SPVM MODULE_NAME
Note that at this point a SPVM runtime has not yet been created.
A default SPVM runtime is created the first time you call a method of SPVM module or call a function or method of the Exchange API.
Let's call SPVM class method from Perl.
use SPVM 'Foo'; my $total = SPVM::Foo->sum(1, 2);
The definition of Foo module is the following.
Foo
If the number of arguments does not match the number of arguments of the SPVM method, an exception occurs.
The Perl values of the arguments are converted to the SPVM values by the rule of argument convertion.
If the type is non-conforming, an exception occurs.
The SPVM return value is converted to a Perl return value by the rule of return value convertion.
The SPVM exception is converted to a Perl exception.
Let's call SPVM instance method from Perl.
use SPVM 'Foo'; my $foo = SPVM::Foo->new; my $total = $foo->sum(1, 2);
# SPVM/Foo.spvm class Foo { static method new : Foo () { return new Foo; } method sum : int ($x1 : int, $x2 : int) ( return $x1 + $x2; } }
Exchange API is APIs to convert Perl data structures to/from SPVM data structures and to call SPVM methods from Perl.
my $api = SPVM::api();
Gets the global SPVM::ExchangeAPI object.
SPVM documents.
SPVM Tutorial.
Tutorial
SPVM Language Specification.
Language Specification
SPVM Standard Modules.
Standard Modules
SPVM Exchange APIs is functions to convert between Perl data structures and SPVM data structures.
ExchangeAPI
The native module is the module that is implemented by native language such as C language or C++.
C language
C++
Native Method
SPVM native APIs are public APIs that are used in native language sources such as C language or C++.
Native APIs
A resource is a native module that contains a set of sources and headers of native language such as C language or C++.
Resource
spvmcc is the compiler and linker to create the executable file from SPVM source codes.
spvmcc
spvmdist is the command to create SPVM distribution.
spvmdist
SPVM performance benchmarks.
Benchmark
SPVM building directory to build precompile and native methods. If the SPVM_BUILD_DIR environment variable is not set, the building of precompile and native methods fails.
precompile
native
SPVM_BUILD_DIR
bash:
export SPVM_BUILD_DIR=~/.spvm_build
csh:
setenv SPVM_BUILD_DIR ~/.spvm_build
Print debug messages of SPVM::Builder::CC to stderr.
Force the compilation and the link of SPVM::Builder::CC.
Github
GitHub Issue
Github Discussions
Yuki Kimoto <kimoto.yuki@gmail.com>
moti<motohiko.ave@gmail.com>
Mohammad S Anwar
akinomyoga
NAGAYASU Shinya
Reini Urban
chromatic
Kazutake Hiramatsu
Yasuaki Omokawa
Suman Khanal
Ryunosuke Murakami
Yoshiyuki Itoh
Tore Aursand
greengorcer
Copyright 2018-2022 Yuki Kimoto, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
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.