<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 17.05.2011 20:27, Eliot Miranda wrote:
<blockquote
cite="mid:BANLkTikLt2pqwsjz-dpkmFO2F4C0FdGh-g@mail.gmail.com"
type="cite">
<pre wrap=""> </pre>
<div class="gmail_quote">
<div>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:</div>
<div><br>
</div>
<div>InterpreterPlugin class methods for translation</div>
<div>storeString: s onFileNamed: fileName</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>"Store
the given string in a file of the given name."</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>|
f |</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>f
:= CrLfFileStream forceNewFileNamed: fileName.</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>f
nextPutAll: s.</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>f
close.</div>
<div><br>
</div>
<div>that I'd like to replace with</div>
<div><br>
</div>
<div>VMMaker class methods for utilities</div>
<div>
<div>newFileStream</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>"Always
output files in unix lf format.</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>A
single format is friendlier to e.g. external version control
systems.</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>The
Microsoft and old MacOS classic C compilers all accept lf
format files."</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>^MultiByteFileStream
new</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>lineEndConvention:
#lf;</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>yourself</div>
</div>
<div><br>
</div>
<div>
<div>InterpreterPlugin class methods for translation</div>
<div>storeString: s onFileNamed: fileName</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>"Store
the given string in a file of the given name."</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>|
f |</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>f
:= VMMaker newFileStream forceNewFileNamed: fileName.</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>f
nextPutAll: s.</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>f
close.</div>
</div>
<div><br>
</div>
<div>but only class-side methods understand forceNewFileNamed:,
and hence one would have to write</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div><br>
</div>
<div>
<div>InterpreterPlugin class methods for translation</div>
<div>storeString: s onFileNamed: fileName</div>
<div><span class="Apple-tab-span" style="white-space: pre;">
</span>"Store the given string in a file of the given
name."</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space: pre;">
</span>| f |</div>
<div><span class="Apple-tab-span" style="white-space: pre;">
</span>f := MultiByteFileStream forceNewFileNamed:
fileName.</div>
<span class="Apple-style-span" style="white-space: pre;"> f
</span>lineEndConvention: #lf.
<div><span class="Apple-tab-span" style="white-space: pre;">
</span>f nextPutAll: s.</div>
<div><span class="Apple-tab-span" style="white-space: pre;">
</span>f close</div>
</div>
</div>
<div><br>
</div>
<div>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?</div>
<div><br>
</div>
<div>best,</div>
<div>Eliot</div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
<div>
<div class="h5">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;"><br>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br>
</blockquote>
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. <br>
Doesn't even need to be a subclass really:<br>
<br>
VMFileStream class >> forceNewNamed: fileName do: aBlock<br>
^FileStream forceNewFileNamed: fileName do: [:fs |<br>
fs lineEndConvention: #lf.<br>
aBlock value: fs]<br>
<br>
Basically, reintroduce a variant of CRLFFileStream for use
specifically in the VM :)<br>
<br>
Cheers,<br>
Henry<br>
</body>
</html>