On Sat, May 21, 2011 at 7:44 AM, David T. Lewis lewis@mail.msen.com wrote:
On Wed, May 18, 2011 at 10:40:25AM +0200, Henrik Sperre Johansen wrote:
On 17.05.2011 20:27, Eliot Miranda wrote:
I'm just trying to eliminate the explicit references to CrLfFileStream in the Cog VMMaker, but I've hit a snag.
Hi Eliot,
I don't know if you have done anything further on this,
yes, I added a single method cuxz there's really only the one case, forceNewFileNamed:. So just one more thing to merge when we get to it :)
but thanks!
but the attached is a trivial replacement for CrLfFileStream that can be used in VMMaker to get rid of the CrLfFileStream dependency and produce <lf> line terminators in the generated sources.
I tried this in VMMaker, changing the references from CrLfFileStream to CCodeFileStream, and it seems fine for all the source code generation.
Let me know what approach you are taking and I'll add the same to VMMaker classic.
HTH, Dave
e.g. there's this idiom:
InterpreterPlugin class methods for translation storeString: s onFileNamed: fileName "Store the given string in a file of the given name."
| f | f := CrLfFileStream forceNewFileNamed: fileName. f nextPutAll: s. f close.
that I'd like to replace with
VMMaker class methods for utilities newFileStream "Always output files in unix lf format. A single format is friendlier to e.g. external version control systems. The Microsoft and old MacOS classic C compilers all accept lf format files."
^MultiByteFileStream new lineEndConvention: #lf; yourself
InterpreterPlugin class methods for translation storeString: s onFileNamed: fileName "Store the given string in a file of the given name."
| f | f := VMMaker newFileStream forceNewFileNamed: fileName. f nextPutAll: s. f close.
but only class-side methods understand forceNewFileNamed:, and hence one would have to write
InterpreterPlugin class methods for translation storeString: s onFileNamed: fileName "Store the given string in a file of the given name."
| f | f := MultiByteFileStream forceNewFileNamed: fileName. f lineEndConvention: #lf. f nextPutAll: s. f close
which is a tad tedious and distributed. I could have a set of convenience methods in VMMaker class, forceNewFileStream: oldFileStream etc. There could be subclasses of MultiByteFileStream purely for instance creation (MultiByteLfFileStream et al). Or...? Any thoughts?
best, Eliot
I'd suggest wrappingthe *fileNamed:do: protocol in a new class, state in the class comment that it's only purpose is to ensure all VM files are written with consistent line endings, and use that class' methods exclusively elsewhere. Doesn't even need to be a subclass really:
VMFileStream class >> forceNewNamed: fileName do: aBlock ^FileStream forceNewFileNamed: fileName do: [:fs | fs lineEndConvention: #lf. aBlock value: fs]
Basically, reintroduce a variant of CRLFFileStream for use specifically in the VM :)
Cheers, Henry