Truffle Language with Binary File input
Jaroslav Tulach
jaroslav.tulach at oracle.com
Sat Aug 1 16:50:05 UTC 2015
Replying to mailing list, as this looks like a generally useful question...
> > Begin forwarded message:
> > Hello.
> >
> > What is the preferred way of implementing a Truffle language that
> > takes a binary file as input?
> >
> > I have a binary file containing the bytecode instructions for the
> > teaching language, and a reader that will read this binary format into
> > an in-memory datastructure.
> >
> > Currently I am overriding :
> > protected Object eval (Source code)
> >
> > in the TruffleLanguage class.
> >
> > I have tried calling:
> > code.getInputStream()
> >
> > to get access to the underlying binary stream, but this doesn't work
> > because the file has been read as a character stream and already has
> > UTF-8 byte order marks inserted everywhere which is corrupting the
> > bytecode format.
> >
> > Thanks!
Yes, we need to get ready for TruffleLanguage to be able to read non-text
data. Right now there is some initial sketch of support for MIME type and I
think we should built on top of it:
1. MIME type should be associated with Source
2. TruffleVM.eval should take Source as its parameter
That way it should be possible to send binary file to TruffleVM as
s = Source.fromBytes(yourArray, "my binary data", "application/g-zip");
truffleVM.eval(s);
and really use s.getInputStream() inside of your TruffleLanguage.parse (there
is no eval method anymore). Would that work for you?
If so, there is just one remaining thing to do: find somebody who's going to
implement this.
-jt
More information about the graal-dev
mailing list