| 1 | package SPVM::Builder::Native::Compiler; | ||||||||||
| 2 | |||||||||||
| 3 | 1498 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 760 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 760 | ▶ | use Scalar::Util 'weaken'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 749 | ▶ | use SPVM::Builder::Native::Runtime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | ### Fields | ||||||||||
| 10 | |||||||||||
| 11 | 2818 | ▶ | sub get_runtime { shift->{runtime} } | ||||||||
|
Subroutine
get_runtime: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 12 | |||||||||||
| 13 | sub pointer { | ||||||||||
| 14 | 27 | ▶ | my $self = shift; | ||||||||
|
Subroutine
pointer: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 15 | 27 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 27 | $self->{pointer} = $_[0]; | |||||||||
| 17 | 27 | return $self; | |||||||||
| 18 | } | ||||||||||
| 19 | else { | ||||||||||
| 20 | 27 | return $self->{pointer}; | |||||||||
| 21 | } | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub boot_env { | ||||||||||
| 25 | 1447 | ▶ | my $self = shift; | ||||||||
|
Subroutine
boot_env: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 26 | 1447 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 1447 | $self->{boot_env} = $_[0]; | |||||||||
| 28 | 1447 | return $self; | |||||||||
| 29 | } | ||||||||||
| 30 | else { | ||||||||||
| 31 | 27 | return $self->{boot_env}; | |||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | sub get_formatted_error_messages { | ||||||||||
| 36 | 33 | ▶ | my ($self, $fh) = @_; | ||||||||
|
Subroutine
get_formatted_error_messages: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 37 | |||||||||||
| 38 | 76 | 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 | 1420 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 49 | |||||||||||
| 50 | 1447 | my $self = {@_}; | |||||||||
| 51 | |||||||||||
| 52 | 1447 | bless $self, $class; | |||||||||
| 53 | |||||||||||
| 54 | 1447 | my $boot_env = SPVM::Builder::Native::Env->new; | |||||||||
| 55 | |||||||||||
| 56 | 1447 | $self->boot_env($boot_env); | |||||||||
| 57 | |||||||||||
| 58 | 1420 | $self->create_native_compiler; | |||||||||
| 59 | |||||||||||
| 60 | 1420 | my $runtime = $self->get_runtime; | |||||||||
| 61 | |||||||||||
| 62 | 1420 | $runtime->{compiler} = $self; | |||||||||
| 63 | |||||||||||
| 64 | 1420 | weaken $runtime->{compiler}; | |||||||||
| 65 | |||||||||||
| 66 | 1420 | return $self; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | sub compile_with_exit { | ||||||||||
| 70 | 1274 | ▶ | my ($self, $class_name, $file, $line) = @_; | ||||||||
|
Subroutine
compile_with_exit: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 71 | |||||||||||
| 72 | 1274 | $self->set_start_file($file); | |||||||||
| 73 | |||||||||||
| 74 | 1301 | $self->set_start_line($line); | |||||||||
| 75 | |||||||||||
| 76 | 1301 | eval { $self->compile($class_name); }; | |||||||||
| 77 | |||||||||||
| 78 | 1301 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 29 | Carp::confess(join("\n", @{$self->get_formatted_error_messages})); | |||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | sub compile_anon_class_with_exit { | ||||||||||
| 84 | 105 | ▶ | my ($self, $source, $file, $line) = @_; | ||||||||
|
Subroutine
compile_anon_class_with_exit: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 85 | |||||||||||
| 86 | 105 | $self->set_start_file($file); | |||||||||
| 87 | |||||||||||
| 88 | 105 | $self->set_start_line($line); | |||||||||
| 89 | |||||||||||
| 90 | 105 | my $anon_class_name; | |||||||||
| 91 | |||||||||||
| 92 | 110 | eval { $anon_class_name = $self->compile_anon_class($source); }; | |||||||||
| 93 | |||||||||||
| 94 | 110 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 35 | Carp::confess(join("\n", @{$self->get_formatted_error_messages})); | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 107 | 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 | ||||||||||