blib/lib/SPVM/Builder/Native/Compiler.pm

filter: Statementstmt 100% 58 / 58 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 7 totaltotal 88.1% 74 / 84 CC 11 SCAR 5.6
CC
11
Cov
95%
pointer
2.1
pointer
2.1
boot_env
2.0
CRAP 1.8
« blib/lib/SPVM/Builder/Native/Env.pm ↑ Summary blib/lib/SPVM/Builder/ConfigBuilder.pm »
1 package SPVM::Builder::Native::Compiler;
2  
3 1286 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 644 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 644 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 643 ▶use SPVM::Builder::Native::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 ### Fields
10  
11 2457 ▶sub get_runtime { shift->{runtime} }
Subroutine get_runtime: called CC=1 SCAR=0.0
Pod undocumented
12  
13 sub pointer {
14 36 ▶ my $self = shift;
Subroutine pointer: called CC=2 SCAR=7.2
Pod undocumented
15 36 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
16 36 $self->{pointer} = $_[0];
17 36 return $self;
18 }
19 else {
20 36 return $self->{pointer};
21 }
22 }
23  
24 sub boot_env {
25 1352 ▶ my $self = shift;
Subroutine boot_env: called CC=2 SCAR=7.0
Pod undocumented
26 1352 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1352 0 1352
27 1352 $self->{boot_env} = $_[0];
28 1352 return $self;
29 }
30 else {
31 36 return $self->{boot_env};
32 }
33 }
34  
35 sub get_formatted_error_messages {
36 42 ▶ my ($self, $fh) = @_;
Subroutine get_formatted_error_messages: called CC=2 SCAR=6.9
Pod undocumented
37
38 115 my $formatted_error_messages = [];
39 6 my $error_messages = $self->get_error_messages;
40 6 for my $error_message (@$error_messages) {
41 6 push @$formatted_error_messages, "[Compilation Error]$error_message\n";
42 }
43
44 6 return $formatted_error_messages;
45 }
46  
47 sub new {
48 1316 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
49
50 1352 my $self = {@_};
51
52 1352 bless $self, $class;
53
54 1352 my $boot_env = SPVM::Builder::Native::Env->new;
55
56 1352 $self->boot_env($boot_env);
57
58 1316 $self->create_native_compiler;
59
60 1316 my $runtime = $self->get_runtime;
61
62 1316 $runtime->{compiler} = $self;
63
64 1316 weaken $runtime->{compiler};
65
66 1316 return $self;
67 }
68  
69 sub compile_with_exit {
70 953 ▶ my ($self, $class_name, $file, $line) = @_;
Subroutine compile_with_exit: called CC=2 SCAR=6.9
Pod undocumented
71
72 953 $self->set_start_file($file);
73
74 989 $self->set_start_line($line);
75
76 989 eval { $self->compile($class_name); };
77
78 989 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 1023 1025
79 38 Carp::confess(join("\n", @{$self->get_formatted_error_messages}));
80 }
81 }
82  
83 sub compile_anon_class_with_exit {
84 165 ▶ my ($self, $source, $file, $line) = @_;
Subroutine compile_anon_class_with_exit: called CC=2 SCAR=6.9
Pod undocumented
85
86 165 $self->set_start_file($file);
87
88 165 $self->set_start_line($line);
89
90 165 my $anon_class_name;
91
92 201 eval { $anon_class_name = $self->compile_anon_class($source); };
93
94 201 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 3 127 130
95 75 Carp::confess(join("\n", @{$self->get_formatted_error_messages}));
96 }
97
98 198 return $anon_class_name;
99 }
100  
101 1;
102  
103 =head1 Name
104  
105 SPVM::Builder::Native::Compiler - Compiler Native APIs
106  
107 =head1 Copyright & License
108  
109 Copyright (c) 2023 Yuki Kimoto
110  
111 MIT License
« blib/lib/SPVM/Builder/Native/Env.pm ↑ Summary blib/lib/SPVM/Builder/ConfigBuilder.pm »