read in script vs compiled

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

read in script vs compiled

Peter Lane
Hi,

I may be misunderstanding something here about how the jvm uses terminal
input, and how that interacts with Kawa.

I am trying to get some user input from the terminal in a script, but I
receive Null pointer errors with Kawa.  On a little investigation, Kawa
does not seem to like input entered from the terminal, but is ok with
input from a redirected file or when compiled to a class file and run
with java, or in the REPL.  (I'm using bash under ubuntu.)

(If I display the current input port I get: #<input-port /dev/stdin>  
which looks right.)

This happens with the simplest file, e.g. a file "read.scm" containing
simply:  (read)

If I compile to a .class file and run it through Java, read works:

$ kawa --main -C read.scm
$ java -cp .:/home/peter/Software/kawa-2.3/lib/kawa.jar read
1

But I get an exception if I use kawa to run the .class file, or if I run
the .scm file as a script:

$ kawa read.scm
1
java.lang.NullPointerException
     at gnu.expr.Compilation.getFileName(Compilation.java:2641)
     at gnu.lists.PairWithPosition.<init>(PairWithPosition.java:74)
     at kawa.lang.Translator.pushPositionOf(Translator.java:1317)
     at kawa.lang.Translator.scanForm(Translator.java:1501)
     at gnu.kawa.lispexpr.LispLanguage.parse(LispLanguage.java:115)
     at gnu.expr.Language.parse(Language.java:776)
     at gnu.expr.Language.parse(Language.java:770)
     at gnu.kawa.io.JLineInPort.parse(JLineInPort.java:93)
     at
org.jline.reader.impl.LineReaderImpl.acceptLine(LineReaderImpl.java:2493)
     at
org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:518)
     at gnu.kawa.io.JLineInPort.fill(JLineInPort.java:163)
     at gnu.kawa.io.InPort.read(InPort.java:445)
     at gnu.kawa.io.TtyInPort.read(TtyInPort.java:227)
     at gnu.kawa.lispexpr.LispReader.readObject(LispReader.java:482)
     at gnu.kawa.lispexpr.LispReader.readObject(LispReader.java:466)
     at kawa.lib.ports.read(ports.scm:367)
     at kawa.lib.ports.read(ports.scm:363)
     at read.run(read.scm:3)
     at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
     at gnu.expr.CompiledModule.evalModule(CompiledModule.java:42)
     at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
     at kawa.Shell.runFile(Shell.java:565)
     at kawa.Shell.runFileOrClass(Shell.java:468)
     at kawa.repl.processArgs(repl.java:700)
     at kawa.repl.main(repl.java:820)

--
Peter Lane
http://peterlane.info/scheme.html

Reply | Threaded
Open this post in threaded view
|

Re: read in script vs compiled

Per Bothner
On 03/09/2017 03:19 PM, Peter Lane wrote:

> Hi,
>
> I may be misunderstanding something here about how the jvm uses terminal input, and how that interacts with Kawa.
>
> I am trying to get some user input from the terminal in a script, but I receive Null pointer errors with Kawa.  On a little investigation, Kawa does not seem to like input entered from the terminal, but is ok with input from a redirected file or when compiled to a class file and run with java, or in the REPL.  (I'm using bash under ubuntu.)
>> ...
> But I get an exception if I use kawa to run the .class file, or if I run the .scm file as a script:
>
> $ kawa read.scm
> 1
> java.lang.NullPointerException
>     at gnu.expr.Compilation.getFileName(Compilation.java:2641)

There is some awkwardness is how Kawa communicates with the JLine
input editor.  (The complication is because we want to handle multi-line
inputs.)

What needs to happen is that the JLineInPort.parse methods needs to
know if we're reading forms (expressions) or "data".  That shouldn't
be very hard, but it is probably a bit "fiddly" figuring out the
right way to do it.

As a work-around, you can disable jline input-editing:

$ kawa console:use-jline=no read.scm
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: read in script vs compiled

Per Bothner
On 03/09/2017 03:47 PM, Per Bothner wrote:

>> I am trying to get some user input from the terminal in a script, but I receive Null pointer errors with Kawa.

This should work now (in the master branch).

> What needs to happen is that the JLineInPort.parse methods needs to
> know if we're reading forms (expressions) or "data".  That shouldn't
> be very hard, but it is probably a bit "fiddly" figuring out the
> right way to do it.

I think I found a fairly clean and simple way to distinguish reading
"data" from the terminal vs reading "code" as part of the REPL.
And you can use the JLine input editor for either.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/