[Vm-dev] Re: [OT] MultiByteFileStream

Henrik Sperre Johansen henrik.s.johansen at veloxit.no
Wed May 18 08:40:25 UTC 2011


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.  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20110518/266f81e3/attachment.htm


More information about the Vm-dev mailing list