Perlito5/Java.pm untested

filter: Statementstmt 0.0% 0 / 520 Branchbran 0.0% 0 / 290 Conditioncond 0.0% 0 / 298 MC/DCmcdc 0.0% 0 / 171 Subroutinesub 0.0% 0 / 51 Podpod 0.0% 0 / 42 totaltotal 0.0% 0 / 1372 CC 146 SCAR 54.0
CC
146
Cov
0%
to_native_bool
930.0
to_native_arg
342.0
is_native_args
182.0
CRAP 222.3
1  
2 package Perlito5::Java;
3  
4 use v5;
5 use Perlito5::AST;
6 use Perlito5::AST::Captures;
7 use Perlito5::Dumper;
8 use Perlito5::Java::Emitter;
9 use Perlito5::Java::Apply;
10 use Perlito5::Perl5::Emitter; # TODO - cleanup the dependency on Perl5 emitter
11 use Perlito5::Perl5::PrettyPrinter; # TODO - cleanup the dependency on Perl5 emitter
12 use strict;
13  
14 sub init {
15 Perlito5::Java::init_java_class();
16 }
17  
18 my %label;
19  
20 # 'The::Class' => {
21 # import => 'full.path.Class', # Java class path
22 # perl_package => 'The::Class', # Perl package name
23 # java_type => 'Class', # generated, can be overridden: 'Class<String>'
24 # perl_to_java => 'to_TheClass', # generated, can be overridden
25 # java_native_to_perl => 'pClass', # generated
26 # }
27 my %Java_class;
28  
29 our %Java_var_name; # 101 => 'this.env.[0]'
30 my %Java_var; # 101 => { id => 101, type => 'Byte' }
31 our @Java_init;
32 our $is_inside_subroutine; # 'shift @_' vs. 'shift @ARGV'
33  
34 sub pkg {
35 Perlito5::Java::escape_string($Perlito5::PKG_NAME )
36 }
37 sub get_label {
38 'tmp' . $Perlito5::ID++
39 }
40 sub tab {
41 my $level = shift;
42 " " x $level
43 }
44 sub get_java_class_info {
45 return \%Java_class;
46 }
47 sub get_java_var_info {
48 return \%Java_var;
49 }
50 sub set_java_class_defaults {
51 my ($perl_package, $java_import) = @_;
52 # import => 'full.path.Class', # Java class path
53 # perl_package => 'The::Class', # Perl package name
54 # java_type => 'Class', # generated, can be overridden: 'Class<String>'
55 # perl_to_java => 'to_TheClass', # generated, can be overridden
56 # java_native_to_perl => 'pClass', # generated
57 #
58 # import => 'full.path.Class<String>', # Java class path + type argument
59 #
60 my $Java_class = Perlito5::Java::get_java_class_info();
61 my @parts = split /\./, $java_import;
62 # $Java_class->{$perl_package}->{java_type} //= $parts[-1];
63 $Java_class->{$perl_package}->{java_type} //= $java_import;
64 $Java_class->{$perl_package}->{java_native_to_perl} //= 'p' . $parts[-1];
65 # "List<String>" becomes "PlList_String_"
66 $Java_class->{$perl_package}->{java_native_to_perl} =~ s/[<>]/_/g;
67 # my $perl_to_java = $perl_package;
68 # $perl_to_java =~ s/:://g;
69 # $Java_class->{$perl_package}->{perl_to_java} //= "to_${perl_to_java}";
70 $Java_class->{$perl_package}->{perl_package} = $perl_package;
71 }
72  
73 our %is_long_type = (
74 'long' => 1,
75 'Long' => 1,
76 'java.lang.Long' => 1,
77 );
78 our %is_float_type = (
79 'float' => 1,
80 'Float' => 1,
81 'java.lang.Float' => 1,
82 );
83 our %is_char_type = (
84 'char' => 1,
85 'Character' => 1,
86 'java.lang.Character' => 1,
87 );
88 our %is_double_type = (
89 'double' => 1,
90 'Double' => 1,
91 'java.lang.Double' => 1,
92 );
93 our %is_boolean_type = (
94 'boolean' => 1,
95 'Boolean' => 1,
96 'java.lang.Boolean' => 1,
97 );
98 our %is_char_type = (
99 'char' => 1,
100 'Character' => 1,
101 'java.lang.Character' => 1,
102 );
103 our %is_int_type = (
104 'int' => 1,
105 'Integer' => 1,
106 'java.lang.Integer' => 1,
107 );
108 our %is_short_type = (
109 'short' => 1,
110 'Short' => 1,
111 'java.lang.Short' => 1,
112 );
113 our %is_byte_type = (
114 'byte' => 1,
115 'Byte' => 1,
116 'java.lang.Byte' => 1,
117 );
118  
119 our %stringify = (
120 byte => "Byte.toString",
121 short => "Short.toString",
122 int => "Integer.toString",
123 long => "Long.toString",
124 float => "Float.toString",
125 double => "Double.toString",
126 char => "Character.toString",
127 boolean => "Boolean.toString",
128 );
129  
130 sub init_java_class {
131 my $Java_class = Perlito5::Java::get_java_class_info();
132 $Java_class->{String} = {
133 java_type => 'String',
134 java_native_to_perl => 'PlString',
135 perl_to_java => 'toString',
136 perl_package => 'String',
137 };
138 $Java_class->{Long} = {
139 java_type => 'Long',
140 java_native_to_perl => 'PlInt',
141 perl_to_java => 'to_long',
142 perl_package => 'Long',
143 };
144 $Java_class->{Integer} = {
145 java_type => 'Integer',
146 java_native_to_perl => 'PlInt',
147 perl_to_java => 'to_int',
148 perl_package => 'Integer',
149 };
150 $Java_class->{Boolean} = {
151 java_type => 'Boolean',
152 java_native_to_perl => 'PlBool',
153 perl_to_java => 'to_boolean',
154 perl_package => 'Boolean',
155 };
156 $Java_class->{Double} = {
157 java_type => 'Double',
158 java_native_to_perl => 'PlDouble',
159 perl_to_java => 'to_double',
160 perl_package => 'Double',
161 };
162 $Java_class->{Byte} = {
163 java_type => 'Byte',
164 java_native_to_perl => 'PlInt',
165 perl_to_java => 'to_byte',
166 perl_package => 'Byte',
167 };
168 $Java_class->{Short} = {
169 java_type => 'Short',
170 java_native_to_perl => 'PlInt',
171 perl_to_java => 'to_short',
172 perl_package => 'Short',
173 };
174 $Java_class->{Float} = {
175 java_type => 'Float',
176 java_native_to_perl => 'PlDouble',
177 perl_to_java => 'to_float',
178 perl_package => 'Float',
179 };
180 # # $Java_class->{Object} = {
181 # # java_type => 'Object',
182 # # java_native_to_perl => 'PlObject',
183 # # perl_to_java => 'to_object',
184 # # perl_package => 'Object',
185 # # };
186 #
187 # - "java.lang.Object" can be imported using the standard import syntax:
188 #
189 # package Java::Object { import => "java.lang.Object" };
190 # my Java::Object $obj = Java::Object->new();
191 #
192 $Java_class->{Character} = {
193 java_type => 'Character',
194 java_native_to_perl => 'PlString',
195 perl_to_java => 'to_char',
196 perl_package => 'Character',
197 };
198 $Java_class->{long} = {
199 java_type => 'long',
200 java_native_to_perl => 'PlInt',
201 perl_to_java => 'to_long',
202 perl_package => 'long',
203 };
204 $Java_class->{int} = {
205 java_type => 'int',
206 java_native_to_perl => 'PlInt',
207 perl_to_java => 'to_int',
208 perl_package => 'int',
209 };
210 $Java_class->{short} = {
211 java_type => 'short',
212 java_native_to_perl => 'PlInt',
213 perl_to_java => 'to_long',
214 perl_package => 'short',
215 };
216 $Java_class->{byte} = {
217 java_type => 'byte',
218 java_native_to_perl => 'PlInt',
219 perl_to_java => 'to_long',
220 perl_package => 'byte',
221 };
222 $Java_class->{boolean} = {
223 java_type => 'boolean',
224 java_native_to_perl => 'PlBool',
225 perl_to_java => 'to_boolean',
226 perl_package => 'boolean',
227 };
228 $Java_class->{double} = {
229 java_type => 'double',
230 java_native_to_perl => 'PlDouble',
231 perl_to_java => 'to_double',
232 perl_package => 'double',
233 };
234 $Java_class->{float} = {
235 java_type => 'float',
236 java_native_to_perl => 'PlDouble',
237 perl_to_java => 'to_float',
238 perl_package => 'float',
239 };
240 $Java_class->{char} = {
241 java_type => 'char',
242 java_native_to_perl => 'PlString',
243 perl_to_java => 'to_char',
244 perl_package => 'char',
245 };
246 }
247  
248 our %Java_loop_label;
249 sub get_java_loop_label {
250 my $s = shift;
251 return 0 if !$s;
252 return $Java_loop_label{$s} if exists $Java_loop_label{$s};
253 my $label = $Perlito5::ID++;
254 $Java_loop_label{$s} = $label;
255 # push @Perlito5::Java::Java_constants, "public static final int Loop$s = $label;";
256 return $label;
257 }
258  
259 our %Java_constant_seen;
260 sub get_constant {
261 my ($type, $create) = @_;
262 if (exists $Java_constant_seen{$create}) {
263 return $Java_constant_seen{$create};
264 }
265 my $label = Perlito5::Java::get_label();
266 push @Perlito5::Java::Java_constants, "public static final $type $label = $create;";
267 $Java_constant_seen{$create} = $label;
268 return $label;
269 }
270  
271 # prefix operators that take a "str" parameter
272 our %op_prefix_js_str = (
273 'prefix:<-A>' => 'PerlOp.p5atime',
274 'prefix:<-C>' => 'PerlOp.p5ctime',
275 'prefix:<-M>' => 'PerlOp.p5mtime',
276 'prefix:<-d>' => 'PerlOp.p5is_directory',
277 'prefix:<-e>' => 'PerlOp.p5file_exists',
278 'prefix:<-f>' => 'PerlOp.p5is_file',
279 'prefix:<-s>' => 'PerlOp.p5size',
280 'prefix:<-l>' => 'PerlOp.p5is_symbolic_link',
281 'prefix:<-r>' => 'PerlOp.p5is_readable',
282 'prefix:<-w>' => 'PerlOp.p5is_writable',
283 'prefix:<-x>' => 'PerlOp.p5is_executable',
284 'prefix:<-p>' => 'PerlOp.p5is_named_pipe',
285 );
286  
287 # these operators need 2 "str" parameters
288 our %op_infix_js_str = (
289 'infix:<eq>' => ' == ',
290 'infix:<ne>' => ' != ',
291 'infix:<le>' => ' <= ',
292 'infix:<ge>' => ' >= ',
293 'infix:<lt>' => ' < ',
294 'infix:<gt>' => ' > ',
295 );
296 # these operators always return "bool"
297 our %op_to_boolean = map +($_ => 1), qw(
298 prefix:<!>
299 infix:<!=>
300 infix:<==>
301 infix:<<=>
302 infix:<>=>
303 infix:<>>
304 infix:<<>
305 infix:<eq>
306 infix:<ne>
307 infix:<ge>
308 infix:<le>
309 infix:<gt>
310 infix:<lt>
311 prefix:<not>
312 exists
313 defined
314 );
315 # these operators always return "string"
316 our %op_to_str = map +($_ => 1), qw(
317 substr
318 join
319 list:<.>
320 chr
321 lc
322 uc
323 lcfirst
324 ucfirst
325 ref
326 );
327 # these operators always return "num"
328 our %op_to_num = map +($_ => 1), qw(
329 length
330 index
331 rindex
332 ord
333 oct
334 int
335 infix:<->
336 infix:<+>
337 infix:<*>
338 infix:</>
339 infix:<%>
340 infix:<**>
341 infix:<|>
342 infix:<&>
343 );
344 # these operators always return "scalar"
345 our %op_to_scalar = map +($_ => 1), (
346 keys %op_to_str,
347 keys %op_to_num,
348 keys %op_to_boolean,
349 'circumfix:<[ ]>',
350 'circumfix:<{ }>',
351 qw(
352 infix:<cmp>
353 infix:<<=>>
354 postfix:<++>
355 postfix:<-->
356 prefix:<++>
357 prefix:<-->
358 bless
359 ),
360 # exceptions:
361 # 'prefix:<\\>' because '\(@a)' is a list
362 # 'infix:<=>' depends on the sigil
363 );
364 # these operators will generate native Java code when possible
365 our %native_op = qw(
366 infix:<-> -
367 infix:<+> +
368 infix:<*> *
369 infix:</> /
370 infix:<!=> !=
371 infix:<==> ==
372 infix:<<=> <=
373 infix:<>=> >=
374 infix:<>> >
375 infix:<<> <
376 );
377 our %native_op_unary = qw(
378 postfix:<++> 1
379 postfix:<--> 1
380 prefix:<++> 1
381 prefix:<--> 1
382 );
383 # these operators will generate native Java code when possible; return "boolean"
384 our %native_op_to_boolean = qw(
385 infix:<!=> !=
386 infix:<==> ==
387 infix:<<=> <=
388 infix:<>=> >=
389 infix:<>> >
390 infix:<<> <
391 );
392 our %valid_java_statement = qw(
393 delete 1
394 die 1
395 do 1
396 infix:<=> 1
397 last 1
398 next 1
399 postfix:<++> 1
400 postfix:<--> 1
401 prefix:<++> 1
402 prefix:<--> 1
403 print 1
404 printf 1
405 push 1
406 redo 1
407 return 1
408 say 1
409 shift 1
410 tie 1
411 unshift 1
412 untie 1
413 warn 1
414 );
415 # these variables will be optimized
416 our %special_scalar = (
417 '_' => "Scalar_ARG", # $_
418 '\\' => "Scalar_OUTPUT_RECORD_SEPARATOR", # $\
419 '|' => "Scalar_AUTOFLUSH", # $|
420 '@' => "Scalar_EVAL_ERROR", # $@
421 );
422  
423 my %safe_char = (
424 '\\' => '\\\\',
425 '"' => '\\"',
426 chr(10) => '\\n',
427 chr(13) => '\\r',
428 map { $_ => $_ } (
429 'A' .. 'Z',
430 'a' .. 'z',
431 '0' .. '9',
432 ' ',
433 '!',
434 '#',
435 '$',
436 '%',
437 '&',
438 "'",
439 '(',
440 ')',
441 '*',
442 '+',
443 ',',
444 '-',
445 '.',
446 '/',
447 ':',
448 ';',
449 '<',
450 '=',
451 '>',
452 '?',
453 '@',
454 '[',
455 ']',
456 '^',
457 '_',
458 '`',
459 '{',
460 '|',
461 '}',
462 '~',
463 ),
464 );
465  
466 sub escape_string {
467 my $s = shift;
468 my @out = '"';
469 my $has_char = 0;
470 return '""' if $s eq '';
471 my $v;
472 for my $c ( split "", $s ) {
473 $v = $safe_char{$c};
474 if ( !defined $v ) {
475 if (ord($c) > 65535) {
476
477 # this is necessary to support characters with code > 65535
478 # new String(Character.toChars((int)(1114109L)))
479
480 $v = $safe_char{$c} = "\" + new String(Character.toChars(" . ord($c) . ")) + \"";
481 }
482 else {
483 $v = $safe_char{$c} = "\" + (char)" . ord($c) . " + \"";
484 }
485 }
486 push @out, $v;
487 }
488 push @out, "\"";
489 return join("", @out);
490 }
491  
492 sub is_native {
493 my $self = shift;
494  
495 if ( ref($self) eq 'Perlito5::AST::Var' ) {
496 my $id = $self->{_id};
497 my $sigil = $self->{_real_sigil} || $self->{sigil};
498 if ( $sigil eq '$' && $id ) {
499 my $Java_var = Perlito5::Java::get_java_var_info();
500 my $type = $Java_var->{ $id }{type} || 'PlLvalue';
501 if ($type ne 'PlLvalue') {
502 # my Integer $i
503 return 1;
504 }
505 }
506 }
507  
508 if ( ref($self) eq 'Perlito5::AST::Call' ) {
509  
510 # class method call in native 'Java' packages
511 #
512 # package Sample { import => "misc.Java.Sample" };
513 # Sample->new();
514 # new Sample();
515 #
516 if ( ref($self->{invocant}) eq 'Perlito5::AST::Var' && $self->{invocant}->{sigil} eq '::' ) {
517 my $Java_class = Perlito5::Java::get_java_class_info();
518 if ( exists $Java_class->{$self->{invocant}->{namespace}} ) {
519 return 1;
520 }
521 }
522  
523 # method call on a typed invocant
524 # package Sample { import => "misc.Java.Sample" };
525 # my Sample $s;
526 # $s->meth();
527 #
528 if ( ref($self->{invocant}) eq 'Perlito5::AST::Var' && $self->{invocant}->{_id} ) {
529 my $id = $self->{invocant}->{_id};
530 my $Java_var = Perlito5::Java::get_java_var_info();
531 my $type = $Java_var->{ $id }{type} || 'PlLvalue';
532 if ($type ne 'PlLvalue') {
533 return 1;
534 }
535 }
536  
537 # method call on a "is_native" invocant
538 # package Sample { import => "misc.Java.Sample" };
539 # my Sample $s;
540 # $s->meth()->meth();
541 #
542 if ( is_native($self->{invocant}) ) {
543 return 1;
544 }
545  
546 # type coercion method call on an untyped invocant
547 # package Sample { import => "misc.Java.Sample" };
548 # my $x;
549 # $x->to_Sample();
550 #
551 my $meth = $self->{method};
552 if ( $meth =~ /^to/ ) {
553 # TODO - check for no-arguments
554 my $Java_class = Perlito5::Java::get_java_class_info();
555 for my $info ( values %{$Java_class} ) {
556 if ( $meth eq $info->{perl_to_java} ) {
557 return 1;
558 }
559 }
560 }
561  
562 }
563  
564 return 0; # <- not native (plain Perl)
565 }
566  
567 sub is_native_bool {
568 my $self = shift;
569  
570 # if (is_native($self)) {
571 # return 1;
572 # }
573 if (is_native_args([$self])) {
574 return 1;
575 }
576 my $is_apply = (ref($self) eq 'Perlito5::AST::Apply' ) && $self->{arguments} && @{$self->{arguments}};
577 if ($is_apply && exists $native_op_to_boolean{ $self->{code} } && is_native_args($self->{arguments})) {
578 return 1;
579 }
580 return 0;
581 }
582  
583 sub to_native_arg {
584 my $cond = shift;
585 my $level = shift;
586 my $java_type = shift // '';
587 my $wantarray = 'scalar';
588  
589 return to_native_int($cond, $level, $java_type)
590 if $is_long_type{$java_type} || $is_int_type{$java_type};
591 return to_native_num($cond, $level, $java_type)
592 if $is_float_type{$java_type} || $is_double_type{$java_type};
593 return to_native_bool($cond, $level, $java_type) if $is_boolean_type{$java_type};
594 return to_native_char($cond, $level, $java_type) if $is_char_type{$java_type};
595 return to_native_short($cond, $level, $java_type) if $is_short_type{$java_type};
596 return to_native_byte($cond, $level, $java_type) if $is_byte_type{$java_type};
597  
598 my $is_apply = (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{arguments} && @{$cond->{arguments}};
599  
600 if ( $is_apply && exists $native_op{ $cond->{code} } ) {
601 # TODO - cast arguments to "number", "string" or "boolean" depending on operator
602 return '(' . to_native_num($cond->{arguments}[0], $level) .
603 ' ' . $native_op{ $cond->{code} } . ' ' . to_native_num($cond->{arguments}[1], $level) . ')';
604 }
605 elsif ( $is_apply && exists $op_to_num{ $cond->{code} } ) {
606 if (@{$cond->{arguments}} == 2) {
607 return '(' . $cond->emit_java($level, $wantarray) . ').' .
608 (${$cond->{arguments}}[0]->isa( 'Perlito5::AST::Num' ) || ${$cond->{arguments}}[1]->isa( 'Perlito5::AST::Num' )
609 ? 'to_double()' : 'to_long()');
610 }
611 if (@{$cond->{arguments}} == 1) {
612 return '(' . $cond->emit_java($level, $wantarray) . ').' .
613 (${$cond->{arguments}}[0]->isa( 'Perlito5::AST::Num' )
614 ? 'to_double()' : 'to_long()');
615 }
616 }
617 elsif ( $is_apply && exists $op_to_str{ $cond->{code} } ) {
618 return '(' . $cond->emit_java($level, $wantarray) . ').toString()';
619 }
620 elsif ( (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{code} eq 'undef' ) {
621 return 'null';
622 }
623 elsif ((ref($cond) eq 'Perlito5::AST::Buf' )) {
624 return Perlito5::Java::escape_string( $cond->{buf} );
625 }
626 elsif ((ref($cond) eq 'Perlito5::AST::Int' )) {
627 return $cond->{int};
628 }
629 elsif ((ref($cond) eq 'Perlito5::AST::Num' )) {
630 return $cond->{num};
631 }
632 return $cond->emit_java($level, $wantarray);
633 }
634  
635 sub to_native_args {
636 my $args = shift;
637 my $level = shift;
638 my $java_type = shift;
639 my @out;
640 for my $cond (@$args) {
641 if ( ref($cond) eq 'Perlito5::AST::Apply' && $cond->{arguments} && $cond->{code} eq 'circumfix:<( )>') {
642 push @out, to_native_args( $cond->{arguments}, $level, $java_type )
643 }
644 else {
645 push @out, to_native_arg( $cond, $level, $java_type );
646 }
647 }
648 return join(', ', @out);
649 }
650  
651 sub is_native_args {
652 my $args = shift;
653 my $wantarray = 'scalar';
654 my $s = '';
655 my @out;
656  
657 for my $cond (@$args) {
658 my $is_apply = (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{arguments} && @{$cond->{arguments}};
659  
660 if ( $is_apply && $cond->{code} eq 'circumfix:<( )>') {
661 return 0 unless is_native_args($cond->{arguments});
662 }
663 elsif ( $is_apply && exists $native_op{ $cond->{code} } ) {
664 return 0 unless is_native_args($cond->{arguments});
665 }
666 elsif ( $is_apply && exists $native_op_unary{ $cond->{code} } ) {
667 return 0 unless is_native_args($cond->{arguments});
668 }
669 # elsif ( $is_apply && exists $op_to_num{ $cond->{code} } ) {
670 # push @out, '(' . $cond->emit_java($level, $wantarray) . ').' .
671 # (${$cond->{arguments}}[0]->isa( 'Perlito5::AST::Num' ) || ${$cond->{arguments}}[1]->isa( 'Perlito5::AST::Num' )
672 # ? 'to_double()' : 'to_long()');
673 # }
674 # elsif ( $is_apply && exists $op_to_str{ $cond->{code} } ) {
675 # push @out, '(' . $cond->emit_java($level, $wantarray) . ').toString()';
676 # }
677 # elsif ( (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{code} eq 'undef' ) {
678 # push @out, 'null';
679 # }
680 # elsif ((ref($cond) eq 'Perlito5::AST::Buf' )) {
681 # push @out, Perlito5::Java::escape_string( $cond->{buf} );
682 # }
683 elsif ((ref($cond) eq 'Perlito5::AST::Int' )) {
684 ;
685 }
686 elsif ((ref($cond) eq 'Perlito5::AST::Num' )) {
687 ;
688 }
689 elsif ( ref($cond) eq 'Perlito5::AST::Var' && $cond->{_id} ) {
690 my $id = $cond->{_id};
691 my $Java_var = Perlito5::Java::get_java_var_info();
692 my $type = $Java_var->{ $id }{type} || 'PlLvalue';
693 if ($type eq 'PlLvalue') {
694 return 0;
695 }
696 }
697 else {
698 return 0 unless is_native($cond);
699 }
700 }
701 return 1 if @$args;
702 return 0;
703 }
704  
705 sub to_native_num {
706 my $cond = shift;
707 my $level = shift;
708 my $java_type = shift // '';
709  
710 if ( (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{code} eq 'circumfix:<( )>'
711 && $cond->{arguments} && @{$cond->{arguments}}
712 )
713 {
714 return to_native_num( $cond->{arguments}[0], $level, $java_type )
715 }
716 elsif ((ref($cond) eq 'Perlito5::AST::Buf' )) {
717 my $type_spec = 'D';
718 $type_spec = 'F' if $is_float_type{$java_type};
719 return ( 0 + $cond->{buf} ) . $type_spec;
720 }
721 elsif ((ref($cond) eq 'Perlito5::AST::Int' )) {
722 my $type_spec = 'D';
723 $type_spec = 'F' if $is_float_type{$java_type};
724 return $cond->{int} . $type_spec;
725 }
726 elsif ((ref($cond) eq 'Perlito5::AST::Num' )) {
727 my $type_spec = 'D';
728 $type_spec = 'F' if $is_float_type{$java_type};
729 return $cond->{num} . $type_spec;
730 }
731 else {
732 # TODO - ensure "num"
733 return to_native_args([$cond], $level);
734 }
735 }
736  
737 sub to_native_char {
738 my $cond = shift;
739 my $level = shift;
740 my $java_type = shift // '';
741 return '(char)(' . to_native_int( $cond, $level, 'int' ) . ')' if $java_type eq 'char';
742 return '(new Character((char)' . to_native_int( $cond, $level, 'int' ) . '))';
743 }
744  
745 sub to_native_byte {
746 my $cond = shift;
747 my $level = shift;
748 my $java_type = shift // '';
749 return '(byte)(' . to_native_int( $cond, $level, 'int' ) . ')';
750 }
751  
752 sub to_native_short {
753 my $cond = shift;
754 my $level = shift;
755 my $java_type = shift // '';
756 return '(short)(' . to_native_int( $cond, $level, 'int' ) . ')';
757 }
758  
759 sub to_native_str {
760 my $cond = shift;
761 my $level = shift;
762 my $wantarray = shift;
763 if ( (ref($cond) eq 'Perlito5::AST::Apply') && $cond->{arguments} && @{$cond->{arguments}} ) {
764 if ( $cond->{code} eq 'circumfix:<( )>' ) {
765 return to_native_str( $cond->{arguments}[0], $level, $wantarray )
766 }
767 if ( $cond->{code} eq 'ref' ) {
768 return $cond->{arguments}[0]->emit_java( $level, $wantarray ) . '.ref_str()';
769 }
770 if ( $cond->{code} eq 'list:<.>' ) {
771 return '(' . join( ' + ', map( Perlito5::Java::to_native_str($_, $level, 'scalar'), @{ $cond->{arguments} } ) ) . ')';
772 }
773 }
774 if ((ref($cond) eq 'Perlito5::AST::Buf' )) {
775 return Perlito5::Java::escape_string( $cond->{buf} );
776 }
777 elsif ((ref($cond) eq 'Perlito5::AST::Int' )) {
778 return Perlito5::Java::escape_string( $cond->{int} );
779 }
780 elsif ((ref($cond) eq 'Perlito5::AST::Num' )) {
781 return Perlito5::Java::escape_string( $cond->{num} );
782 }
783 elsif ( ref($cond) eq 'Perlito5::AST::Var' && $cond->{_id} ) {
784 my $id = $cond->{_id};
785 my $Java_var = Perlito5::Java::get_java_var_info();
786 my $type = $Java_var->{ $id }{type} || 'PlLvalue';
787 if ($type ne 'PlLvalue') {
788 return $stringify{$type} . '(' . $cond->emit_java($level, $wantarray) . ')' if $stringify{$type};
789 }
790 }
791 return $cond->emit_java($level, $wantarray) . '.toString()';
792 }
793  
794 sub to_native_int {
795 my $cond = shift;
796 my $level = shift;
797 my $java_type = shift // 'int';
798 my $wantarray = 'scalar';
799  
800 my $type_spec = '';
801 $type_spec = 'L' if $is_long_type{$java_type};
802  
803 my $cast = '.to_int()';
804 $cast = '.to_long()' if $is_long_type{$java_type};
805  
806 my $is_apply = (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{arguments} && @{$cond->{arguments}};
807  
808 if ($is_apply) {
809  
810 if ( $cond->{code} eq 'circumfix:<( )>' ) {
811 return to_native_int( $cond->{arguments}[0], $level, $java_type )
812 }
813 # elsif ( exists $native_op{ $cond->{code} } ) {
814 # return '(' . to_native_num($cond->{arguments}[0], $level, $java_type) . ' '
815 # . $native_op{ $cond->{code} } . ' '
816 # . to_native_num($cond->{arguments}[1], $level, $java_type) . ')';
817 # }
818  
819 if ( $cond->{code} eq 'infix:<+>'
820 && ( $cond->{arguments}[0]->isa( 'Perlito5::AST::Int' )
821 || $cond->{arguments}[1]->isa( 'Perlito5::AST::Int' ) )
822 )
823 {
824 return to_native_int( $cond->{arguments}[0], $level, $java_type ) . " + " . to_native_int( $cond->{arguments}[1], $level, $java_type );
825 }
826 if ( $cond->{code} eq 'infix:<->'
827 && ( $cond->{arguments}[0]->isa( 'Perlito5::AST::Int' )
828 || $cond->{arguments}[1]->isa( 'Perlito5::AST::Int' ) )
829 )
830 {
831 return to_native_int( $cond->{arguments}[0], $level, $java_type ) . " - " . to_native_int( $cond->{arguments}[1], $level, $java_type );
832 }
833  
834 }
835  
836 if ( (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{code} eq 'undef' ) {
837 return '0' . $type_spec;
838 }
839  
840 if ((ref($cond) eq 'Perlito5::AST::Buf' )) {
841 return int( 0 + $cond->{buf} ) . $type_spec;
842 }
843 elsif ((ref($cond) eq 'Perlito5::AST::Int' )) {
844 return int( 0 + $cond->{int} ) . $type_spec;
845 }
846 elsif ((ref($cond) eq 'Perlito5::AST::Num' )) {
847 return int( 0 + $cond->{num} ) . $type_spec;
848 }
849  
850 return $cond->emit_java($level, $wantarray) if is_native($cond); # java native call
851 return $cond->emit_java($level, $wantarray) . $cast;
852 }
853  
854 sub to_str {
855 my $cond = shift;
856 my $level = shift;
857 my $wantarray = 'scalar';
858 if ( (ref($cond) eq 'Perlito5::AST::Apply' ) && $cond->{code} eq 'circumfix:<( )>'
859 && $cond->{arguments} && @{$cond->{arguments}}
860 )
861 {
862 return to_str( $cond->{arguments}[0], $level )
863 }
864  
865 if ( ((ref($cond) eq 'Perlito5::AST::Buf' ))
866 || ((ref($cond) eq 'Perlito5::AST::Apply' ) && exists $op_to_str{ $cond->{code} } )
867 )
868 {
869 return $cond->emit_java($level, $wantarray);
870 }
871 else {
872 return 'new PlString(' . to_native_str($cond, $level, $wantarray) . ')';
873 }
874 }
875 sub to_num {
876 my $cond = shift;
877 my $level = shift;
878 my $type = shift;
879 my $wantarray = 'scalar';
880 if ( (ref($cond) eq 'Perlito5::AST::Int' )
881 || (ref($cond) eq 'Perlito5::AST::Num' )
882 || ((ref($cond) eq 'Perlito5::AST::Apply' ) && exists $op_to_num{ $cond->{code} } )
883 )
884 {
885 return $cond->emit_java($level, $wantarray);
886 }
887 else {
888 # TODO - this converts to "double" - it should be int/double depending on context
889 if ($type eq 'int') {
890 return 'new PlInt(' . $cond->emit_java($level, $wantarray) . '.to_long())';
891 }
892 return 'new PlDouble(' . $cond->emit_java($level, $wantarray) . '.to_double())';
893 }
894 }
895  
896 sub to_native_bool {
897 my $cond = shift;
898 my $level = shift;
899 my $wantarray = 'scalar';
900 my $class = ref($cond);
901  
902 if ( $class eq 'Perlito5::AST::Apply' ) {
903  
904 if ( $cond->{code} eq 'circumfix:<( )>'
905 && $cond->{arguments} && @{$cond->{arguments}}
906 )
907 {
908 if (@{$cond->{arguments}} == 1) {
909 return to_native_bool( $cond->{arguments}[0], $level );
910 }
911 }
912 if ( $cond->{code} eq 'undef' ) {
913 return 'false';
914 }
915 if ( $cond->{code} eq 'ref'
916 && $cond->{arguments} && @{$cond->{arguments}}
917 )
918 {
919 return $cond->{arguments}[0]->emit_java( $level, $wantarray ) . '.ref_boolean()';
920 }
921  
922 # Note: 'infix:<||>' and 'infix:<&&>' can only be optimized here because we know we want "bool"
923 if ( $cond->{code} eq 'infix:<&&>'
924 || $cond->{code} eq 'infix:<and>'
925 )
926 {
927 return '(' . to_native_bool($cond->{arguments}->[0], $level) . ' && '
928 . to_native_bool($cond->{arguments}->[1], $level) . ')'
929 }
930 if ( $cond->{code} eq 'infix:<||>'
931 || $cond->{code} eq 'infix:<or>'
932 )
933 {
934 return '(' . to_native_bool($cond->{arguments}->[0], $level) . ' || '
935 . to_native_bool($cond->{arguments}->[1], $level) . ')'
936 }
937 if ( $cond->{code} eq 'prefix:<!>'
938 || $cond->{code} eq 'prefix:<not>'
939 )
940 {
941 if (@{$cond->{arguments}} == 1) {
942 return '!' . to_native_bool($cond->{arguments}->[0], $level)
943 }
944 }
945 if ( $cond->{code} eq 'infix:<eq>' ) {
946 return to_native_str($cond->{arguments}->[0], $level, 'scalar') . '.equals('
947 . to_native_str($cond->{arguments}->[1], $level, 'scalar') . ')'
948 }
949 if ( $cond->{code} eq 'infix:<ne>' ) {
950 return '!' . to_native_str($cond->{arguments}->[0], $level, 'scalar') . '.equals('
951 . to_native_str($cond->{arguments}->[1], $level, 'scalar') . ')'
952 }
953 if ( $cond->{code} eq 'infix:<le>' ) {
954 return '(' . to_native_str($cond->{arguments}->[0], $level, 'scalar') . '.compareTo('
955 . to_native_str($cond->{arguments}->[1], $level, 'scalar') . ') <= 0)'
956 }
957 if ( $cond->{code} eq 'infix:<ge>' ) {
958 return '(' . to_native_str($cond->{arguments}->[0], $level, 'scalar') . '.compareTo('
959 . to_native_str($cond->{arguments}->[1], $level, 'scalar') . ') >= 0)'
960 }
961 if ( $cond->{code} eq 'infix:<lt>' ) {
962 return '(' . to_native_str($cond->{arguments}->[0], $level, 'scalar') . '.compareTo('
963 . to_native_str($cond->{arguments}->[1], $level, 'scalar') . ') < 0)'
964 }
965 if ( $cond->{code} eq 'infix:<gt>' ) {
966 return '(' . to_native_str($cond->{arguments}->[0], $level, 'scalar') . '.compareTo('
967 . to_native_str($cond->{arguments}->[1], $level, 'scalar') . ') > 0)'
968 }
969  
970 if ( exists $native_op_to_boolean{ $cond->{code} } && is_native_args($cond->{arguments}) ) {
971 return '(' . to_native_num($cond->{arguments}[0], $level) .
972 ' ' . $native_op_to_boolean{ $cond->{code} }
973 . ' ' . to_native_num($cond->{arguments}[1], $level) . ')';
974 }
975  
976 if ( $cond->{code} eq 'defined' ) {
977 my $arg = $cond->{arguments}[0];
978 if ( ref( $arg ) eq 'Perlito5::AST::Apply'
979 && $arg->{code} eq 'prefix:<&>'
980 )
981 {
982 my $arg2 = $arg->{arguments}->[0];
983 return '!PlV.code_lookup_by_name_no_autoload(' . Perlito5::Java::escape_string($Perlito5::PKG_NAME ) . ', ' . $arg2->emit_java($level) . ').is_undef()';
984 }
985 elsif ( ref( $arg ) eq 'Perlito5::AST::Var'
986 && $arg->{sigil} eq '&'
987 )
988 {
989 my $name = $arg->{name};
990 my $namespace = $arg->{namespace} || $Perlito5::PKG_NAME;
991 return '!PlV.cget_no_autoload(' . Perlito5::Java::escape_string($namespace . '::' . $name) . ').is_undef()';
992 }
993 if (is_native($arg)) {
994 return $arg->emit_java($level, 'scalar') . ' != null'
995 }
996 return '!' . $arg->emit_java($level, 'scalar') . '.is_undef()';
997 }
998 if ( $cond->{code} eq 'prefix:<@>'
999 )
1000 {
1001 if (@{$cond->{arguments}} == 1) {
1002 return $cond->emit_java($level, 'list') . '.length_of_array_boolean()';
1003 }
1004 }
1005 }
1006  
1007 if ( $class eq 'Perlito5::AST::Var' && $cond->{sigil} eq '@' ) {
1008 return $cond->emit_java($level, "list") . '.length_of_array_boolean()';
1009 }
1010 elsif ($class eq 'Perlito5::AST::Int') {
1011 if ($cond->{int} == 0) {
1012 return 'false';
1013 }
1014 return '(' . $cond->{int} . ' != 0)';
1015 }
1016 elsif ($class eq 'Perlito5::AST::Num') {
1017 if ($cond->{num} == 0.0) {
1018 return 'false';
1019 }
1020 return '(' . $cond->{num} . ' != 0.0)';
1021 }
1022  
1023 return $cond->emit_java($level, $wantarray) if is_native($cond); # java native call
1024  
1025 if ($class eq 'Perlito5::AST::Apply' && exists $op_to_boolean{ $cond->{code} }) {
1026 return $cond->emit_java($level, $wantarray) . '.to_boolean()';
1027 }
1028 else {
1029 return $cond->emit_java($level, $wantarray) . '.to_boolean()';
1030 }
1031 }
1032  
1033 sub is_scalar {
1034 $_[0]->isa( 'Perlito5::AST::Int' )
1035 || $_[0]->isa( 'Perlito5::AST::Num' )
1036 || $_[0]->isa( 'Perlito5::AST::Buf' )
1037 || Perlito5::AST::Sub::is_anon_sub($_[0])
1038 || ($_[0]->isa( 'Perlito5::AST::Var' ) && $_[0]->{sigil} eq '$')
1039 || ($_[0]->isa( 'Perlito5::AST::Apply' )
1040 && ( exists($op_to_scalar{ $_[0]->{code} })
1041 )
1042 )
1043 }
1044  
1045 sub to_filehandle {
1046 my ($item, $level) = @_;
1047  
1048 if (ref($item) eq 'Perlito5::AST::Block') {
1049 # print { $f } @list
1050 my $stmts = $item->{stmts};
1051 if ( @$stmts == 1 ) {
1052 $item = $stmts->[0];
1053 }
1054 }
1055  
1056 return 'PerlOp.get_filehandle('
1057 . $item->emit_java( $level ) . ', '
1058 . Perlito5::Java::escape_string($Perlito5::PKG_NAME)
1059 . ')'
1060 }
1061  
1062 sub to_method_call_param_list {
1063 my ($this, $items, $level) = @_;
1064 my $items = to_list_preprocess( $items );
1065  
1066 if ((ref($this) eq 'Perlito5::AST::Var') && $this->{sigil} eq '::') {
1067 # convert bareword to string
1068 $this = Perlito5::AST::Buf->new( buf => $this->{namespace} );
1069 }
1070  
1071 'PlArray.construct_list_of_aliases('
1072 . join(', ',
1073 $this->emit_java($level, 'scalar', 'lvalue'),
1074 map( $_->emit_java($level, 'list', 'lvalue'), @$items ),
1075 )
1076 . ')';
1077 }
1078  
1079 sub to_param_list {
1080 my $items = to_list_preprocess( $_[0] );
1081 my $level = $_[1];
1082  
1083 if (@$items == 0) {
1084 return "new PlArray()";
1085 }
1086  
1087 if (@$items == 1) {
1088 my $item = $items->[0];
1089 if ( (ref($item) eq 'Perlito5::AST::Apply') && ( $item->{code} eq 'infix:<..>' ) ) {
1090 return '(PlArray)(' . $item->emit_java($level, 'list') . ')';
1091 }
1092 }
1093  
1094 'PlArray.construct_list_of_aliases('
1095 . join(', ', map( $_->emit_java($level, 'list', 'lvalue'), @$items ))
1096 . ')';
1097 }
1098  
1099 sub to_list_for_push {
1100 my $items = to_list_preprocess( $_[0] );
1101 my $level = $_[1];
1102  
1103 if (@$items == 0) {
1104 return "";
1105 }
1106  
1107 my $item = $items->[0];
1108 if ( @$items == 1 && (ref($item) eq 'Perlito5::AST::Var') && ( $item->{sigil} eq '@' ) ) {
1109 return $item->emit_java($level, 'list');
1110 }
1111  
1112 return join(', ', map( $_->emit_java($level, 'list'), @$items ));
1113 }
1114  
1115 sub to_list {
1116 my $items = to_list_preprocess( $_[0] );
1117 my $level = $_[1];
1118  
1119 if (@$items == 0) {
1120 return "new PlArray()";
1121 }
1122  
1123 my $item = $items->[0];
1124 if ( @$items == 1 && (ref($item) eq 'Perlito5::AST::Var') && ( $item->{sigil} eq '@' ) ) {
1125 return $item->emit_java($level, 'list');
1126 }
1127  
1128 return 'new PlArray('
1129 . join(', ', map( $_->emit_java($level, 'list'), @$items ))
1130 . ')';
1131 }
1132  
1133 sub to_list_preprocess {
1134 my @items;
1135 for my $item ( @{$_[0]} ) {
1136 if ( (ref($item) eq 'Perlito5::AST::Apply' )
1137 && ( $item->{code} eq 'circumfix:<( )>' || $item->{code} eq 'list:<,>' || $item->{code} eq 'infix:<=>>' )
1138 )
1139 {
1140 if ((ref($item) eq 'Perlito5::AST::Apply')
1141 && $item->{code} eq 'infix:<=>>'
1142 )
1143 {
1144 $item->{arguments}[0] = Perlito5::AST::Lookup->autoquote( $item->{arguments}[0] );
1145 }
1146  
1147 for my $arg ( @{ to_list_preprocess($item->{arguments}) } ) {
1148 push( @items, $arg);
1149 }
1150 }
1151 else {
1152 push( @items, $item);
1153 }
1154 }
1155 return \@items;
1156 }
1157  
1158 sub to_scalar {
1159 my $items = to_scalar_preprocess( $_[0] );
1160 my $level = $_[1];
1161 my $wantarray = 'scalar';
1162  
1163 # Note: v = 1,2,5 // 5
1164  
1165 @$items
1166 ? '('
1167 . join(', ', map( $_->emit_java($level, $wantarray), @$items ))
1168 . ')'
1169 : 'null'
1170 }
1171  
1172 sub to_scalar_preprocess {
1173 my @items;
1174 for my $item ( @{$_[0]} ) {
1175 if ( (ref($item) eq 'Perlito5::AST::Apply' )
1176 && ( $item->{code} eq 'list:<,>' || $item->{code} eq 'infix:<=>>' )
1177 )
1178 {
1179 if ((ref($item) eq 'Perlito5::AST::Apply')
1180 && $item->{code} eq 'infix:<=>>'
1181 )
1182 {
1183 $item->{arguments}[0] = Perlito5::AST::Lookup->autoquote( $item->{arguments}[0] );
1184 }
1185  
1186 for my $arg ( @{ to_scalar_preprocess($item->{arguments}) } ) {
1187 push( @items, $arg);
1188 }
1189 }
1190 else {
1191 push( @items, $item);
1192 }
1193 }
1194 return \@items;
1195 }
1196  
1197 sub to_runtime_context {
1198 my $items = to_scalar_preprocess( $_[0] );
1199 my $level = $_[1];
1200 my $wantarray = $_[2]; # 'return';
1201  
1202 my @s = grep {$_ ne ''} map( $_->emit_java($level, $wantarray), @$items );
1203  
1204 return 'PerlOp.context(want)'
1205 if @s == 0;
1206  
1207 return $s[0]
1208 if @s == 1 && is_scalar($items->[0]);
1209  
1210  
1211 if ( @s == 1 && $items->[0]->isa( 'Perlito5::AST::Apply' )
1212 && ( $items->[0]->{code} eq 'circumfix:<( )>' && @{$items->[0]->{arguments}} == 0 )
1213 )
1214 {
1215 # empty list: return ()
1216 return $s[0];
1217 }
1218  
1219 if ( @s == 1 && $items->[0]->isa( 'Perlito5::AST::Apply' )
1220 && ( $items->[0]->{code} && $items->[0]->{namespace} )
1221 )
1222 {
1223 # this looks like a plain-perl subroutine call
1224 return $s[0];
1225 }
1226  
1227 if ( @s == 1 && $items->[0]->isa( 'Perlito5::AST::Call' )
1228 )
1229 {
1230 # TODO - indentify java-native method calls
1231 # this looks like a plain-perl subroutine call
1232 return $s[0];
1233 }
1234  
1235 'PerlOp.context(' . to_context($wantarray) . ', '
1236 . join(', ', @s)
1237 . ')'
1238 }
1239  
1240 sub to_context {
1241 my $wantarray = shift;
1242 $wantarray eq 'list' ? 'PlCx.LIST'
1243 : $wantarray eq 'scalar' ? 'PlCx.SCALAR'
1244 : $wantarray eq 'void' ? 'PlCx.VOID'
1245 : $wantarray eq 'statement' ? 'PlCx.VOID'
1246 : $wantarray eq 'return' ? 'return_context'
1247 : $wantarray eq 'runtime' ? 'want'
1248 : 'want' # default = 'runtime'
1249 }
1250  
1251 sub autoquote {
1252 my $index = shift;
1253 my $level = shift;
1254 $index = Perlito5::AST::Lookup->autoquote($index);
1255 return to_native_str($index, $level);
1256 }
1257  
1258 sub emit_java_autovivify {
1259 my $obj = shift;
1260 my $level = shift;
1261 my $type = shift; # 'array'/'hash'
1262  
1263 if ( (ref($obj) eq 'Perlito5::AST::Index' )
1264 || (ref($obj) eq 'Perlito5::AST::Lookup' )
1265 || (ref($obj) eq 'Perlito5::AST::Call' )
1266 )
1267 {
1268 return $obj->emit_java($level, 0, $type);
1269 }
1270  
1271 # if ( (ref($obj) eq 'Perlito5::AST::Apply' ) && $obj->{code} eq 'prefix:<$>' ) {
1272 # my $arg = $obj->{arguments}->[0];
1273 # return 'get_scalarref('
1274 # . $arg->emit_java( $level ) . ', '
1275 # . Perlito5::Java::escape_string($Perlito5::PKG_NAME) . ', '
1276 # . Perlito5::Java::escape_string($type) # autovivification type
1277 # . ')';
1278 # }
1279  
1280 $obj->emit_java($level)
1281 }
1282  
1283 sub emit_java_list_with_tabs {
1284 my ($level, $argument) = @_;
1285 my $tab = Perlito5::Java::tab($level);
1286 return map { ref($_) eq 'ARRAY'
1287 ? emit_java_list_with_tabs($level+1, $_)
1288 : $tab . $_
1289 }
1290 @$argument;
1291 }
1292  
1293 sub emit_wrap_java {
1294 my ($level, @argument) = @_;
1295 return @argument if wantarray; # nested calls will execute the formatting only once
1296 my $s;
1297 $s = shift @argument if !ref($argument[0]);
1298 return join("\n", ($s ? $s : ()),
1299 emit_java_list_with_tabs($level, [
1300 \@argument,
1301 ]));
1302 }
1303  
1304 sub emit_wrap_statement_java {
1305 my ($level, $wantarray, $argument) = @_;
1306 if ($wantarray eq 'void' || $wantarray eq 'statement') {
1307 return $argument;
1308 }
1309 emit_wrap_java( $level, $argument )
1310 }
1311  
1312 sub emit_wrap_last_exception_java {
1313 my ($self, $stmts, $wantarray) = @_;
1314 my $block_label = Perlito5::Java::get_java_loop_label( $self->{label} );
1315 my $test_label = 'e.label_id != 0';
1316 $test_label = "e.label_id != $block_label && e.label_id != 0"
1317 if $block_label;
1318 my @str = (
1319 "try {",
1320 [ @$stmts ],
1321 '}',
1322 'catch(PlLastException e) {',
1323 [ "if ($test_label) {",
1324 [ "throw e;" ],
1325 "}"
1326 ],
1327 '}' );
1328 if ($wantarray ne 'void' && $wantarray ne 'statement') {
1329 push @str, "return PlCx.UNDEF;";
1330 }
1331 return @str;
1332 }
1333  
1334 1;
1335  
1336 =begin
1337  
1338 =head1 NAME
1339  
1340 Perlito5::Java - Code generator for Perlito Perl5-in-Java
1341  
1342 =head1 SYNOPSIS
1343  
1344 $ast->emit_java($level) # generated Perl5 code
1345  
1346 =head1 DESCRIPTION
1347  
1348 This module generates Java code for the Perlito compiler.
1349  
1350 =head1 AUTHORS
1351  
1352 Flavio Soibelmann Glock <fglock@gmail.com>.
1353 The Pugs Team.
1354  
1355 =head1 COPYRIGHT
1356  
1357 Copyright 2006, 2009, 2011, 2012 by Flavio Soibelmann Glock, Audrey Tang and others.
1358  
1359 This program is free software; you can redistribute it and/or modify it
1360 under the same terms as Perl itself.
1361  
1362 See L<http://www.perl.com/perl/misc/Artistic.html>
1363  
1364 =end