line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mylisp::ToMy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3126
|
use 5.012; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
no warnings 'experimental'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
our @EXPORT = |
9
|
|
|
|
|
|
|
qw(ast_to_my atoms_to_my atoms_to_mys atom_to_my oper_to_my name_to_my func_to_my args_to_my aindex_to_my for_to_my our_to_my str_to_my string_to_my array_to_my hash_to_my is_kstr tidy_my); |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use Spp::Builtin; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
174
|
|
12
|
1
|
|
|
1
|
|
6
|
use Spp::Tools; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1041
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub ast_to_my { |
15
|
0
|
|
|
0
|
0
|
|
my $ast = shift; |
16
|
0
|
|
|
|
|
|
my $str = atoms_to_my($ast); |
17
|
0
|
|
|
|
|
|
return tidy_my($str); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub atoms_to_my { |
21
|
0
|
|
|
0
|
0
|
|
my $atoms = shift; |
22
|
0
|
|
|
|
|
|
my $strs = [map { atom_to_my($_) } @{ atoms($atoms) }]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return join ' ', @{$strs}; |
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub atoms_to_mys { |
27
|
0
|
|
|
0
|
0
|
|
my $atoms = shift; |
28
|
0
|
|
|
|
|
|
return estr([map { atom_to_my($_) } @{ atoms($atoms) }]); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub atom_to_my { |
32
|
0
|
|
|
0
|
0
|
|
my $atom = shift; |
33
|
0
|
|
|
|
|
|
my ($name, $args) = flat($atom); |
34
|
0
|
0
|
|
|
|
|
if ( |
35
|
|
|
|
|
|
|
$name ~~ [ |
36
|
|
|
|
|
|
|
'!=', '&&', '+', '-', '<', '<<', '<=', '==', |
37
|
|
|
|
|
|
|
'>', '=', '>=', '>>', '><', 'eq', 'in', 'le', |
38
|
|
|
|
|
|
|
'ne', 'x', '||' |
39
|
|
|
|
|
|
|
] |
40
|
|
|
|
|
|
|
) |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
|
|
|
return oper_to_my($name, $args); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
given ($name) { |
45
|
0
|
|
|
|
|
|
when ('func') { return func_to_my($args) } |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
when ('Aindex') { return aindex_to_my($args) } |
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
when ('Str') { return str_to_my($args) } |
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
when ('String') { return string_to_my($args) } |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
when ('Array') { return array_to_my($args) } |
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
when ('Hash') { return hash_to_my($args) } |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
when ('for') { return for_to_my($args) } |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
when ('our') { return our_to_my($args) } |
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
when ('package') { return "(package $args)" } |
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
when ('use') { return "(use $args)" } |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
when ('Sym') { return $args } |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
when ('Int') { return $args } |
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
when ('Ns') { return $args } |
|
0
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
when ('Bool') { return $args } |
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
when ('Char') { return $args } |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
when ('Type') { return $args } |
|
0
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
when ('end') { return '(end)' } |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
default { return name_to_my($name, $args) } |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub oper_to_my { |
67
|
0
|
|
|
0
|
0
|
|
my ($name, $args) = @_; |
68
|
0
|
|
|
|
|
|
my $strs = atoms_to_mys($args); |
69
|
0
|
|
|
|
|
|
my $str = ejoin($strs, " $name "); |
70
|
0
|
|
|
|
|
|
return "($str)"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub name_to_my { |
74
|
0
|
|
|
0
|
0
|
|
my ($name, $args) = @_; |
75
|
0
|
|
|
|
|
|
my $str = atoms_to_my($args); |
76
|
0
|
|
|
|
|
|
return "($name $str)"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub func_to_my { |
80
|
0
|
|
|
0
|
0
|
|
my $atoms = shift; |
81
|
0
|
|
|
|
|
|
my ($name_args, $exprs) = match($atoms); |
82
|
0
|
|
|
|
|
|
my ($name, $args) = flat($name_args); |
83
|
0
|
|
|
|
|
|
my $args_str = args_to_my($args); |
84
|
0
|
|
|
|
|
|
my $exprs_str = atoms_to_my($exprs); |
85
|
0
|
|
|
|
|
|
return "(func ($name $args_str) $exprs_str)"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub args_to_my { |
89
|
0
|
|
|
0
|
0
|
|
my $args = shift; |
90
|
0
|
|
|
|
|
|
my $strs = []; |
91
|
0
|
|
|
|
|
|
for my $arg (@{ atoms($args) }) { |
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my ($name, $type) = flat($arg); |
93
|
0
|
|
|
|
|
|
push @{$strs}, "$name:$type"; |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
return join ' ', @{$strs}; |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub aindex_to_my { |
99
|
0
|
|
|
0
|
0
|
|
my $args = shift; |
100
|
0
|
|
|
|
|
|
my $strs = atoms_to_mys($args); |
101
|
0
|
|
|
|
|
|
my ($name, $indexs) = match($strs); |
102
|
0
|
|
|
|
|
|
my $indexs_str = ejoin($indexs, ']['); |
103
|
0
|
|
|
|
|
|
return "$name\[$indexs_str]"; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub for_to_my { |
107
|
0
|
|
|
0
|
0
|
|
my $args = shift; |
108
|
0
|
|
|
|
|
|
my ($iter_expr, $exprs) = match($args); |
109
|
0
|
|
|
|
|
|
my ($loop, $iter_atom) = flat($iter_expr); |
110
|
0
|
|
|
|
|
|
my $iter_str = atom_to_my($iter_atom); |
111
|
0
|
|
|
|
|
|
my $exprs_str = atoms_to_my($exprs); |
112
|
0
|
|
|
|
|
|
return "(for ($loop in $iter_str) $exprs_str)"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub our_to_my { |
116
|
0
|
|
|
0
|
0
|
|
my $args = shift; |
117
|
0
|
|
|
|
|
|
my $strs = atoms_to_mys($args); |
118
|
0
|
|
|
|
|
|
my ($slist, $value) = flat($strs); |
119
|
0
|
|
|
|
|
|
return "(my $slist $value)"; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub str_to_my { |
123
|
0
|
|
|
0
|
0
|
|
my $str = shift; |
124
|
0
|
0
|
|
|
|
|
if (is_kstr($str)) { return ":$str" } |
|
0
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return "'$str'"; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub string_to_my { |
129
|
0
|
|
|
0
|
0
|
|
my $string = shift; |
130
|
0
|
|
|
|
|
|
my $strs = [map { value($_) } @{ atoms($string) }]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $str = join '', @{$strs}; |
|
0
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return "\"$str\""; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub array_to_my { |
136
|
0
|
|
|
0
|
0
|
|
my $array = shift; |
137
|
0
|
|
|
|
|
|
my $atoms = atoms_to_mys($array); |
138
|
0
|
|
|
|
|
|
my $atoms_str = ejoin($atoms, ' '); |
139
|
0
|
|
|
|
|
|
return "[$atoms_str]"; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub hash_to_my { |
143
|
0
|
|
|
0
|
0
|
|
my $pairs = shift; |
144
|
0
|
|
|
|
|
|
my $pairs_strs = []; |
145
|
0
|
|
|
|
|
|
for my $pair (@{ atoms($pairs) }) { |
|
0
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my ($name, $key_value) = flat($pair); |
147
|
0
|
|
|
|
|
|
my $pair_strs = atoms_to_mys($key_value); |
148
|
0
|
|
|
|
|
|
my ($key, $value) = flat($pair_strs); |
149
|
0
|
|
|
|
|
|
push @{$pairs_strs}, "$key => $value"; |
|
0
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
my $pairs_str = join ', ', @{$pairs_strs}; |
|
0
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return "{$pairs_str}"; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub is_kstr { |
156
|
0
|
|
|
0
|
0
|
|
my $str = shift; |
157
|
0
|
|
|
|
|
|
for my $char (split '', $str) { |
158
|
0
|
0
|
|
|
|
|
next if is_alpha($char); |
159
|
0
|
|
|
|
|
|
return 0; |
160
|
|
|
|
|
|
|
} |
161
|
0
|
|
|
|
|
|
return 1; |
162
|
|
|
|
|
|
|
} |
163
|
0
|
|
|
0
|
0
|
|
sub tidy_my { my $str = shift; return $str } |
|
0
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |