-
Notifications
You must be signed in to change notification settings - Fork 15
/
CompilerDriver.pm
65 lines (51 loc) · 1.31 KB
/
CompilerDriver.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package CompilerDriver;
use strict;
use warnings;
use 5.010;
use Sub::Exporter -setup => {
exports => [ qw(compile) ]
};
open ::NIECZA_OUT, ">&", \*STDOUT;
BEGIN {
unshift @INC, 'STD_checkout';
$ENV{PERL6LIB} = "STD_checkout:STD_checkout/lib";
}
use Body ();
use Decl ();
use Unit ();
use Op ();
use Storable;
use Niecza::Grammar ();
use Niecza::Actions ();
print ::NIECZA_OUT <<EOH;
using System;
using System.Collections.Generic;
using Niecza;
EOH
sub compile {
my %args = @_;
$args{lang} //= 'CORE';
local $::SETTING_RESUME;
local $::YOU_WERE_HERE;
local $::UNITNAME = $args{main} ? '' : $args{file};
$::UNITNAME =~ s/\.(?:pm6?|setting)//;
$::UNITNAME =~ s|[\\/]|.|g;
$STD::ALL = {};
$::SETTING_RESUME = retrieve($args{lang} . '_ast.store')
unless $args{lang} eq 'NULL';
my ($m, $a) = $args{file} ? ('parsefile', $args{file}) :
('parse', $args{code});
my $ast = Niecza::Grammar->$m($a, setting => $args{lang},
actions => 'Niecza::Actions')->{_ast};
if ($args{ast}) {
delete $a->mainline->{outer};
delete $a->{setting};
print STDOUT YAML::XS::Dump($a);
return;
}
$::SETTING_RESUME = undef;
$ast->write;
store $::SETTING_RESUME, ($::UNITNAME . '_ast.store')
if $::SETTING_RESUME;
}
1;