NAME

SPVM - Fast Calculation and Easy C/C++ Binding with perlish syntax and static typing

SPVM is before 1.0 under development! I will change implementation and specification without warnings.

SYNOPSIS

Fast Array Operation using SPVM.

SPVM Module:

# lib/SPVM/MyMath.spvm
package MyMath {
  # Standard functions
  use Std;
  
  # Sub Declaration
  sub sum : int ($nums : int[]) {
    
    # Culcurate total
    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 module
use SPVM 'MyMath';

# New SPVM int array
my $sp_nums = SPVM::new_int_array([3, 6, 8, 9]);

# Call SPVM subroutine
my $total = SPVM::MyMath->sum($sp_nums);

print $total . "\n";

If you know more SPVM syntax, see SPVM::Document::Specification.

If you know more Functions to convert Perl Data to SPVM Data, see SPVM::Document::DataConversionAPI.

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

If you know more SPVM Extension, see SPVM::Document::Extension.

If you know the APIs to manipulate SPVM data, see SPVM::Document::NativeAPI.

DESCRIPTION

SPVM provide Fast Culcuration and Easy way to Bind C/C++ Language to Perl.

  • Fast calculation - The Perl's biggest weak point is the calculation performance. SPVM provides fast calculations.

  • GC - You don't need to care about freeing memory

  • Static typing - Static typing for performance

  • VM - Byte codes are generated so that you can run them on SPVM language

  • Perlish syntax - SPVM syntax is very similar to Perl

  • Perl module - SPVM function can be called from Perl itself.

SPVM Tutorial

SPVM is a language which is similar with Perl. SPVM is very similar to Perl, and you can write same syntax of Perl in most part.

SPVM communicate with Perl. You can call SPVM function directory from Perl.

SPVM is very fast and provide array data structure. Now SPVM array operation is about 6x faster.

SPVM module

At first, you can write SPVM module.

# lib/SPVM/MyModule1.spvm
package MyModule1 {
  has x : int;
  has y : int;

  sub sum : int ($x : int, $y : int) {

    my $total = $x + $y;

    return $total;
  }
}

This is same as Perl except SPVM have static type and has keyword.

You can define field by has keyword, and specify static type by : type.

has x : int;

You can specify argument types and return type to subroutine by : type.

sub sum : int ($x : int, $y : int) {

  my $total = $x + $y;

  return $total;
}

Let's save this file by the following name

lib/SPVM/MyModule1.spvm

If package name is MyModule1, file name must be SPVM/MyModule1.spvm.

Extension is spvm. And you create SPVM directory.

lib is normal directory.

Call SPVM subroutine

Next you can use SPVM subroutine from Perl.

use FindBin;
use lib "$FindBin::Bin/lib";

use SPVM 'MyModule1';

my $total = SPVM::MyModule1::sum(3, 5);
print $total . "\n";

At first, you add library path by FindBin and lib module.

use FindBin;
use lib "$FindBin::Bin/lib";

Next, use SPVM module. MyModule1 is loaded.

use SPVM 'MyModule1';

And call SPVM subroutine. If SPVM subroutine absolute name is MyModule1::sum, you can call this subroutine by SPVM::MyModule1::sum.

my $total = SPVM::MyModule1::sum(3, 5);
print $total . "\n";

Document

SPVM Functions

SPVM::Document::DataConversionAPI - SPVM data convertion functions.

List of SPVM functions:

  • new_byte_array

  • new_byte_array_data

  • new_byte_array_string

  • new_short_array

  • new_int_array

  • new_long_array

  • new_float_array

  • new_double_array

  • new_object_array_len

  • new_object

If you know Detail of SPVM Function, see SPVM::Document::DataConversionAPI.

SPVM Specification

SPVM::Document::Specification - SPVM Specification

SPVM Native Interface

SPVM::Document::NativeAPI - SPVM Native Interface.

Native API is C level API. You can write programing logic using C language and SPVM Native API.

SPVM Standard Function

SPVM::Document::Functions - SPVM Standard Functions

SPVM Standard Module

SPVM::Document::Modules - SPVM Standard Modules

SPVM FAQ

SPVM::Document::FAQ - Oftten asked question.

SUPPORT

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

SPVM(GitHub).

AUTHOR

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

CONTRIBUTERS

COPYRIGHT AND LICENSE

Copyright (C) 2017-2018 by Yuki Kimoto

MIT License