Ticket #1115 (closed feature: fixed)

Opened 5 years ago

Last modified 4 years ago

show results of expressions in HLLCompiler based repls (again)

Reported by: riffraff Owned by: pmichaud
Priority: normal Milestone:
Component: PCT Version: trunk
Severity: medium Keywords: repl
Cc: Language:
Patch status: obsolete Platform: all

Description

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.

Attachments

the_p_in_repl.patch Download (2.5 KB) - added by riffraff 5 years ago.
adds a field for printout banner in HLLCompiler's interactive loop

Change History

Changed 5 years ago by riffraff

adds a field for printout banner in HLLCompiler's interactive loop

in reply to: ↑ description ; follow-up: ↓ 2   Changed 5 years ago by jkeenan

Replying to riffraff:

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. All parrot and rakudo tests seem to pass, which means that probably there are no tests for this functionality at all.

If this is the case, and if this patch touches several of the Parrot tools as you indicate, then the first step would be to write the tests needed. I would not recommend adding more functionality to an untested area.

kid51

in reply to: ↑ 1   Changed 5 years ago by riffraff

Replying to jkeenan:

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

If this is the case, and if this patch touches several of the Parrot tools as you indicate, then the first step would be to write the tests needed. I would not recommend adding more functionality to an untested area.

sorry I must have failed to express myself: it does not touch much, if you look at the patch it only does skin-deep changes, about ten lines.

And it does them to an area which basically nobody tests.. I presume because it's difficult to test with the current infrastructure, and because changes are close enough to the surface of the software that they seldom cause problems.

But I understand why untested code should not go in, I just reposted the one year old patch and have no time to improve it now, I'm sorry.

Frankly, though, I believe going from this

> mecbuc:~/Dev/rakudo rff$ ./perl6 
> 1
> 1+12
> 1+3;
> print 1; 
1> say 1
1

to

mecbuc:~/Dev/rakudo rff$ ./perl6 
>> 1
=> 1
>> 1+12
=> 13
>> my $v = [1,2,45]
=> 1 2 45
>> print 'hello'
hello=> 1
>> say 'kewl'
kewl
=> 1
>>

should be pretty close to the top of the wanted features for any interpreter :)

  Changed 4 years ago by coke

  • status changed from new to closed
  • resolution set to fixed
  • patch changed from new to obsolete

Thank you very much for the patch. Sorry for the delay in responding.

These features were recently added into HLL::Compiler (though this patch was not used), so I'm going to close out this ticket.

Please try out a recent version of rakudo to see them in action.

Thanks again.

Note: See TracTickets for help on using tickets.