Mildew/Backend/C/V6.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 53 CC 1 SCAR 6.9
CC
1
Cov
0%
wrap_in_block_without_setr
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use v5.10;
2 use MooseX::Declare;
3 use Mildew::Setting::SMOP;
4 class Mildew::Backend::C::V6 extends Mildew::Backend::C::So {
5 use Mildew::AST;
6 use Mildew::AST::Helpers;
7 use File::Temp qw(tempfile tmpnam);
8  
9  
10  
11 # false doesn't support setr
12 sub wrap_in_block_without_setr {
13 my ($ast,$scope) = @_;
14 Mildew::AST::Block->new(regs=>['interpreter','scope'],stmts=>[fcall(call(new => FETCH(lookup('Code')),[],[string 'outer'=>($scope // reg '$scope'),string 'signature'=>empty_sig(),string 'mold' => $ast]))]);
15 }
16  
17 method compile($ast,$output) {
18 die "-o is required when compiling to an executable\n" unless $output;
19 my ($c_fh,$c_file) = tempfile();
20 binmode($c_fh,":utf8");
21 my $wrapped_ast = $self->wrap_in_block ? wrap_in_block_without_setr($ast,$self->enclosing_scope) : $ast;
22 print $c_fh $self->c_source($wrapped_ast);
23  
24  
25 # compile the c source to the shared library
26 $ENV{LD_RUN_PATH} = join(':',SMOP::ld_library_path(),Mildew::Setting::SMOP::ld_library_path());
27 system("gcc","-fPIC","-g","-xc",@{$self->cflags},"-shared",$c_file,"-o",$output);
28 }
29  
30  
31 method get_boilerplate {
32 <<'END'
33  
34 #include <smop/main.h>
35  
36 #include <smop/base.h>
37 #include <smop/s0native.h>
38 #include <smop/nagc.h>
39 #include <smop/interpreter.h>
40 #include <smop/capture.h>
41 #include <smop/native.h>
42 #include <smop/mold.h>
43 #include <smop/s1p.h>
44 #include <smop/lost.h>
45 #include <smop/p6opaque.h>
46 #include <smop/s1p-oo.h>
47 #include <smop/yeast.h>
48 #include <smop/profile.h>
49 #include <smop/dump.h>
50 #include <smop/nagc.h>
51 #include <stdio.h>
52  
53 /* Your helper function go here */
54 %%FUNCS%%
55  
56 int run(int argc, char** argv) {
57  
58  
59 SMOP__Object* interpreter = smop_main_get_interpreter();
60  
61  
62 /* The frame creation code goes here */
63 %%BODY%%
64  
65 SMOP_DISPATCH(interpreter, SMOP_RI(interpreter),
66 SMOP__NATIVE__idconst_create("goto"),
67 SMOP__NATIVE__capture_create(interpreter,
68 (SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter),frame,NULL},
69 (SMOP__Object*[]) {NULL})
70 );
71  
72 SMOP_DISPATCH(interpreter, SMOP_RI(interpreter),
73 SMOP__NATIVE__idconst_create("loop"),
74 SMOP__NATIVE__capture_create(
75 interpreter,
76 (SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter),NULL}
77 ,(SMOP__Object*[]) {NULL}));
78  
79 SMOP_DISPATCH(interpreter, SMOP_RI(interpreter),
80 SMOP__NATIVE__idconst_create("goto"),
81 SMOP__NATIVE__capture_create(
82 interpreter,
83 (SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter),SMOP__NATIVE__bool_false,NULL}
84 ,(SMOP__Object*[]) {NULL}));
85  
86 SMOP_DISPATCH(interpreter, SMOP_RI(interpreter),
87 SMOP__NATIVE__idconst_create("loop") , SMOP__NATIVE__capture_create(
88 interpreter,
89 (SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter),NULL},
90 (SMOP__Object*[]) {NULL}));
91  
92 return 0;
93 }
94 END
95 }
96  
97 method path_to_setting {
98 Mildew::Setting::SMOP::ld_library_path() . '/' .
99 'MildewCORE.setting.so';
100 }
101 method run($ast) {
102 die "can't run with this backend";
103 }
104 }