Name

SPVM::Document::NativeAPI::Runtime - Runtime Native APIs

Description

The runtime native APIs of SPVM are the APIs for SPVM runtimes.

Usage

SPVM_API_RUNTIME* api_runtime = env->api->runtime;

int32_t basic_types_length = api_runtime->get_basic_types_length(env->runtime);

Runtime Native APIs

get_object_data_offset

int32_t (*get_object_data_offset)(void* runtime);

Returns the offset of data area in SPVM_OBJECT struct.

Elements in an array or fields or a pointer in a pointer class is stored into the data area.

get_object_ref_count_offset

int32_t (*get_object_ref_count_offset)(void* runtime);

Returns the offset of the ref_count field in SPVM_OBJECT struct.

get_object_length_offset

int32_t (*get_object_length_offset)(void* runtime);

Returns the offset of the length field in SPVM_OBJECT struct.

get_basic_type_by_id

void* (*get_basic_type_by_id)(void* runtime, int32_t basic_type_id);

Searches a basic type given the basic type ID basic_type_id.

If it is found, returns it. Otherwise, returns NULL.

get_basic_type_by_name

void* (*get_basic_type_by_name)(void* runtime, const char* basic_type_name);

Searches a basic type given the basic type name basic_type_name.

If it is found, returns it. Otherwise, returns NULL.

get_basic_types_length

int32_t (*get_basic_types_length)(void* runtime);

Returns the length of the basic types owned by the SPVM runtime runtime.

build_precompile_class_source

void (*build_precompile_class_source)(void* runtime, void* string_buffer, void* basic_type);

Creates a C source code for methods with the precompile attribute defined in the class given by the its basic type basic_type, and saves it to the string buffer string_buffer.

build_precompile_method_source

void (*build_precompile_method_source)(void* runtime, void* string_buffer, void* method);

Creates a C source code for the method method, and saves it to the string buffer string_buffer.

get_compiler

void* (*get_compiler)(void* runtime);

Returns the value of the compiler field. The compiler that build the runtime runtime is stored to this field.

set_compiler

void (*set_compiler)(void* runtime, void* compiler);

Sets compiler to the compiler field.

get_spvm_stdin

FILE* (*get_spvm_stdin)(void* runtime);

Returns SPVM's standard input.

get_spvm_stdout

FILE* (*get_spvm_stdout)(void* runtime);

Returns SPVM's standard output.

get_spvm_stderr

FILE* (*get_spvm_stderr)(void* runtime);

Returns SPVM's standard error.

get_env

SPVM_ENV* (*get_env)(void* runtime);

Returns the runtime environment.

get_object_capacity_offset

int32_t (*get_object_capacity_offset)(void* runtime);

Returns the offset of capacity membar variable in SPVM_OBJECT struct.

method_begin_cb

void* method_begin_cb;

The callback function called at the beginning of a method.

The callback function must be a function pointer with the following signature:

void cb(SPVM_ENV* env, SPVM_VALUE* stack);

  • env : The runtime environment.

  • stack : The runtime stack. This can be used to access arguments.

method_end_cb

void* method_end_cb;

The callback function called at the end of a method.

The callback function must be a function pointer with the following signature:

void cb(SPVM_ENV* env, SPVM_VALUE* stack);

The arguments are the same as "method_begin_cb". This can be used to access the return value.

object_data_offset

void* object_data_offset;.

Returns the offset of data member variavle in SPVM_OBJECT object. This must not be used because it is only for internal.

object_length_offset

void* object_length_offset;

Returns the offset of length member variavle in SPVM_OBJECT object. This must not be used because it is only for internal.

object_capacity_offset

void* object_capacity_offset;

Returns the offset of capacity member variavle in SPVM_OBJECT object. This must not be used because it is only for internal.

stack_index_call_depth

void* stack_index_call_depth;

The index of the call_depth stack variable on the runtime stack. This value is cast to void*.

Examples:

int32_t call_depth_index = (int32_t)(intptr_t)env->api->runtime->stack_index_call_depth;
int32_t call_depth = stack[call_depth_index].ival;

stack_index_caller_info_stack

void* stack_index_caller_info_stack;

The index of the caller_info_stack stack variable on the runtime stack. This value is cast to void*.

Examples:

int32_t caller_info_stack_index = (int32_t)(intptr_t)env->api->runtime->stack_index_caller_info_stack;
void** caller_info_stack = (void**)stack[caller_info_stack_index].oval;

stack_index_caller_info_stack_record_size

void* stack_index_caller_info_stack_record_size;

The index of the caller_info_stack_record_size stack variable on the runtime stack. This value is cast to void*.

Examples:

int32_t record_size_index = (int32_t)(intptr_t)env->api->runtime->stack_index_caller_info_stack_record_size;
int32_t record_size = stack[record_size_index].ival;

Native Runtime API IDs

0 get_object_data_offset
1 get_object_ref_count_offset
2 get_object_length_offset
3 get_basic_type_by_id
4 get_basic_type_by_name
5 get_basic_types_length
6 build_precompile_class_source
7 build_precompile_method_source
8 get_compiler
9 set_compiler
10 get_spvm_stdin
11 get_spvm_stdout
12 get_spvm_stderr
13 get_env
14 get_object_capacity_offset
15 method_begin_cb
16 method_end_cb
17 object_data_offset
18 object_length_offset
19 object_capacity_offset
20 stack_index_call_depth
21 stack_index_caller_info_stack
22 stack_index_caller_info_stack_record_size

See Also

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License