Mildew/Backend/C/M0ld.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 36 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use v5.10;
2 use MooseX::Declare;
3 class Mildew::Backend::C::M0ld with Mildew::Backend::C {
4 use File::Temp qw(tempfile tmpnam);
5 method c_source($ast) {
6 my $body = "SMOP__Object* mold = " . $self->m0ld_to_c($self->ast_to_m0ld($ast)) . ";\n" .
7 "SMOP__Object* frame = SMOP__Mold__Frame_create(interpreter,mold);";
8 my $boilerplate = $self->get_boilerplate;
9 $boilerplate =~ s/%%BODY%%/$body/;
10 $boilerplate =~ s/%%FUNCS%%//;
11 $boilerplate;
12 }
13  
14 method ast_to_m0ld($ast) {
15 my ($front,$back);
16
17 # TODO support 'so' and 'js-lib'
18
19 #if ($C eq 'so' or $C eq 'js-lib') {
20 # $front = "my \$interpreter;\nmy \$scope;\nmy \$back;\n";
21 # $back = 'my $void = $back."setr"($ret);my $void = $interpreter."goto"($back);';
22 #} else {
23 $front = "my \$scope = ?SMOP__S1P__LexicalPrelude;\n";
24 $back = '';
25 #}
26
27 my $m0ld = $front.<<'BOILERPLATE_FRONT'.$ast->m0ld('$main').<<'BOILERPLATE_BACK'.$back;
28 my $void;
29 BOILERPLATE_FRONT
30 my $AdhocSignature_scalar = $scope."lookup"("AdhocSignature");
31 my $AdhocSignature = $AdhocSignature_scalar."FETCH"();
32
33 my $sig = $AdhocSignature."new"(:"BIND"(mold {
34 my $interpreter;
35 my $scope;
36 my $capture;
37 my $continuation = $interpreter."continuation"();
38 my $back = $continuation."back"();
39 my $void = $interpreter."goto"($back);
40 }),:"ACCEPTS"(mold {
41 my $interpreter;
42 my $scope;
43 my $capture;
44 my $continuation = $interpreter."continuation"();
45 my $back = $continuation."back"();
46 my $void = $interpreter."goto"($back);
47 }));
48
49 my $Code_scalar = $scope."lookup"("Code");
50 my $Code = $Code_scalar."FETCH"();
51 my $main_code = $Code."new"(:"outer"($scope),:"mold"($main),:"signature"($sig));
52 my $Capture_scalar = $scope."lookup"("capture");
53 my $Capture = $Capture_scalar."FETCH"();
54 my $capture = $Capture."new"();
55 my $ret = $main_code."postcircumfix:( )"($capture);
56 BOILERPLATE_BACK
57 }
58 method m0ld_to_c($m0ld) {
59 #XXX
60 my @options;
61  
62 use IPC::Open2;
63 open2(my $m0ld_exe_out,my $m0ld_exe_in,"../smop/m0ld_exe",@options);
64 binmode $m0ld_exe_in, ':utf8';
65 print $m0ld_exe_in $m0ld;
66 close($m0ld_exe_in);
67 local $/;
68 binmode $m0ld_exe_out, ':utf8';
69 return <$m0ld_exe_out>;
70 }
71 }