[Vm-dev] Re: [OT] MultiByteFileStream

David T. Lewis lewis at mail.msen.com
Sat May 21 14:44:35 UTC 2011


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, 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

-------------- next part --------------
'From Squeak3.11alpha of 15 May 2011 [latest update: #11424] on 21 May 2011 at 10:17:07 am'!
StandardFileStream subclass: #CCodeFileStream
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'VMMaker-Translation to C'!
!CCodeFileStream commentStamp: 'dtl 5/20/2011 22:59' prior: 0!
A CCodeFileStream reimplements #cr to emit a line feed character. This is intended for generating C source files for use on any platform. All C compilers accept line feed as a line terminator, and the use of a common line terminator convention for storage of C source modules is helpful for consistent version control of C source files.
!


!CCodeFileStream methodsFor: 'character writing' stamp: 'dtl 5/19/2011 08:00'!
cr
	"Assuming the sender means this as a line terminator, convert to
	line feed for use by a C compiler on any platform."

	self lf! !


More information about the Vm-dev mailing list