Name
SPVM::Document::NativeAPI::Compiler - Compiler Native APIs
Usage
SPVM_API_COMPILER* api_compiler = env->api->compiler;
void* compiler = api_compiler->new_instance();
api_compiler->add_include_dir(compiler, "lib");
api_compiler->set_start_file(compiler, __FILE__);
api_compiler->get_start_line(compiler, __LINE__ + 1);
int32_t status = api_compiler->compile(compiler, "MyClass");
api_compiler->free_instance(compiler);
Description
The compiler native APIs in SPVM are the APIs for SPVM compilers.
Compiler Native APIs
new_instance
void* (*new_instance)(void);
Creates a new compiler and returns it.
free_instance
void (*free_instance)(void* compiler);
Frees the compiler compiler.
get_start_line
int32_t (*get_start_line)(void* compiler);
Returns the value of the start_line
field. The starting line for an exception call stack is stored to this field.
set_start_line
void (*set_start_line)(void* compiler, int32_t start_line);
Sets start_line to the start_line
field.
get_start_file
const char* (*get_start_file)(void* compiler);
Returns the value of the start_file
field. The starting file path for an exception call stack is stored to this field.
set_start_file
void (*set_start_file)(void* compiler, const char* start_file);
Sets start_file to the start_file
field.
get_include_dirs_length
int32_t (*get_include_dirs_length)(void* compiler);
Returns the length of the class searching directories.
get_include_dir
const char* (*get_include_dir)(void* compiler, int32_t index);
Searches a class searching directory given the index index.
If it is found, returns it, otherwise returns NULL
.
add_include_dir
void (*add_include_dir)(void* compiler, const char* include_dir);
Adds include_dir at the end of the class searching directories.
clear_include_dirs
void (*clear_include_dirs)(SPVM_COMPILER* compiler);
Removes all class searching directories.
add_class_file
void (*add_class_file)(void* compiler, const char* class_name);
Creates the class file for the class given by class_name, and adds it to the symbol table of the compiler compiler.
If the class file already exists, nothing is performed.
delete_class_file
void (*delete_class_file)(void* compiler, const char* class_name);
Removes the class file for the class given by the class name class_name.
get_class_file
void* (*get_class_file)(void* compiler, const char* class_name);
Returns the class file for the class given by the class name class_name.
compile
int32_t (*compile)(void* compiler, const char* class_name);
Compiles the SPVM class given by the class name class_name. Classes loaded by the class and classes subsequently loaded are also compiled.
The runtime is build.
If the compilation is successful, returns 0, otherwise returns a non-zero value.
This native API can be called repeatedly to compile other classes.
get_error_messages_length
int32_t (*get_error_messages_length)(void* compiler);
Returns the length of the compilation error messages.
get_error_message
const char* (*get_error_message)(void* compiler, int32_t index);
Searches the compiler error message given the index index.
If it is found, returns it, otherwise returns NULL
.
get_runtime
void* (*get_runtime)(void* compiler);
Returns the runtime that is build by the compiler compiler.
prepend_include_dir
void (*prepend_include_dir)(void* compiler, const char* include_dir);
Prepends include_dir to the class searching directory.
compile_anon_class
int32_t (*compile_anon_class)(void* compiler, const char* source, const char** anon_basic_type_name_ptr);
Compiles a SPVM anon class given the source code source. Classes loaded by the class and classes subsequently loaded are also compiled.
The runtime is build.
If the compilation is successful, returns 0, otherwise returns a non-zero value.
The generated anon class name is set to the value referenced by anon_basic_type_name_ptr.
This native API can be called repeatedly to compile other classes.
Native API IDs
0 new_instance
1 free_instance
2 get_start_line
3 set_start_line
4 get_start_file
5 set_start_file
6 get_include_dirs_length
7 get_include_dir
8 add_include_dir
9 clear_include_dirs
10 add_class_file
11 delete_class_file
12 get_class_file
13 compile
14 get_error_message
15 get_error_messages_length
16 get_runtime
17 prepend_include_dir
18 compile_anon_class
See Also
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License