blib/lib/SPVM/Native.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 package SPVM::Native;
2  
3  
4  
5 1;
6  
7 =head1 Name
8  
9 SPVM::Native - Getting the current native environment, stack, runtime, compiler.
10  
11 =head1 Description
12  
13 The Native class of L<SPVM> has methods to get the current native environment, stack, runtime, compiler.
14  
15 =head1 Usage
16  
17 use Native;
18  
19 =head1 Class Methods
20  
21 =head2 get_current_stack
22  
23 C<static method get_current_stack : L<Native::Stack|SPVM::Native::Stack> ();>
24  
25 Returns the current execution stack.
26  
27 =head2 get_current_env
28  
29 C<static get_current_env : L<Native::Env|SPVM::Native::Env> ();>
30  
31 Returns the current execution environemnt.
32  
33 =head2 get_current_runtime
34  
35 C<static method get_current_runtime : L<Native::Runtime|SPVM::Native::Runtime> ();>
36  
37 Returns the current runtime.
38  
39 =head2 get_current_compiler
40  
41 C<static method get_current_compiler : L<Native::Compiler|SPVM::Native::Compiler> ();>
42  
43 Returns the current compiler.
44  
45 =head2 check_bootstrap_method
46  
47 C<static method check_bootstrap_method : void ($basic_type_name : string);>
48  
49 Check the bootstrap method in the basic type $basic_type_name.
50  
51 =head2 use
52  
53 C<static method use : void (static method use : void ($class_name : string, $file : string = undef, $line : int = -1));>
54  
55 Compiles the class $class_name using the compiler of the current runtime.
56  
57 =head2 use_anon_class
58  
59 C<static method use_anon_class : string ($source : string, $file : string = undef, $line : int = -1);>
60  
61 Compiles the anon class source $source using the compiler of the current runtime.
62  
63 =head2 eval
64  
65 C<static method eval : object ($eval_source : string);>
66  
67 This method emulates L<Perl's string eval|https://perldoc.perl.org/functions/eval#String-eval>.
68  
69 This method creates the following source code.
70  
71 "
72 class {
73 static method eval : object () {
74 #line 1
75 $eval_source
76 }
77 }
78 "
79  
80 And calls L</"compile_anon_class"> given this source code and gets the anon class name.
81  
82 And calls L<call_class_method|SPVM::Native::MethodCall/"call_class_method"> in the Native::MethodCall class.
83  
84 Native::MethodCall->call_class_method($anon_class_name, "eval");
85  
86 Examples:
87  
88 my $value = (Int)Native->eval("my $total = 1 + 2; return $total;");
89 say $value->value;
90  
91 =head2 inc
92  
93 C<static method inc : string[] ();>
94  
95 Returns the current serach directories of the class search directories of the compiler of the current runtime.
96  
97 =head2 set_inc
98  
99 C<static method set_inc : void ($class_search_dirs : string[]);>
100  
101 Set the current serach directories $class_search_dirs to the class search directories of the compiler of the current runtime.
102  
103 =head2 push_inc
104  
105 C<static method push_inc : void ($class_search_dir : string);>
106  
107 Add the class search directory $class_search_dir at the tail of the class search directories of the compiler of the current runtime.
108  
109 =head2 unshift_inc
110  
111 C<static method unshift_inc : void ($class_search_dir : string);>
112  
113 Add the class search directory $class_search_dir at the head of the class search directories of the compiler of the current runtime.
114  
115 =head1 Copyright & License
116  
117 Copyright (c) 2023 Yuki Kimoto
118  
119 MIT License
120