4 chomp(my $lib = `kp6 -lib`);
5 eval("use lib '$lib';");
7 use KindaPerl6
::Runtime
::Perl5
::Runtime
;
8 use File
::Temp
'tmpnam';
9 use Scriptalicious
1.05;
15 open(F
,"|kp6 $args > $tmpfn") or die;
18 my $output = `cat $tmpfn`;
24 print ":h show this help\n";
26 print ":v toggles verbose output\n";
27 print ":5 <p5code> run perl5 code\n";
28 print " <p6code> run perl6 code\n";
29 print ":l <filename> run perl6 file\n";
32 # Design issue [Getting-Expression-Value]
33 # kp6 currently generates p5 code which always evaluates to 1.
34 # So how should we print the value of the user's expression?
35 # One can wrap simple expressions in "say". "say 3;".
36 # But kp6 doesn't currently understand "{;3}" as a way of
37 # wrapping expressions without altering scope.
38 # And wrapping a function and calling it seems likely to
39 # cause trouble (eg, "sub wrap(){ 3 } say wrap();").
42 # Design issue [Perserving-Variables]
43 # kp6 currently uses our() variables, so they are lost at the
44 # end of the eval(), and unavailable for subsequent user input.
45 # For now, accumulate all non-error causing p6, and eval the
46 # entire accumulation.
47 # We can't accumulate p5 instead of p6, because compilation
48 # requires knowing previous declarations.
49 # So the accumulated p6 keeps getting bigger. :( XXX
51 my $accumulated_p6; # See [Perserving-Variables].
56 my @result = eval($p5);
58 # @result is always [1]. See [Getting-Expression-Value].
59 #print "",(map{defined $_ ? $_ : 'undef'}@result),"\n";
65 # XXX Wrap one-liners in say(). See [Getting-Expression-Value].
66 $code = "say $code;" if $code =~ tr/\n/\n/ <= 1;
68 # XXX See [Perserving-Variables].
69 $code = $accumulated_p6 ."\n". $code;
70 my $new_accumulation = $accumulated_p6 ."\n". $p6;
72 my $p5 = call_kp6
($code,'');
74 print call_kp6
($p6,'-ast | perltidy');
75 print "# p5\n",number_the_lines
($p5),"\n";
80 $accumulated_p6 = $new_accumulation if !$@
;
84 my $line = prompt_string
("p5ugs> ");
85 last if !defined $line;
86 if ($line =~ /\A:h\s*\Z/) { print_repl_help
(); next;}
87 if ($line =~ /\A:q\s*\Z/) { exit(0);}
88 if ($line =~ /\A:v\s*\Z/) { $verbose = !$verbose; next;}
89 if ($line =~ /\A:5\s+(.+)/) {
93 if ($line =~ /\A:l\s+(\S+)/) {
95 my $p6 = `cat $filename`;
103 sub number_the_lines
{
106 $s =~ s/^/$cnt++."\t"/mge;