SPVM Native API

SPVM Native API is described in this document.

Last Updated: 2020-06-24

What is the SPVM Native API?

The SPVM Native API is a C API that can be called in a Native Subroutine of SPVM. The specifications for native spvm subroutine are also described here.

  • how Native Subroutine are defined
  • receives arguments from spvm subroutine in Native Subroutine
  • returns the return value of the
  • Native Subroutine as the return value of the SPVM subroutine
  • gets the elements of the SPVM array as a C array

You can call Native Subroutine from SPVM.

Native Subroutine Declaration

The declaration of the SPVM Native Subroutine is done by using the descriptor "native" of the subroutine. End with a semicolon without writing a block of subroutine. The following is an example of declaring in a module called Foo::Bar.

# Foo/Bar.spvm
package Foo::Bar {
  native sub sum : int ($num1 : int, $num2 : int);
}

Native Subroutine Definition

You define Native Subroutine in a native source file. The native source file changes the extension of the SPVM module to the extension of the target language. For example, if it is C, it is changed to ".c". In C++, it was changed to .cpp. This can be changed in the settings of the Native Subroutine.

# Module name Foo::Native source file for Bar
Foo/Bar.c

When you create a native source file, you must create a native configuration file. The native configuration file changes the extension of the SPVM module to .config. If the native configuration file does not exist, an exception is raised.

# Module name Foo::Bar native configuration file
Foo/Bar.config

The native configuration file is perl source code. The SPVM::Builder:Config object must be written at the end of the source code and returned. Otherwise, an exception is raised.

If you want to write C on the same C99 as SPVM, write:

use strict;
use warnings;

use SPVM::Builder::Config;
my $bconf = SPVM::Builder::Config->new_c99;

$bconf;

If you want to compile outside of C99, or if you want to add a library, see the SPVM::Builder:Config documentation sample.

You define Native Subroutine in a native source file. An example in this case is Foo/Bar.c.

#include "spvm_native.h"

int32_t SPNATIVE__Foo__Bar__sum(SPVM_ENV* env, SPVM_VALUE* stack) {

  int32_t num1 = stack[0].ival;
  int32_t num2 = stakc[1].ival;

  int32_t total = num1 + num2;

  stack[0].ival = total;

  return SPVM_SUCCESS;
}

Include "spvm_native.h" at the beginning of the native source file. This header file defines the SPVM Native API and the required structure.

A Native Subroutine definition is a simple C language function.

The function name in C of the Native Subroutine starts with "SPNATIVE__", followed by the module name "::" converted to "__", followed by "__", and ends with the subroutine name. If the correspondence with the subroutine name in SPVM is incorrect, a compile error will occur.

There are two arguments, the first argument is "SPVM_ENV* env" which has the information of the execution environment, and the second argument is "SPVM_VALUE* stack" which is used for the argument and return value.

The return type is "int32_t". If the subroutine raises an exception, "SPVM_EXCEPTION" is returned, otherwise "SPVM_SUCCESS" is returned.

In the above sample, it takes two int type arguments of SPVM, calculates the sum, and returns the return value.

Compile Native Subroutine

Native subroutine are compiled with Perl and are compiled into a dynamically readable shared library depending on the OS. Shared libraries (.so) on Unix/Linux, dynamic link libraries (.dll) on Windows.

Compilation into a dynamically readable shared library is done during SPVM compilation. The build directory must exist at compile time. If the build directory does not exist, an exception will be thrown.

The default build directory is the "~/.spvm_build" directory in the directory containing the executed Perl script, and can be changed with the environment variable "SPVM_BUILD_DIR".

If you want to use SPVM Native Subroutine from Perl, create a "~/.spvm_build" directory in the directory where the executed Perl script exists.

script.pl
~/.spvm_build

The intermediately generated object files are generated under "work/object" under the build directory. The object file name has the extension of the SPVM module changed to ".o".

~/.spvm_build/work/object/Foo/Bar.o

Dynamically readable shared libraries are generated under "work/lib" under the build directory. The file name of the dynamically readable shared library is the extension of the SPVM module changed to the dynamically readable shared library extension according to the OS.

# Unix/Linux
~/.spvm_build/work/object/Foo/Bar.so

# Windows
~/.spvm_build/work/object/Foo/Bar.dll

Arguments

  • Arguments and stack
  • Get byte type argument
  • Get short type argument
  • Get int type argument
  • Get long type argument
  • Get float type argument
  • Get double type argument
  • Get object type argument
  • Stack of arguments
  • Get reference type argument of byte
  • Get reference type argument of short
  • Get int reference type argument
  • Get long reference type argument
  • Get float reference type argument
  • Get double reference type argument
  • Get multiple numeric argument
  • Arguments and stack

    The stack is the "SPVM_VALUE* stack" passed as the second argument in the definition of the Native Subroutine, and the arguments are stored in this.

    int32_t SPNATIVE__Foo__Bar__sum(SPVM_ENV* env, SPVM_VALUE* stack) {
    
    }
    

    SPVM_VALUE is a C language union for storing SPVM values. You can save numeric, object, and reference values.

    Pointer to the beginning of the "SPVM_VALUE type array" of "SPVM_VALUE* stack". The value of the argument of the Native Subroutine called from SPVM side is set in this array.

    For example, to get the value of the first argument of int type, write as follows.

    int32_t args1 = stack[0].ival;
    

    For example, to get the value of the second argument of long type, write as follows.

    int64_t args2 = stack[0].lval;
    

    Get byte type argument

    To get the SPVM byte argument, access the bval field. Assign to the C language int8_t type.

    int8_t args1 = stack[0].bval;
    

    Get short type argument

    To get the short argument of SPVM, access the sval field. Assign it to the C language int16_t type.

    int16_t args1 = stack[0].sval;
    

    Get int type argument

    To get the SPVM int type argument, access the ival field. Assign to the C language int32_t type.

    int32_t args1 = stack[0].ival;
    

    Get long type argument

    To get the long argument of SPVM, access the lval field. Assign to the C language int64_t type.

    int64_t args1 = stack[0].lval;
    

    Get float type argument

    To get the SPVM float type argument, access the fval field. Assign to float type of C language.

    float args1 = stack[0].fval;
    

    Get double type argument

    To get the SPVM double argument, access the dval field. Assign to the C language double type.

    double args1 = stack[0].dval;
    

    Get object type argument

    To get the SPVM object type argument, access the oval field. Assign it to void* type in C language.

    void* args1 = stack[0].oval;
    

    Get reference type argument of byte

    To get the SPVM byte reference type argument, access the bref field. Assign to the C language int8_t* type.

    int8_t* args1 = stack[0].bref;
    

    Get reference type argument of short

    To get the SPVM short reference type argument, access the sref field. Assign it to the C language int16_t* type.

    int16_t* args1 = stack[0].sref;
    

    Get int reference type argument

    To get the SPVM int reference type argument, access the iref field. Assign to the C language int32_t* type.

    int32_t* args1 = stack[0].iref;
    

    Get reference type argument of long

    To get the SPVM long reference type argument, access the lref field. Assign to int64_t* type of C language.

    int64_t* args1 = stack[0].lref;
    

    Get argument of float reference type

    To get the SPVM float reference type argument, access the fref field. Assign to float* type of C language.

    float* args1 = stack[0].fref;
    

    doubleのリファレンス型の引数の取得

    To get the SPVM double reference type argument, access the dref field. Assign to the C language double* type.

    double* args1 = stack[0].dref;
    

    Get multiple numeric type arguments

    In a Native Subroutine, multiple numeric type arguments are assigned to multiple arguments.

    For example, in the case of the argument of SPVM::Complex_2d type, it gets from two arguments. Note that you cannot access it by field name.

    double args_re = stack[0].dval;
    double args_im = stack[1] .dval;
    

    Return Value

    • Return value and stack
    • Set return value of byte type
    • Set return value of short type
    • Set return value of int type
    • Set long type return value
    • Set return value of float type
    • Set return value of double type
    • Set return value of object type
    • Multiple numeric return value setting
    • Return value and stack

      Native subroutine use the stack to set the return value, rather than returning it with a C language return statement.

      For example, to return an int type return value, write as follows.

      stack[0].ival = 3;
      

      For example, to get the value of the second argument of long type, write as follows.

      stack[0].lval = 56;
      

      Set return value of byte type

      To set the SPVM byte return value, assign it to the bval field. Assigns a value of type int8_t in C language.

      int8_t retval;
      stack[0].bval = retval;
      

      Set return value of short type

      To set the SPVM short return value, assign it to the sval field. Assigns a C language int16_t type value.

      int16_t retval;
      stack[0].sval = retval;
      

      Set return value of int type

      To set the SPVM int return value, assign it to the ival field. Assigns a C language int32_t type value.

      int32_t retval;
      stack[0].ival = retval;
      

      Set long type return value

      To set the SPVM long return value, assign it to the lval field. Assigns a value of C language int64_t type.

      int64_t retval;
      stack[0].lval = retval;
      

      Set return value of float type

      To set the SPVM float return value, assign it to the fval field. Substitutes a C type float type value.

      float retval;
      stack[0].fval = retval;
      

      Set return value of double type

      To set the SPVM double return value, assign it to the dval field. Assigns a C type double value.

      double retval;
      

      Set return value of object type

      To set the return value of the SPVM object type, assign it to the oval field. Assign a value of void* type in C language.

      void* retval;
      stack[0].oval = retval;
      

      Set multiple numeric return value

      In a Native Subroutine, multiple numeric return values ​​are assigned to multiple return values.

      For example, for the return value of SPVM::Complex_2d type, set two return values.

      double retval_x;
      double retval_y;
      stack[0].dval = retval_x;
      stack[1] .dval = retval_y;
      

      Call SPVM Subroutine

      To call the SPVM subroutine, first use the sub_id function or the method_sub_id function

      // For a subroutine that is not a method
      int32_t sub_id = env->get_sub_id(env, "Foo", "sum", "int (int, int)");
      
      // For method
      int32_t sub_id = env->get_method_sub_id(env, object, "sum", "int (self, int, int)");
      

      If sub_id is less than 0, it means that the subroutine was not found. It is safe to handle exceptions as follows.

      if (sub_id <0) {
        SPVM_DIE ("Can't find sub id", "Foo/Bar.c", __LINE__);
      }
      

      Set the SPVM subroutine argument to stack before calling the subroutine.

      stack[0].ival = 1;
      stack[0].ival = 2;
      

      To call a SPVM subroutine, use the call_sub function.

      int32_t exception_flag = env->call_sub(env, sub_id, stack);
      

      Nonzero if the subroutine raised an exception, 0 if no exception occurred.

      The return value of the subroutine is stored in the first element of the stack.

      int32_t total = stack[0].ival;
      

      Native Subroutine Scope

      Native subroutine are entirely enclosed in scope.

      Objects added to the mortal stack will automatically have their reference count decremented by 1 when the Native Subroutine ends. When the reference count reaches 0, it is released.

      Use push_mortal to add objects to the mortal stack.

      env->push_mortal(env, object);
      

      Native APIs that normally create an object such as "new_object" will add the automatically created object to the mortal stack so you don't need to use this.

      Use "enter_scope" to create a scope. The return value is the ID of that scope.

      int32_t scope_id = env->enter_scope (env);
      

      Use "leave_scope" to leave the scope. For the argument, it is necessary to specify the scope ID obtained in "enter_scope".

      env->leave_scope(env, scope_id);
      

      Use "remove_mortal" to remove the object from the mortal stack. For the argument, specify the scope ID obtained by "enter_scope" and the object you want to remove. The object is removed from the mortal stack and the reference count is automatically decremented by 1. When the reference count reaches 0, it is released.

      env->remove_mortal(env, scope_id, object);
      

      Information about the mortal stack is stored in env.

      Exception in Native Subroutine

      In the Native Subroutine, it is the return value that indicates whether an exception has occurred.

      return SPVM_SUCCESS;
      
      return SPVM_EXCEPTION;
      

      If no exception occurs, "SPVM_SUCCESS" is returned. This is defined as "0".

      If an exception occurs, "SPVM_EXCEPTION" is returned. It is defined as a value other than "0".

      If you want to set the exception message yourself, you can create an exception message with "new_string" and set it with "set_exception".

      env->set_exception(env, env->new_string(env, "Exception occur");
      return SPVM_EXCEPTION;
      

      If no exception message is set, a default exception message will be set.

      Usually, "SPVM_DIE" is defined to make it easier to use, so it is better to use this.

      SPVM_DIE ("Error. Values must be %d and %d", 3, 5, "Foo/Bar.c", __LINE__);
      

      SPVM_DIE can be used in the same way as the C language sprintf function. Be sure to include this file name in the second from the end, and the line number in the last argument. If the message exceeds 255 bytes, the excess is truncated.

      The exception is stored in env.

      Pointer Type

      There is a type called pointer type in SPVM, but I will explain how to use it.

      The pointer type definition specifies the pointer_t descriptor in the SPVM package definition. Pointer types cannot have field definitions. This example describes how to use the C standard "struct tm" as a pointer type.

      # MyTimeInfo.spvm
      package MyTimeInfo : pointer_t {
      
        # Constructor
        native sub new : MyTimeInfo ();
      
        # Get second
        native sub sec : int ($self : self);
      
        # Destructor
        native sub DESTROY : ($self : self);
      }
      

      It defines a new constructor, a method that takes seconds information called sec, and a destructor called DESTROY. These are Native Subroutine.

      Next is the definition on the C language side.

      # MyTimeInfo.c
      
      int32_t SPNATIVE__MyTimeInfo__new(SPVM_ENV* env, SPVM_VALUE* stack) {
      
        // Alloc strcut tm
        void* tm_ptr = env->alloc_memory_block_zero (sizeof (struct tm));
      
        // Create strcut tm instance
        void* tm_obj = env->new_pointer(env, "MyTimeInfo", tm_ptr);
      
        stack[0].oval = tm_obj;
      
        return SPVM_SUCCESS;
      }
      
      int32_t SPNATIVE__MyTimeInfo__sec(SPVM_ENV* env, SPVM_VALUE* stack) {
        void* tm_obj = stack[0].oval;
      
        strcut tm* tm_ptr = (struct tm*) env->get_pointer(env, tm_obj);
      
        stack[0].ival = tm_ptr-> tm_sec;
      
        return SPVM_SUCCESS;
      }
      
      int32_t SPNATIVE__MyTimeInfo__DESTROY(SPVM_ENV* env, SPVM_VALUE* stack) {
      
        void* tm_obj = stack[0].oval;
        strcut tm* tm_ptr = (struct tm*) env->get_pointer(env, tm_obj);
      
        env->free_memory_block (tm_ptr);
      
        return SPVM_SUCCESS;
      }
      

      In the constructor new, the memory of "struct tm" is first allocated by the alloc_memory_block_zero function. This is a function that reserves one memory block in SPVM. Similar to malloc, this function increments the memory block count by one, making it easier to spot memory leaks.

      // Alloc strcut tm
      void* tm_ptr = env->alloc_memory_block_zero (sizeof (struct tm));
      

      Next, use the new_pointer function to create a new pointer type object with MyTimeInfo associated with it in the allocated memory.

      // Create strcut tm instance
      void* tm_obj = env->new_pointer(env, "MyTimeInfo", tm_ptr);
      

      If you return this as a return value, the constructor is complete.

      stack[0].ival = tm_ptr-> tm_sec;
      
      return SPVM_SUCCESS;
      

      Next, let's get the value of tm_sec. sec method. The get_pointer function can be used to get a pointer to the memory allocated as a "struct tm" from a pointer type object.

      void* tm_obj = stack[0].oval;
      
      strcut tm* tm_ptr = (struct tm*) env->get_pointer(env, tm_obj);
      
      stack[0].ival = tm_ptr-> tm_sec;
      

      The last is the destructor. Be sure to define a destructor, as the allocated memory will not be released automatically.

      int32_t SPNATIVE__MyTimeInfo__DESTROY(SPVM_ENV* env, SPVM_VALUE* stack) {
      
        void* tm_obj = stack[0].oval;
      
        strcut tm* tm_ptr = (struct tm*) env->get_pointer(env, tm_obj);
      
        env->free_memory_block (tm_ptr);
      
        return SPVM_SUCCESS;
      }
      

      Execute the free_memory_block function to free the memory. Be sure to free the memory allocated by alloc_memory_block_zero with the free_memory_block function. Releases the memory and decrements the memory block count by one.

      Native API index

      The Native API has an index that corresponds to the name. This number is permanently maintained for binary compatibility with Native Subroutine. When adding a new API, it will be added at the end.

      0 package_vars_heap
      1 object_header_byte_size
      2 object_weaken_backref_head_offset
      3 object_ref_count_offset
      4 object_basic_type_id_offset
      5 object_type_dimension_offset
      6 object_runtime_type_category_offset
      7 object_flag_offset
      8 object_length_offset
      9 byte_object_basic_type_id
      10 short_object_basic_type_id
      11 int_object_basic_type_id
      12 long_object_basic_type_id
      13 float_object_basic_type_id
      14 double_object_basic_type_id
      15 compiler
      16 exception_object
      17 native_mortal_stack
      18 native_mortal_stack_top
      19 native_mortal_stack_capacity
      20 get_basic_type_id
      21 get_field_id
      22 get_field_offset
      23 get_package_var_id
      24 get_sub_id
      25 get_method_sub_id
      26 new_object_raw
      27 new_object
      28 new_byte_array_raw
      29 new_byte_array
      30 new_short_array_raw
      31 new_short_array
      32 new_int_array_raw
      33 new_int_array
      34 new_long_array_raw
      35 new_long_array36    new_float_array_raw
      37 new_float_array
      38 new_double_array_raw
      39 new_double_array
      40 new_object_array_raw
      41 new_object_array
      42 new_muldim_array_raw
      43 new_muldim_array
      44 new_mulnum_array_raw
      45 new_mulnum_array
      46 new_string_raw
      47 new_string
      48 new_string_len_raw
      49 new_string_len
      50 new_pointer_raw
      51 new_pointer
      52 concat_raw
      53 concat
      54 new_stack_trace_raw
      55 new_stack_trace
      56 length
      57 get_elems_byte
      58 get_elems_short
      59 get_elems_int
      60 get_elems_long
      61 get_elems_float
      62 get_elems_double
      63 get_elem_object
      64 set_elem_object
      65 get_field_byte
      66 get_field_short
      67 get_field_int
      68 get_field_long
      69 get_field_float
      70 get_field_double
      71 get_field_object
      72 set_field_byte
      73 set_field_short
      74 set_field_int
      75 set_field_long
      76 set_field_float
      77 set_field_double
      78 set_field_object
      79 get_package_var_byte
      80 get_package_var_short
      81 get_package_var_int
      82 get_package_var_long
      83 get_package_var_float
      84 get_package_var_double
      85 get_package_var_object
      86 set_package_var_byte
      87 set_package_var_short
      88 set_package_var_int
      89 set_package_var_long
      90 set_package_var_float
      91 set_package_var_double
      92 set_package_var_object
      93 get_pointer
      94 set_pointer
      95 call_sub
      96 get_exception
      97 set_exception
      98 get_ref_count
      99 inc_ref_count
      100 dec_ref_count
      101 enter_scope
      102 push_mortal
      103 leave_scope
      104 remove_mortal
      105 is_type
      106 has_callback
      107 get_object_basic_type_id
      108 get_object_type_dimension
      109 weaken
      110 isweak
      111 unweaken
      112 alloc_memory_block_zero
      113 free_memory_block
      114 get_memory_blocks_count
      115 get_type_name_raw
      116 get_type_name
      117 new_env
      118 free_env
      119 memry_blocks_count
      

      Call Native API

      Native API can be called from "SPVM_ENV* env" passed as an argument. Note that you have to pass env as the first argument.

      int32_t basic_type_id = env->get_basic_type_id(env, "SPVM::Int");
      

      List of Native APIs

      package_vars_heap

      the pointer to the storage area of the package variables. It is used internally.

      object_header_byte_size

      The byte size of the object's header. It is used internally.

      object_weaken_backref_head_offset

      Offset to a pointer to the back reference of the weak reference in the object structure. It is used internally.

      object_ref_count_offset

      Reference count offset in the object structure. It is used internally.

      object_basic_type_id_offset

      Offset of basic type ID in object structure. It is used internally.

      object_type_dimension_offset

      Offset of type dimension in object structure. It is used internally.

      object_runtime_type_category_offset

      Offset of runtime type category in object structure. It is used internally.

      object_flag_offset

      Offset of flag in object structure. It is used internally.

      object_length_offset

      The length offset in the object structure. It is used internally.

      byte_object_basic_type_id

      Basic type ID of SPVM::Byte type. It is used internally.

      short_object_basic_type_id

      ID of the base type of SPVM::Short type. It is used internally.

      int_object_basic_type_id

      ID of the base type of SPVM::Int type. It is used internally.

      long_object_basic_type_id

      ID of the base type of SPVM::Long type. It is used internally.

      float_object_basic_type_id

      ID of the base type of SPVM::Float type. It is used internally.

      double_object_basic_type_id

      ID of the base type of SPVM::Double type. It is used internally.

      compiler

      A pointer to the SPVM compiler. It is used internally.

      exception_object

      Exception object. It is used internally.

      native_mortal_stack

      Mortal stack used for native calls. It is used internally.

      native_mortal_stack_top

      The top position of the mortal stack used for native calls. It is used internally.

      native_mortal_stack_capacity

      The amount of mortal stack used for native calls. It is used internally.

      get_basic_type_id

      Get the ID of the base type given the name of the base type. If it does not exist, a value less than 0 is returned.

      int32_t (*get_basic_type_id)(SPVM_ENV* env, const char* basic_type_name);
      

      Example:

      int32_t basic_type_id = env->get_basic_type_id(env, "SPVM::Int");
      

      get_field_id

      Get the ID of the field given the package name, field name, and signature. If the field does not exist, a value less than 0 is returned.

      int32_t (*get_field_id)(SPVM_ENV* env, const char* package_name, const char* field_name, const char* signature);
      

      The signature is the same as the field type name.

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "int");
      

      get_field_offset

      Gets the offset of the field given the field ID. The field ID must be a valid field ID obtained with the field_id function.

      int32_t (*get_field_offset)(SPVM_ENV* env, int32_t field_id);
      

      get_package_var_id

      Get the package variable ID given the package name, package variable name and signature. If the package variable does not exist, a value less than 0 is returned.

      int32_t (*get_package_var_id)(SPVM_ENV* env, const char* package_name, const char* package_var_name, const char* signature);
      

      The signature is the same as the package variable type name.

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "int");
      

      get_sub_id

      Get the subroutine ID by specifying the package name, subroutine name, and signature. If no subroutine exists, a value less than 0 is returned.

      int32_t (*get_sub_id)(SPVM_ENV* env, const char* package_name, const char* sub_name, const char* signature);
      

      The signature has the following format: Must not contain white space.

      Return value type name (argument type name 1, argument type name 2, ...)
      

      Example:

      int32_t sub_id = env->get_sub_id(env, "Foo", "func", "int (long, string)");
      

      get_method_sub_id

      int32_t (*get_method_sub_id)(SPVM_ENV* env, void* object, const char* method_name, const char* signature);
      

      Get the subroutine ID by specifying the object and method name. If the method does not exist, a value less than 0 is returned.

      The signature is the same as the sub_id signature.

      Example:

      int32_t sub_id = env->get_method_sub_id(env, object, "method", "int(self,long,string)");
      

      new_object_raw

      Generates a new object with a base type ID. The base type ID must be the correct base type ID obtained by the "basic_type_id function".

      void* (*new_object_raw)(SPVM_ENV* env, int32_t basic_type_id);
      

      This function does not add objects to the mortal stack, so use new_object to avoid memory leaks for normal use.

      new_object

      Generates and returns a new object with a base type ID. The base type ID must be the correct base type ID obtained in the basic_type_id. Adds a newly generated object to the mortal stack.

      void* (*new_object)(SPVM_ENV* env, int32_t basic_type_id);
      

      Sample:

      int32_t basic_type_id = env-&gt;get_basic_type_id(env,"SPVM::Int");
      void* object = env-&gt;new_object(env, basic_type_id);
      

      new_byte_array_raw

      Generates a new "byte[] type" object by specifying the length of the array. The initial value of all elements is 0.

      void* (*new_byte_array_raw)(SPVM_ENV* env, int32_t length);
      

      This function does not add objects to the mortal stack, so use new_byte_array to avoid memory leaks for normal use.

      new_byte_array

      Generates and returns a new "byte[] type" object with the length of the array. The initial value of all elements is 0. Adds a newly generated object to the mortal stack.

      void* (*new_byte_array)(SPVM_ENV* env, int32_t length);
      

      Sample:

      void* byte_array_obj = env-&gt;new_byte_array(env, 100);
      

      new_short_array_raw

      Generates a new "short[] type" object by specifying the length of the array. The initial value of all elements is 0.

      void* (*new_short_array_raw)(SPVM_ENV* env, int32_t length);
      

      This function does not add objects to the mortal stack, so use new_short_array to avoid memory leaks for normal use.

      new_short_array

      Generates and returns a new "short[] type" object with the length of the array. The initial value of all elements is 0. Adds a newly generated object to the mortal stack.

      void* (*new_short_array)(SPVM_ENV* env, int32_t length);
      

      Sample:

      void* short_array_obj = env-&gt;new_short_array(env, 100);
      

      new_int_array_raw

      Generates a new "int[] type" object by specifying the length of the array. The initial value of all elements is 0.

      void* (*new_int_array_raw)(SPVM_ENV* env, int32_t length);
      

      This function does not add objects to the mortal stack, so normal use should use new_int_array to avoid memory leaks.

      new_int_array

      Generates and returns a new "int[] type" object with the length of the array. The initial value of all elements is 0. Adds a newly generated object to the mortal stack.

      void* (*new_int_array)(SPVM_ENV* env, int32_t length);
      

      Sample:

      void* int_array_obj = env-&gt;new_int_array(env, 100);
      

      new_long_array_raw

      Creates a new "long[] type" object by specifying the length of the array. The initial value of all elements is 0.

      void* (*new_long_array_raw)(SPVM_ENV* env, int32_t length);
      

      This function does not add objects to the mortal stack, so use normal_new_long_array to avoid memory leaks.

      new_long_array

      Create a new "long[] type" object by specifying the length of the array and return it. The initial value of all elements is 0. Add the newly created object to the mortal stack.

      void* (*new_long_array)(SPVM_ENV* env, int32_t length);
      

      Example:

      void* long_array_obj = env->new_long_array(env, 100);
      

      new_float_array_raw

      Create a new "float[] type" object by specifying the length of the array. The initial value of all elements is 0.

      void* (*new_float_array_raw)(SPVM_ENV* env, int32_t length);
      

      This function does not add any objects to the mortal stack, so use new_float_array for normal use to avoid memory leaks.

      new_float_array

      Create a new "float[] type" object by specifying the length of the array and return it. The initial value of all elements is 0. Add the newly created object to the mortal stack.

      void* (*new_float_array)(SPVM_ENV* env, int32_t length);
      

      Example:

      void* float_array_obj = env->new_float_array(env, 100);
      

      new_double_array_raw

      Creates a new "double[]" object by specifying the length of the array. The initial value of all elements is 0.

      void* (*new_double_array_raw)(SPVM_ENV* env, int32_t length);
      

      This function does not add any objects to the mortal stack, so use normal_new_double_array to avoid memory leaks.

      new_double_array

      Generate a new "double[] type" object by specifying the length of the array and return it. The initial value of all elements is 0. Add the newly created object to the mortal stack.

      void* (*new_double_array)(SPVM_ENV* env, int32_t length);
      

      Example:

      void* double_array_obj = env->new_double_array(env, 100);
      

      new_object_array_raw

      Create a new object type array by specifying the basic type ID and array length and return it. The basic type ID must be the correct basic type ID obtained with the "basic_type_id function". The initial value of all elements is null.

      void* (*new_object_array_raw)(SPVM_ENV* env, int32_t basic_type_id, int32_t length);
      

      This function does not add objects to the mortal stack, so use normal_new_object_array to avoid memory leaks.

      new_object_array

      Create a new object type array by specifying the basic type ID and array length and return it. The basic type ID must be the correct basic type ID obtained with the "basic_type_id function". The initial value of all elements is null. Add the newly created object to the mortal stack.

      void* (*new_object_array)(SPVM_ENV* env, int32_t basic_type_id, int32_t length);
      

      Example:

      int32_t basic_type_id = env->get_basic_type_id(env, "SPVM::Int");
      void* object_array_obj = env->new_object_array(env, basic_type_id, 100);
      

      new_muldim_array_raw

      Generates and returns a new multidimensional object type array by specifying the basic type ID, element type dimension, and array length. The basic type ID must be the correct basic type ID obtained with the "basic_type_id function". The initial value of all elements is null.

      void* (*new_muldim_array_raw)(SPVM_ENV* env, int32_t basic_type_id, int32_t element_dimension, int32_t length);
      

      This function does not add any objects to the mortal stack, so use new_muldim_array for normal use to avoid memory leaks.

      new_muldim_array

      Generates and returns a new multidimensional object type array by specifying the basic type ID, element type dimension, and array length. The basic type ID must be the correct basic type ID obtained with the "basic_type_id function". The initial value of all elements is null. Add the newly created object to the mortal stack.

      void* (*new_muldim_array_raw)(SPVM_ENV* env, int32_t basic_type_id, int32_t element_dimension, int32_t length);
      

      Element type dimensions must be less than 255.

      Example:

      // new SPVM::Int[][][100]
      int32_t basic_type_id = env->get_basic_type_id(env, "SPVM::Int");
      void* multi_array_obj = env->new_muldim_array(env, basic_type_id, 2, 100);
      

      new_mulnum_array_raw

      Generate a new multi-numeric array by specifying the basic type ID and array length and return it. The basic type ID must be the correct basic type ID acquired by the "basic_type_id function" and must be valid as a composite numeric type. The initial value of all fields for all elements is 0.

      void* (*new_mulnum_array_raw)(SPVM_ENV* env, int32_t basic_type_id, int32_t length);
      

      This function does not add any objects to the mortal stack, so use new_mulnum_array for normal use to avoid memory leaks.

      new_mulnum_array

      Generate a new multi-numeric array by specifying the basic type ID and array length and return it. The basic type ID must be the correct basic type ID acquired by the "basic_type_id function" and must be valid as a composite numeric type. The initial value of all fields for all elements is 0.

      void* (*new_mulnum_array)(SPVM_ENV* env, int32_t basic_type_id, int32_t length);
      

      Example:

      int32_t basic_type_id = env->get_basic_type_id(env, "SPVM::Complex_2d");
      void* value_array_obj = env->new_mulnum_array(env, basic_type_id, 100);
      

      new_string_raw

      Specify a C language string to generate a string type object and return it. The string must end with "\0".

      void* (*new_string_raw)(SPVM_ENV* env, const char* bytes);
      

      This function does not add any objects to the mortal stack, so for normal use use new_string to avoid memory leaks.

      new_string

      Specify a C language string to generate a string type object and return it. The string must end with "\0". Add the newly created object to the mortal stack.

      void* (*new_string)(SPVM_ENV* env, const char* bytes);
      

      Example:

      void* str_obj = env->new_string(env, "Hello World");
      

      new_string_len_raw

      Specify a C language string and length to generate a string type object and return it.

      void* (*new_string_len_raw)(SPVM_ENV* env, const char* bytes, int32_t length);
      

      This function does not add any objects to the mortal stack, so for normal use use new_string_len to avoid memory leaks.

      new_string_len

      Generates and returns a character string type object by specifying the character string and length in C language. Add the newly created object to the mortal stack.

      void* (*new_string_len)(SPVM_ENV* env, const char* bytes, int32_t length);
      

      Example:

      void* str_obj = env->new_string_len(env, "Hello \0World", 11);
      

      new_pointer_raw

      Specify a basic type ID and a C language pointer to create a pointer type object and return it. The basic type ID must be the correct basic type ID acquired by the "basic_type_id function" and valid as a pointer type.

      void* (*new_pointer_raw)(SPVM_ENV* env, int32_t basic_type_id, void* pointer);
      

      This function does not add any objects to the mortal stack, so for normal use use new_pointer to avoid memory leaks.

      new_pointer

      Specify a basic type ID and a C language pointer to create a pointer type object and return it. The basic type ID must be the correct basic type ID acquired by the "basic_type_id function" and valid as a pointer type. Add the newly created object to the mortal stack.

      void* (*new_pointer)(SPVM_ENV* env, int32_t basic_type_id, void* pointer);
      

      Example:

      void* pointer = malloc (sizeof (struct tm));
      void* pointer_obj = env->new_pointer(env, "MyTimeInfo", pointer);
      

      See Using pointer types for a detailed sample.

      concat_raw

      Returns a new byte[] type object that is a concatenation of two byte[] type strings.

      void* (*concat_raw)(SPVM_ENV* env, void* string1, void* string2);
      

      This function does not add objects to the mortal stack, so use concat for normal use to avoid memory leaks.

      concat

      Returns a new byte[] type object that is a concatenation of two byte[] type strings. Add the newly created object to the mortal stack.

      void* (*concat)(SPVM_ENV* env, void* string1, void* string2);
      

      new_stack_trace_raw

      If you specify a byte[] type exception message and a package name, subroutine name, file name and line number, the character string of the package name, subroutine name, file name and line number is added to the end of the byte[] type exception message. The added character string will be returned.

      void* (*new_stack_trace_raw)(SPVM_ENV* env, void* exception, const char* package_name, const char* sub_name, const char* file, int32_t line);
      

      This function does not add objects to the mortal stack, use new_stack_trace to avoid memory leaks for normal use.

      new_stack_trace

      When a byte[] type exception message and a package name, subroutine name, file name and line number are specified, the string of the package name, subroutine name, file name and line number is added to the end of the string type exception message. Returns a new string type object. Add the newly created object to the mortal stack.

      void* (*new_stack_trace)(SPVM_ENV* env, void* exception, const char* package_name, const char* sub_name, const char* file, int32_t line);
      

      length

      If you specify an array, the length of the array is returned.

      int32_t (*length)(SPVM_ENV*, void* array);
      

      Example:

      int32_t length = env->length(env, array);
      

      get_elems_byte

      If you specify a byte[] type array, the pointer at the beginning of the internally stored C language int8_t[] type array is returned.

      int8_t* (*get_elems_byte)(SPVM_ENV* env, void* array);
      

      Example:

      int8_t* values ​​= env->get_elems_byte(env, array);
      values ​​[3] = 5;
      

      get_elems_short

      If a short[] type array is specified, the pointer at the beginning of the internally stored C language int16_t[] type array is returned.

      int16_t* (*get_elems_short)(SPVM_ENV* env, void* array);
      

      Example:

      int16_t* values ​​= env->get_elems_short(env, array);
      values ​​[3] = 5;
      

      get_elems_int

      When an int[] type array is specified, the pointer at the beginning of the internally stored C language int32_t[] type array is returned.

      int32_t* (*get_elems_int)(SPVM_ENV* env, void* array);
      

      Example:

      int32_t* values ​​= env->get_elems_int(env, array);
      values ​​[3] = 5;
      

      get_elems_long

      When a long[] type array is specified, the pointer at the beginning of the internally stored C language int64_t[] type array is returned.

      int64_t* (*get_elems_long)(SPVM_ENV* env, void* array);
      

      Example:

      int64_t* values ​​= env->get_elems_long(env, array);
      values ​​[3] = 5;
      

      get_elems_float

      When a float[] type array is specified, the pointer at the beginning of the C language float[] type array internally held is returned.

      float* (*get_elems_float)(SPVM_ENV* env, void* array);
      

      Example:

      float* values ​​= env->get_elems_float(env, array);
      values ​​[3] = 1.5f;
      

      get_elems_double

      If a double[] type array is specified, the pointer at the beginning of the internally stored C double[] type array is returned.

      double* (*get_elems_double)(SPVM_ENV* env, void* array);
      

      Example:

      double* values ​​= env->get_elems_double(env, array);
      values ​​[3] = 1.5;
      

      get_elem_object

      Gets an object of an element given an array of object types and a subscript. If the element is a weak reference, the weak reference is removed.

      void* (*get_elem_object)(SPVM_ENV* env, void* array, int32_t index);
      

      Example:

      void* object = env->get_elem_object(env, array, 3);
      

      set_elem_object

      If you specify an array of object type and subscript and element objects, the element object is assigned to the corresponding subscript position. If the element's object has a weak reference, the weak reference is removed. The reference count of the originally assigned object is decremented by 1.

      void (*set_elem_object)(SPVM_ENV* env, void* array, int32_t index, void* value);
      

      Example:

      env->get_elem_object(env, array, 3, object);
      

      get_field_byte

      If an object and field ID are specified, the byte field value will be returned as a C language int8_t type value. The field ID must be a valid field ID obtained with the field_id function.

      int8_t (*get_field_byte)(SPVM_ENV* env, void* object, int32_t field_id);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "byte");
      int8_t field_value = env->get_field_byte(env, object, field_id);
      

      get_field_short

      If you specify the object and field ID, the value of the short type field will be returned as the int16_t type value of C language. The field ID must be a valid field ID obtained with the field_id function.

      int16_t (*get_field_short)(SPVM_ENV* env, void* object, int32_t field_id);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "short");
      int16_t field_value = env->get_field_short(env, object, field_id);
      

      get_field_int

      If an object and a field ID are specified, the value of the int type field will be returned as a C language int32_t type value. The field ID must be a valid field ID obtained with the field_id function.

      int32_t (*get_field_int)(SPVM_ENV* env, void* object, int32_t field_id);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "int");
      int32_t field_value = env->get_field_int(env, object, field_id);
      

      get_field_long

      If you specify the object and field ID, the value of the long type field will be returned as the value of int64_t type of C language. The field ID must be a valid field ID obtained with the field_id function.

      int64_t (*get_field_long)(SPVM_ENV* env, void* object, int32_t field_id);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "long");
      int64_t field_value = env->get_field_long(env, object, field_id);
      

      get_field_float

      If you specify the object and field ID, the value of the float type field will be returned as a C language float type value. The field ID must be a valid field ID obtained with the field_id function.

      float (*get_field_float)(SPVM_ENV* env, void* object, int32_t field_id);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "float");
      float field_value = env->get_field_float(env, object, field_id);
      

      get_field_double

      If you specify the object and field ID, the value of the double type field will be returned as a double type value in C language. The field ID must be a valid field ID obtained with the field_id function.

      double (*get_field_double)(SPVM_ENV* env, void* object, int32_t field_id);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "double");
      double field_value = env->get_field_double(env, object, field_id);
      

      get_field_object

      If you specify the object and field ID, the value of the object type field is returned as a void* type value in C language. The field ID must be a valid field ID obtained with the field_id function. If the field is a weak reference, it will be removed.

      void* (*get_field_object)(SPVM_ENV* env, void* object, int32_t field_id);
      
      int32_t field_id = env->get_field_id(env, "Foo", "x", "SPVM::Int");
      void* field_value = env->get_field_object(env, object, field_id);
      

      set_field_byte

      If you specify the object and field ID and the value of the field, the value is set to the byte type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_field_byte)(SPVM_ENV* env, void* object, int32_t field_id, int8_t value);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "byte");
      int8_t field_value = 5;
      env->set_field_byte(env, object, field_id, field_value);
      

      set_field_short

      If you specify the object and field ID and the value of the field, the value is set to the short type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_field_short)(SPVM_ENV* env, void* object, int32_t field_id, int16_t value);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "short");
      int16_t field_value = 5;
      env->set_field_short(env, object, field_id, field_value);
      

      set_field_int

      If you specify the object and field ID and the value of the field, the value is set to the int type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_field_int)(SPVM_ENV* env, void* object, int32_t field_id, int32_t value);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "int");
      int32_t field_value = 5;
      env->set_field_int(env, object, field_id, field_value);
      

      set_field_long

      If you specify the object and field ID and the value of the field, the value is set to the long type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_field_long)(SPVM_ENV* env, void* object, int32_t field_id, int64_t value);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "long");
      int64_t field_value = 5;
      env->set_field_long(env, object, field_id, field_value);
      

      set_field_float

      If you specify the object and field ID and the value of the field, the value is set to the float type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_field_float)(SPVM_ENV* env, void* object, int32_t field_id, float value);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "float");
      float field_value = 1.5f;
      env->set_field_float(env, object, field_id, field_value);
      

      set_field_double

      If you specify the object and field ID and the value of the field, the value is set to the double type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_field_double)(SPVM_ENV* env, void* object, int32_t field_id, double value);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "double");
      double field_value = 1.55;
      env->set_field_double(env, object, field_id, field_value);
      

      set_field_object

      Object and field Specify the ID and the value of the field and set the value to the object type field. The field ID must be a valid field ID obtained with the field_id function. After setting, the reference count is incremented by 1. The original value has the reference count decremented by 1.

      void (*set_field_object)(SPVM_ENV* env, void* object, int32_t field_id, void* value);
      

      Example:

      int32_t field_id = env->get_field_id(env, "Foo", "x", "SPVM::Int");
      int32_t basic_type_id = env->get_basic_type_id(env, "SPVM::Int");
      void* object = env->new_object(env, basic_type_id);
      env->set_field_object(env, object, field_id, object);
      

      get_package_var_byte

      If an object and a package variable ID are specified, the value of the byte type package variable is returned as a C language int8_t type value. The package variable ID must be a valid package variable ID obtained with the field_id function.

      int8_t (*get_package_var_byte)(SPVM_ENV* env, int32_t pkgvar_id);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "byte");
      int8_t pkgvar_value = env->get_package_var_byte(env, object, pkgvar_id);
      

      get_package_var_short

      If an object and a package variable ID are specified, the value of the short type package variable will be returned as a C language int16_t type value. The package variable ID must be a valid package variable ID obtained with the field_id function.

      int16_t (*get_package_var_short)(SPVM_ENV* env, int32_t pkgvar_id);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "short");
      int16_t pkgvar_value = env->get_package_var_short(env, object, pkgvar_id);
      

      get_package_var_int

      If an object and a package variable ID are specified, the value of the int type package variable will be returned as a C language int32_t type value. The package variable ID must be a valid package variable ID obtained with the field_id function.

      int32_t (*get_package_var_int)(SPVM_ENV* env, int32_t pkgvar_id);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "int");
      int32_t pkgvar_value = env->get_package_var_int(env, object, pkgvar_id);
      

      get_package_var_long

      If an object and a package variable ID are specified, the value of the long type package variable will be returned as a C language int64_t type value. The package variable ID must be a valid package variable ID obtained with the field_id function.

      int64_t (*get_package_var_long)(SPVM_ENV* env, int32_t pkgvar_id);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "long");
      int64_t pkgvar_value = env->get_package_var_long(env, object, pkgvar_id);
      

      get_package_var_float

      If an object and a package variable ID are specified, the value of the float type package variable will be returned as a C language float type value. The package variable ID must be a valid package variable ID obtained with the field_id function.

      float (*get_package_var_float)(SPVM_ENV* env, int32_t pkgvar_id);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "float");
      float pkgvar_value = env->get_package_var_float(env, object, pkgvar_id);
      

      get_package_var_double

      If you specify an object and a package variable ID, the value of the double type package variable is returned as a C type double type value. The package variable ID must be a valid package variable ID obtained with the field_id function.

      double (*get_package_var_double)(SPVM_ENV* env, int32_t pkgvar_id);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "double");
      double pkgvar_value = env->get_package_var_double(env, object, pkgvar_id);
      

      get_package_var_object

      When an object and a package variable ID are specified, the value of the object type package variable is returned as a C language void* type value. The package variable ID must be a valid package variable ID obtained with the field_id function.

      void* (*get_package_var_object)(SPVM_ENV* env, int32_t pkgvar_id);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "SPVM::Int");
      void* pkgvar_value = env->get_package_var_byte(env, object, pkgvar_id);
      

      set_package_var_byte

      If you specify the object and field ID and the value of the field, the value is set to the byte type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_package_var_byte)(SPVM_ENV* env, int32_t pkgvar_id, int8_t value);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "byte");
      int8_t pkgvar_value = 5;
      env->set_package_var_byte(env, pkgvar_id, pkgvar_value);
      

      set_package_var_short

      If you specify the object and field ID and the value of the field, the value is set to the short type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_package_var_short)(SPVM_ENV* env, int32_t pkgvar_id, int16_t value);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "short");
      int16_t pkgvar_value = 5;
      env->set_package_var_short(env, pkgvar_id, pkgvar_value);
      

      set_package_var_int

      If you specify the object and field ID and the value of the field, the value is set to the int type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_package_var_int)(SPVM_ENV* env, int32_t pkgvar_id, int32_t value);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "int");
      int32_t pkgvar_value = 5;
      env->set_package_var_int(env, pkgvar_id, pkgvar_value);
      

      set_package_var_long

      If you specify the object and field ID and the value of the field, the value is set to the long type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_package_var_long)(SPVM_ENV* env, int32_t pkgvar_id, int64_t value);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "long");
      int64_t pkgvar_value = 5;
      env->set_package_var_long(env, pkgvar_id, pkgvar_value);
      

      set_package_var_float

      If you specify the object and field ID and the value of the field, the value is set to the float type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_package_var_float)(SPVM_ENV* env, int32_t pkgvar_id, float value);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "float");
      float pkgvar_value = 5;
      env->set_package_var_float(env, pkgvar_id, pkgvar_value);
      

      set_package_var_double

      If you specify the object and field ID and the value of the field, the value is set to the double type field. The field ID must be a valid field ID obtained with the field_id function.

      void (*set_package_var_double)(SPVM_ENV* env, int32_t pkgvar_id, double value);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "double");
      double pkgvar_value = 5;
      env->set_package_var_double(env, pkgvar_id, pkgvar_value);
      

      set_package_var_object

      Object and field Specify the ID and the value of the field and set the value to the object type field. The field ID must be a valid field ID obtained with the field_id function. After setting, the reference count is incremented by 1. The original value has the reference count decremented by 1.

      void (*set_package_var_object)(SPVM_ENV* env, int32_t pkgvar_id, void* value);
      

      Example:

      int32_t pkgvar_id = env->get_package_var_id(env, "Foo", "$VAR", "SPVM::Int");
      int32_t basic_type_id = env->get_basic_type_id(env, "SPVM::Int");
      void* object = env->new_object(env, basic_type_id);
      env->set_package_var_object(env, pkgvar_id, pkgvar_value);
      

      get_pointer

      Specify a pointer type object and return the C language pointer stored inside the object.

      void* (*get_pointer)(SPVM_ENV* env, void* pointer_object);
      

      Example:

      strcut tm* tm_ptr = (struct tm*) env->get_pointer(env, tm_obj);
      

      See Using pointer types for a detailed sample.

      set_pointer

      If you specify a pointer type object and a C language pointer, the C language pointer is saved in the internal data of the pointer type object.

      void (*set_pointer)(SPVM_ENV* env, void* pointer_object, void* pointer);
      

      call_sub

      Call the subroutine by specifying the subroutine ID and argument. The return value is non-zero when an exception occurs in the subroutine, 0 is returned when the exception does not occur.

      int32_t (*call_sub)(SPVM_ENV* env, int32_t sub_id, SPVM_VALUE* args);
      

      The return value of the subroutine is set to "args[0]".

      get_exception

      Returns the byte[] type object saved as an exception.

      void* (*get_exception)(SPVM_ENV* env);
      

      set_exception

      If you specify an object of type byte[], it will be saved as an exception.

      void (*set_exception)(SPVM_ENV* env, void* exception);
      

      get_ref_count

      int32_t (*get_ref_count)(SPVM_ENV* env, void* object);
      

      inc_ref_count

      Specifying an object increments the reference count of the object.

      void (*inc_ref_count)(SPVM_ENV* env, void* object);
      

      Use this method only if you have a specific reason to use it. Normally, the reference count is managed automatically.

      dec_ref_count

      Specifying an object decrements the object's reference count by 1. When the reference count reaches 0, the object is released.

      void (*dec_ref_count)(SPVM_ENV* env, void* object);
      

      Use this method only if you have a specific reason to use it. Normally, the reference count is managed automatically.

      enter_scope

      Create a new scope and return the scope ID.

      int32_t (*enter_scope)(SPVM_ENV* env);
      

      push_mortal

      Add an object to the mortal stack.

      int32_t (*push_mortal)(SPVM_ENV* env, void* object);
      

      If this method succeed, return 0.

      If this method don't alloc memory for new mortal information, return 1.

      leave_scope

      Specify a scope ID to exit that scope and decrement the object's reference count stored in the mortal stack. Objects with a reference count of 0 are released. The scope ID must be the ID obtained by the enter_scope function.

      void (*leave_scope)(SPVM_ENV* env, int32_t scope_id);
      

      remove_mortal

      Given a scope ID and an object, delete the specified object from the mortal stack.

      int32_t (*remove_mortal)(SPVM_ENV* env, int32_t scope_id, void* remove_object);
      

      is_type

      Given an object and a base type ID and a type dimension, returns a nonzero value if the object matches both the base type ID and the type dimension, and 0 otherwise.

      int32_t (*is_type)(SPVM_ENV* env, void* object, int32_t basic_type_id, int32_t type_dimension);
      

      has_callback

      Given a base type id for the object and the callback type, returns a non-zero value if the object conforms to the callback type, and zero otherwise.

      int32_t (*has_callback)(SPVM_ENV* env, void* object, int32_t callback_basic_type_id);
      

      get_object_basic_type_id

      Gets the base type ID of the object.

      int32_t (*get_object_basic_type_id)(SPVM_ENV* env, void* object);
      

      get_object_type_dimension

      Gets the dimension of the type of object.

      int32_t (*get_object_type_dimension)(SPVM_ENV* env, void* object);
      

      weaken

      int32_t (*weaken)(SPVM_ENV* env, void** object_address);
      

      Create weak reference to the object which is specified by object address.

      The reference count of the object is decrimented by 1 and weaken flag is added to the object address.

      If the reference count is 1, "dec_ref_count" is called to the object.

      If object_address is NULL, this method do nothing.

      If the object is already weaken, this method do nothing.

      This method allocate memory internally to add the back reference from the object to the object address.

      This method success return 0.

      If failing memory allocation of back reference, return 1.

      isweak

      Given the address of an object, returns non-zero if the object is a weak reference, 0 otherwise.

      int32_t (*isweak()SPVM_ENV* env, void** object);
      

      unweaken

      Specifying the address of the object releases the weak reference to the object.

      void (*unweaken)(SPVM_ENV* env, void** object_address);
      

      alloc_memory_block_zero

      void* (*alloc_memory_block_zero)(SPVM_ENV* env, int64_t byte_size);
      

      If you specify the size in bytes, the memory block is allocated and the pointer of the allocated memory block is returned. If fail to alloc memory, return NULL. If success, all bits in the memory block are initialized with 0 and the memory block count (memory_blocks_count)is incremented by 1.

      free_memory_block

      void (*free_memory_block)(SPVM_ENV* env, void* block);
      

      If block is not NULL, free the memory and memory blocks count(memory_blocks_count) is decremented by 1.

      get_memory_blocks_count

      Returns the current number of memory blocks.

      int32_t (*get_memory_blocks_count)(SPVM_ENV* env);
      

      The memory block is increased by 1 when an object is created, when the alloc_memory_block_zero function is called, and when a back reference is added by the weaken function.

      get_type_name_raw

      If you specify an object, a new byte[] type object that stores the type name is returned.

      void* (*get_type_name_raw)(SPVM_ENV* env, void* object);
      

      This function does not add objects to the mortal stack, so use type_name for normal use to avoid memory leaks.

      get_type_name

      If you specify an object, a new byte[] type object that stores the type name is returned. Add the newly created object to the mortal stack.

      void* (*get_type_name)(SPVM_ENV* env, void* object);
      

      new_env

      Create a new execution environment based on the current execution environment.

      SPVM_ENV* (*new_env)(SPVM_ENV* env);
      

      Create a new SPVM runtime environment.

      The exception object and mortal stack information will be initialized.

      Share the package variables with the original execution environment.

      The number of memory blocks is shared with the original execution environment.

      If thie method can't allocate memory for SPVM runtime environment, return NULL.

      free_env

      Release the execution environment.

      void (*free_env)(SPVM_ENV* env);
      

      memory_blocks_count

      Memory blocks count. It is used internally.

      void* memory_blocks_count;