blib/lib/SPVM/Document/NativeAPI/Compiler.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 =head1 Name
2  
3 SPVM::Document::NativeAPI::Compiler - Compiler Native APIs
4  
5 =head1 Usage
6  
7 SPVM_API_COMPILER* api_compiler = env->api->compiler;
8
9 SPVM_NATIVE_COMPILER* compiler = api_compiler->new_instance();
10
11 api_compiler->add_class_search_dir(compiler, "lib");
12
13 api_compiler->set_start_file(compiler, __FILE__);
14 api_compiler->set_start_line(compiler, __LINE__ + 1);
15 int32_t status = api_compiler->compile(compiler, "MyClass");
16
17 api_compiler->free_instance(compiler);
18  
19 =head1 Description
20  
21 The compiler native APIs in L<SPVM> are the APIs for SPVM compilers.
22  
23 =head1 Compiler Native APIs
24  
25 =head2 new_instance
26  
27 C<SPVM_NATIVE_COMPILER* (*new_instance)(void);>
28  
29 Creates a new L<compiler|SPVM::Document::NativeAPI::Compiler> and returns it.
30  
31 =head2 free_instance
32  
33 C<void (*free_instance)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>);>
34  
35 Frees the compiler I<compiler>.
36  
37 =head2 get_start_line
38  
39 C<int32_t (*get_start_line)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>);>
40  
41 Returns the value of the C<start_line> field. The starting line for an exception call stack is stored to this field.
42  
43 =head2 set_start_line
44  
45 C<void (*set_start_line)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, int32_t start_line);>
46  
47 Sets I<start_line> to the C<start_line> field.
48  
49 =head2 get_start_file
50  
51 C<const char* (*get_start_file)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>);>
52  
53 Returns the value of the C<start_file> field. The starting file path for an exception call stack is stored to this field.
54  
55 =head2 set_start_file
56  
57 C<void (*set_start_file)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* start_file);>
58  
59 Sets I<start_file> to the C<start_file> field.
60  
61 =head2 get_class_search_dirs_length
62  
63 C<int32_t (*get_class_search_dirs_length)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>);>
64  
65 Returns the length of the class search directories.
66  
67 =head2 get_class_search_dir
68  
69 C<const char* (*get_class_search_dir)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, int32_t index);>
70  
71 Searches a class search directory given the index I<index>.
72  
73 If it is found, returns it. Otherwise, returns C<NULL>.
74  
75 =head2 add_class_search_dir
76
77 C<void (*add_class_search_dir)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* class_search_dir);>
78  
79 Adds I<class_search_dir> at the end of the class search directories.
80  
81 =head2 clear_class_search_dirs
82
83 C<void (*clear_class_search_dirs)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>);>
84  
85 Removes all class search directories.
86  
87 =head2 add_class_file
88  
89 C<void (*add_class_file)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* class_name);>
90  
91 Creates the L<class file|SPVM::Document::NativeAPI::ClassFile> for the class given by I<class_name>, and adds it to the symbol table of the compiler I<compiler>.
92  
93 If the class file already exists, nothing is performed.
94  
95 =head2 delete_class_file
96  
97 C<void (*delete_class_file)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* class_name);>
98
99 Removes the L<class file|SPVM::Document::NativeAPI::ClassFile> for the class given by the class name I<class_name>.
100  
101 =head2 get_class_file
102  
103 C<SPVM_NATIVE_CLASS_FILE* (*get_class_file)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* class_name);>
104  
105 Returns the L<class file|SPVM::Document::NativeAPI::ClassFile> for the class given by the class name I<class_name>.
106  
107 =head2 compile
108
109 C<int32_t (*compile)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* class_name);>
110  
111 Compiles the SPVM class given by the class name I<class_name>. Classes loaded by the class and classes subsequently loaded are also compiled.
112  
113 The L<runtime|/"get_runtime"> is build.
114  
115 If the compilation is successful, returns 0. Otherwise, returns a non-zero value.
116  
117 This native API can be called repeatedly to compile other classes.
118  
119 =head2 get_error_messages_length
120
121 C<int32_t (*get_error_messages_length)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>);>
122  
123 Returns the length of the compilation error messages.
124  
125 =head2 get_error_message
126  
127 C<const char* (*get_error_message)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, int32_t index);>
128  
129 Searches the compiler error message given the index I<index>.
130  
131 If it is found, returns it. Otherwise, returns C<NULL>.
132  
133 =head2 get_runtime
134  
135 C<SPVM_NATIVE_RUNTIME* (*get_runtime)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>);>
136  
137 Returns the L<runtime|SPVM::Document::NativeAPI::Runtime> that is build by the compiler I<compiler>.
138  
139 =head2 prepend_class_search_dir
140
141 C<void (*prepend_class_search_dir)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* class_search_dir);>
142  
143 Prepends I<class_search_dir> to the class search directory.
144  
145 =head2 compile_anon_class
146
147 C<int32_t (*compile_anon_class)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* source, const char** anon_basic_type_name_ptr);>
148  
149 Compiles an SPVM anon class given the source code I<source>. Classes loaded by the class and classes subsequently loaded are also compiled.
150  
151 The L<runtime|/"get_runtime"> is build.
152  
153 If the compilation is successful, returns 0. Otherwise, returns a non-zero value.
154  
155 The generated anon class name is set to the value referenced by I<anon_basic_type_name_ptr>.
156  
157 This native API can be called repeatedly to compile other classes.
158  
159 =head2 compile_script
160  
161 C<int32_t (*compile_script)(L<SPVM_NATIVE_COMPILER* compiler|SPVM::Document::NativeAPI::Compiler>, const char* source, const char** anon_basic_type_name_ptr);>
162  
163 Same as L</"compile_anon_class">.
164  
165 =head1 Native API IDs
166  
167 0 new_instance
168 1 free_instance
169 2 get_start_line
170 3 set_start_line
171 4 get_start_file
172 5 set_start_file
173 6 get_class_search_dirs_length
174 7 get_class_search_dir
175 8 add_class_search_dir
176 9 clear_class_search_dirs
177 10 add_class_file
178 11 delete_class_file
179 12 get_class_file
180 13 compile
181 14 get_error_message
182 15 get_error_messages_length
183 16 get_runtime
184 17 prepend_class_search_dir
185 18 compile_anon_class
186 19 compile_script
187  
188 =head1 See Also
189  
190 =over 2
191  
192 =item * L<SPVM::Document::NativeAPI>
193  
194 =item * L<SPVM::Document::NativeAPI::ClassFile>
195  
196 =item * L<SPVM::Document::NativeAPI::Runtime>
197  
198 =item * L<SPVM::Document::NativeClass>
199  
200 =item * L<SPVM::Document>
201  
202 =back
203  
204 =head1 Copyright & License
205  
206 Copyright (c) 2023 Yuki Kimoto
207  
208 MIT License