++ed by:
MHOWARD FAYLAND

2 PAUSE users
2 non-PAUSE users.

Yuki Kimoto
and 1 contributors

NAME

SPVM - Fast calculation, GC, static typing, VM with perlish syntax

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

SYNOPSIS

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

  use SPVM 'MyModule2';

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

Module file

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

    sub sum ($a : int, $b : int) : int {

      my $total = $a + $b;

      return $total;
    }
  }

  # lib/SPVM/MyModule2.spvm
  use MyModule1;
  package MyModule2 {

    sub foo ($a : int, $b : int) : int {

      my $total = ($a * $b) + MyModule1::sum(2, 4);

      return $total;
    }
  }

If you want to know more syntax, see solo/SPVM/Test.spvm.

If you want to know SPVM language, see solo/README.md

DESCRIPTION

Do you need faster Perl? SPVM provides fast calculation 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 (Not yet implemented).

SPVM only work on the Perl which support 64 bit integer.

SPVM SYNTAX

Type

Numeric type

Numeric types are byte, short, int, long, float, double.

  byte    signed integer          1byte
  short   signed integer          2byte
  int     signed integer          4byte
  long    signed integer          8byte
  float   floating-point number   4byte
  double  floating-point number   8byte

Declaration

  my $value : byte;
  my $value : short;
  my $value : int;
  my $value : long;
  my $value : float;
  my $value : double;

String type

String type is string.

This is same as byte[] at internal data structure.

Declaration

  my $string : string;

Reference type

Reference types are `array` and `object`.

Object type

    PackageName

Declaration

    my $object : PackageName;

Array type

  byte[]   byte array
  short[]  short array
  int[]    int array array
  long[]   long array
  float[]  float array
  doube[]  double array
  PackageName[] object array

Declaration

  my $values : byte[];
  my $values : short[];
  my $values : int[];
  my $values : long[];
  my $values : float[];
  my $values : double[];
  my $values : PackageName[];

Multiple array type

  my $values : byte[][];
  my $values : short[][];
  my $values : int[][];
  my $values : long[][];
  my $values : float[][];
  my $values : double[][];
  my $values : PackageName[][];

  my $values : byte[][][];
  my $values : short[][][];
  my $values : int[][][];
  my $values : long[][][];
  my $values : float[][][];
  my $values : double[][][];
  my $values : PackageName[][][];

Type inference

If the type of right value is known, the type of left value is automatically decided.

  # Type of $value2 is byte.
  my $value1 : byte;
  my $value2 = $value1;

  # Type of $values2 is int[]
  my $values1 = malloc int[3];
  my $values2 = $values1;

  # Type of $object2 is PackageName
  my $object1 = malloc PackageName
  my $object2 = $object1;

Array

Create array

Array is created by malloc. Elements values is not initialized.

  my $nums = malloc byte[3];
  my $nums = malloc short[3];
  my $nums = malloc int[3];
  my $nums = malloc long[3];
  my $nums = malloc float[3];
  my $nums = malloc double[3];

Get array length

  my $len = @$nums;
  my $len = @{$nums};

Get and set array element

  # Get
  my $num = $nums->[0];

  # Set
  $nums->[0] = 5;

Condition branch

  if (1) {

  }
  elsif (2) {

  }
  else {

  }

Loop

for

  my $nums = malloc int[10];
  for (my $i = 0; $i < @$nums; $i++) {
    $nums->[$i] = 0;
  }

while

  my $nums = malloc int[10];
  my $i = 0;
  while ($i < @$nums) {
    $nums->[$i] = 0;
  }

Constant

Constant type

Type of constant default integral value is `int`.

    # int type
    1;
    3;

Type of constant default floating-point value is `double`.

    # double
    1.2
    5.3

Type of constant is specified by type specifier.

    # long
    3L

    # float
    3.2f

    # double
    3.2d

Name

Package name

Package name is a combination of alphabets, numbers, and `::`. Numbers should not appear as the first character. `_` can't be used in class name.

    # OK
    Foo
    Foo::Bar
    Foo1::Bar1

    # Not OK
    1Foo
    Foo::2Bar
    Foo_Bar;

Subroutine name

Subroutine name is a combination of alphabets, numbers, and `_` separators. Continual `_`(For example `__`) can't be used in subroutine name.

    # OK
    foo
    foo1
    foo_bar

    # Not OK
    1foo
    foo__bar

Field name

Field name is a combination of alphabets, numbers, and `_` separators. Continual `_`(For example `__`) can't be used in field name.

    # OK
    foo
    foo1
    foo_bar

    # Not OK
    1foo
    foo__bar

Absolute name

Absolute name is combination of package name and subroutine name, or package name and field name.

    PackageName1::foo
    PackageName1::PackageName2::foo_bar

Limitation

Object can't have object and array of object.

If I have idea to implement weaken reference and implement weaken reference, this limitation is removed.

FUNCTIONS

new_byte_array

Create new_byte array

  my $array = SPVM::new_byte_array([1, 2, 3]);

If you get perl values, you can use get_elements methods.

  my $values = $array->get_elements;

new_short_array

Create short array

  my $array = SPVM::new_short_array([1, 2, 3]);

If you get perl values, you can use get_elements methods.

  my $values = $array->get_elements;

new_int_array

Create int array

  my $array = SPVM::new_int_array([1, 2, 3]);

If you get perl values, you can use get_elements methods.

  my $values = $array->get_elements;

new_long_array

Create long array

  my $array = SPVM::new_long_array([1, 2, 3]);

If you get perl values, you can use get_elements methods.

  my $values = $array->get_elements;

new_float_array

Create float array

  my $array = SPVM::new_float_array([1, 2, 3]);

If you get perl values, you can use get_elements methods.

  my $values = $array->get_elements;

new_double_array

Create double array

  my $array = SPVM::new_double_array([1, 2, 3]);

If you get perl values, you can use get_elements methods.

  my $values = $array->get_elements;

new_string_raw

Create byte array from not decoded Perl string. This function is faster than SPVM::string because copy is not executed.

  my $array = SPVM::new_string_raw("AGTCAGTC");

new_string

Create byte array from decoded Perl string.

  my $array = SPVM::new_string("����������");

new_object

Create object.

  my $object = SPVM::new_object("Point");

You can set and get value by set and get method.

  $object->set(x => 1);
  my $x = $object->get('x');

FAQ

  • Why SPVM don't support 32 bit Perl

    In many 32 bit Perl, 64 bit integer is not supported. This means that Perl can not express 64 bit integers on source code.

    See the following code.

        my $value = 9223372036854775807;

    In 32 bit Perl, 64bit integer value is converted to double automatically. The double value can't express long value accurately.

AUTHOR

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

CONTRIBUTERS

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Yuki Kimoto

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.3 or, at your option, any later version of Perl 5 you may have available.