NAME

SPVM - Fast array and numeric operation, and provide easy way to 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

Copyright 2017-2018 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.