#1115: show results of expressions in HLLCompiler based repls (again)
----------------------+-----------------------------------------------------
 Reporter:  riffraff  |       Owner:  pmichaud
     Type:  feature   |      Status:  new     
 Priority:  normal    |   Milestone:          
Component:  PCT       |     Version:  trunk   
 Severity:  medium    |    Keywords:  repl    
     Lang:            |       Patch:  new     
 Platform:  all       |  
----------------------+-----------------------------------------------------
 This is a repost of the patch sent one year ago on parrot-bug, to add the
 "print" in REPL to parrot tools.

 all tests still passing but sadly I ahve no time to add more atte moment.

 Basically

 {{{

 mecbuc:~/Dev/parrot/examples/languages/squaak rff$ svn diff
 mecbuc:~/Dev/parrot/examples/languages/squaak rff$ perl Configure.pl &&
 make
 Creating Makefile
 /Users/rff/Dev/parrot/parrot
 /Users/rff/Dev/parrot/runtime/parrot/library/PGE/Perl6Grammar.pbc \
     --output=src/gen_grammar.pir \
     src/parser/grammar.pg
 /Users/rff/Dev/parrot/parrot  /Users/rff/Dev/parrot/compilers/nqp/nqp.pbc
 --output=src/gen_actions.pir \
     --target=pir src/parser/actions.pm
 perl -MExtUtils::Command -e cat src/builtins/say.pir >
 src/gen_builtins.pir
 /Users/rff/Dev/parrot/parrot  -o squaak.pbc squaak.pir
 mecbuc:~/Dev/parrot/examples/languages/squaak rff$ ../../../parrot
 squaak.pbc
 Squaak for Parrot VM
 > var k = 1+2
 => 3
 >

 }}}

 Copy pasted old email follows

 {{{
 the current HLLCompiler infrastructure seems to be an incomplete REPL,
 since it only does Read-Eval-Loop.
 This patch adds a simple Print step and a new attribute
 commandline_result_prompt similar to commandline_prompt, defaulting to
 "=> ".
 It also changes the default commandline_prompt to " >> " to make the
 two vertically aligned.

 A better approach may be splitting the functionality of the
 interactive() method into calls to multiple overrideable methods
 (read, print) to allow further
 customization from users of the class.

 the difference is easy to show, with rakudo:
 >> 1
 => 1
 >> 1+3
 => 4
 >> say "hello"
 hello
 => 1
 >> 1.WHAT
 => Int
 >> 1.HOW
 => get_string() not implemented in class 'P6metaclass'
 current instr.: 'parrot;PCT;HLLCompiler;interactive' pc 1072
 (src/PCT/HLLCompiler.pir:592)
 called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1470
 (src/PCT/HLLCompiler.pir:793)
 called from Sub 'parrot;Perl6;Compiler;main' pc 16749 (perl6.pir:166)

 vs
 > 1
 > 1+3
 > say "hello"
 hello
 > 1.WHAT
 > 1.HOW
 >

 I did not install an exception handler for missing failure in the
 internal say() call cause it feels this should not happen anyway.

 OTOH other exceptions are correctly handled as usual
 >> say miao
 Could not find non-existent sub miao
 >> say $miao
 Scope not found for PAST::Var '$miao'
 >>


 Furthermore, notice that if the result of the operation is null
 nothing is printed (python-like behaviour) so for example the default
 language shell will have

 >> say 1;
 1
 >> say "hello";
 "hello"
 >>

 All parrot and rakudo tests seem to pass, which means that probably
 there are no tests for this functionality at all.

 The patch respects the previous behaviour of special casing the PIR
 target so that it does not print anything else.
 }}}

-- 
Ticket URL: <https://trac.parrot.org/parrot/ticket/1115>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets

Reply via email to