Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'no-readlineint'
  • Loading branch information
hoelzro committed Apr 24, 2015
2 parents 5b982d7 + cf14f27 commit 4b13834
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 37 deletions.
5 changes: 0 additions & 5 deletions docs/ops.markdown
Expand Up @@ -1037,11 +1037,6 @@ in the next `$count` bytes from the filehandle and store them in the array.

Return the next line of the open filehandle.

## readlineintfh
* `readlineintfh(Handle $fh, str $prompt)`

Prompt the user with `$prompt`, then return the next line of the open filehandle.

## readcharsfh
* `nqp::readcharsfh(Handle $fh, $chars)`

Expand Down
20 changes: 15 additions & 5 deletions src/HLL/Compiler.nqp
Expand Up @@ -11,6 +11,7 @@ class HLL::Compiler does HLL::Backend::Default {
has @!cli-arguments;
has %!cli-options;
has $!backend;
has $!save_ctx;

method BUILD() {
# Backend is set to the default one, by default.
Expand Down Expand Up @@ -51,24 +52,33 @@ class HLL::Compiler does HLL::Backend::Default {
unless nqp::tellfh(nqp::getstdout()) > $*AUTOPRINTPOS;
}

method readline($stdin, $stdout, $prompt) {
nqp::printfh(nqp::getstdout(), $prompt);
return nqp::readlinefh($stdin);
}

method context() {
$!save_ctx # XXX starting value?
}

method interactive(*%adverbs) {
nqp::printfh(nqp::getstderr(), self.interactive_banner);

my $stdin := nqp::getstdin();
my $stdout := nqp::getstdout();
my $encoding := ~%adverbs<encoding>;
if $encoding && $encoding ne 'fixed_8' {
nqp::setencoding($stdin, $encoding);
}

my $target := nqp::lc(%adverbs<target>);
my $save_ctx;
my $prompt := self.interactive_prompt // '> ';
my $code;
while 1 {
last if nqp::eoffh($stdin);

my str $newcode := nqp::readlineintfh($stdin, ~$prompt);
if nqp::isnull_s($newcode) {
my str $newcode := self.readline($stdin, $stdout, ~$prompt);
if nqp::isnull_s($newcode) || !nqp::defined($newcode) {
nqp::print("\n");
last;
}
Expand All @@ -94,13 +104,13 @@ class HLL::Compiler does HLL::Backend::Default {
$code := $code ~ "\n";
my $output;
{
$output := self.eval($code, :outer_ctx($save_ctx), |%adverbs);
$output := self.eval($code, :outer_ctx($!save_ctx), |%adverbs);
CATCH {
self.interactive_exception($!);
}
};
if nqp::defined($*MAIN_CTX) {
$save_ctx := $*MAIN_CTX;
$!save_ctx := $*MAIN_CTX;
}

$code := "";
Expand Down
1 change: 0 additions & 1 deletion src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -2037,7 +2037,6 @@ QAST::OperationsJAST.map_classlib_core_op('printfh', $TYPE_OPS, 'printfh', [$RT_
QAST::OperationsJAST.map_classlib_core_op('sayfh', $TYPE_OPS, 'sayfh', [$RT_OBJ, $RT_STR], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('flushfh', $TYPE_OPS, 'flushfh', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('readlinefh', $TYPE_OPS, 'readlinefh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('readlineintfh', $TYPE_OPS, 'readlineintfh', [$RT_OBJ, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('readallfh', $TYPE_OPS, 'readallfh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('getcfh', $TYPE_OPS, 'getcfh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('eoffh', $TYPE_OPS, 'eoffh', [$RT_OBJ], $RT_INT, :tc);
Expand Down
15 changes: 0 additions & 15 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -656,21 +656,6 @@ public static String readlinefh(SixModelObject obj, ThreadContext tc) {
}
}

public static String readlineintfh(SixModelObject obj, String prompt, ThreadContext tc) {
if (obj instanceof IOHandleInstance) {
IOHandleInstance h = (IOHandleInstance)obj;
if (h.handle instanceof IIOInteractive)
return ((IIOInteractive)h.handle).readlineInteractive(tc, prompt);
else
throw ExceptionHandling.dieInternal(tc,
"This handle does not support readline interactive");
}
else {
throw ExceptionHandling.dieInternal(tc,
"readlineintfh requires an object with the IOHandle REPR");
}
}

public static String readallfh(SixModelObject obj, ThreadContext tc) {
if (obj instanceof IOHandleInstance) {
IOHandleInstance h = (IOHandleInstance)obj;
Expand Down
1 change: 0 additions & 1 deletion src/vm/moar/QAST/QASTOperationsMAST.nqp
Expand Up @@ -1984,7 +1984,6 @@ QAST::MASTOperations.add_core_moarop_mapping('writefh', 'write_fhb', 1);
QAST::MASTOperations.add_core_moarop_mapping('printfh', 'write_fhs');
QAST::MASTOperations.add_core_moarop_mapping('sayfh', 'say_fhs');
QAST::MASTOperations.add_core_moarop_mapping('readlinefh', 'readline_fh');
QAST::MASTOperations.add_core_moarop_mapping('readlineintfh', 'readlineint_fh');
QAST::MASTOperations.add_core_moarop_mapping('readallfh', 'readall_fh');
QAST::MASTOperations.add_core_op('getcfh', -> $qastcomp, $op {
$qastcomp.as_mast( QAST::VM.new( :moarop('read_fhs'), $op[0], QAST::IVal.new( :value(1) )) )
Expand Down
9 changes: 0 additions & 9 deletions src/vm/parrot/QAST/Operations.nqp
Expand Up @@ -1821,15 +1821,6 @@ QAST::Operations.add_core_op('readlinefh', -> $qastcomp, $op {
$op[0]
))
});
QAST::Operations.add_core_op('readlineintfh', -> $qastcomp, $op {
if +$op.list != 2 {
nqp::die("The 'readlineintfh' op expects two operands");
}
$qastcomp.as_post(QAST::Op.new(
:op('callmethod'), :name('readline_interactive'),
$op[0], $op[1]
))
});
QAST::Operations.add_core_op('readallfh', -> $qastcomp, $op {
if +$op.list != 1 {
nqp::die("The 'readallfh' op expects one operand");
Expand Down
2 changes: 1 addition & 1 deletion tools/build/MOAR_REVISION
@@ -1 +1 @@
2015.04-5-gae63692
2015.04-10-g343ff5b

0 comments on commit 4b13834

Please sign in to comment.