NAME

SPVM - Static Perl Virtual Machine. Fast calcuration & Easy C/C++ Binding

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, Precompile, Pre compile

  • Perlish syntax, Easy way to C/C++ binding, C99 math functions

EXAMPLES

How to use SPVM from Perl

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";

See also SPVM::Document::PerlAPI.

C Extension using SPVM

SPVM Module:

# 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.

STANDARD FUNCTIONS

SPVM::Document::Functions

print, warn, time

STANDARD MODULES

SPVM::CORE, SPVM::Byte, SPVM::Short, SPVM::Int, SPVM::Long, SPVM::Float, SPVM::Double, SPVM::Bool

SPVM Perl API

SPVM::Document::PerlAPI

Native Interface

SPVM::Document::NativeInterface

Language

SPVM::Document::Language

SUPPORT

If you have problems or find bugs, comment to GitHub Issue.

SPVM(GitHub).

AUTHOR

Yuki Kimoto <kimoto.yuki@gmail.com<gt>

CONTRIBUTERS

NOTE

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.

COPYRIGHT & LICENSE

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.