<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DelphiTools.info</title>
	<atom:link href="http://delphitools.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://delphitools.info</link>
	<description>SamplingProfiler, DWS and other Delphi tools</description>
	<lastBuildDate>Tue, 15 May 2012 07:54:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Partial Classes in DWScript</title>
		<link>http://delphitools.info/2012/05/14/partial-classes-in-dwscript/</link>
		<comments>http://delphitools.info/2012/05/14/partial-classes-in-dwscript/#comments</comments>
		<pubDate>Mon, 14 May 2012 06:07:51 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[DWS]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1863</guid>
		<description><![CDATA[Support for partial classes has been added to DWScript: they can be declared as &#8220;class partial (TAncestor)&#8221; as well as with the Oxygene syntax &#8220;partial class (TAncestor)&#8221; syntax. Partial classes allow to split the definition and implementation of a class over multiple files, or over multiple sections of the same file. Partial declarations must have [...]]]></description>
			<content:encoded><![CDATA[<p>Support for <a href="http://en.wikipedia.org/wiki/Class_%28computer_programming%29#Partial">partial classes</a> has been added to DWScript: they can be declared as &#8220;<em>class partial (TAncestor)</em>&#8221; as well as with the <a href="http://wiki.oxygenelanguage.com/en/Partial_Classes">Oxygene syntax</a> &#8220;<em>partial class (TAncestor)</em>&#8221; syntax.</p>
<p>Partial classes allow to split the definition and implementation of a class over multiple files, or over multiple sections of the same file. Partial declarations must have the same modifiers (abstract, sealed, static&#8230;), must specify the same ancestor (or none), however each partial declaration is allowed to introduce new interfaces and their implementations.</p>
<p>Partial class can have multiple purposes, to quote wikipedia:</p>
<ul>
<li>Facilitates the implementation of code generators that have to &#8220;inject&#8221; code declarations/implementations that comes form other descriptions, such as a Visual UI designer, data and string resources, etc.</li>
<li>Enables separation of concerns, in a way similar to aspect-oriented programming but without using any extra tools.</li>
<li>Enables optionally composited functionality, which can be omitted or substituted depending on target or requirements..</li>
<li><del>Enables separation of a class&#8217;s interface and implementation code in a unique way</del>. (irrelevant for Pascal!)</li>
<li>Enables multiple developers to work on a single class concurrently without the need to merge individual code into one file at a later time.</li>
<li>Eases navigation through large classes within a editor.</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/05/14/partial-classes-in-dwscript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mutant records: on methods (and helpers)</title>
		<link>http://delphitools.info/2012/05/07/mutant-records-on-methods-and-helpers/</link>
		<comments>http://delphitools.info/2012/05/07/mutant-records-on-methods-and-helpers/#comments</comments>
		<pubDate>Mon, 07 May 2012 08:19:37 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[DWS]]></category>
		<category><![CDATA[Immutable]]></category>
		<category><![CDATA[Methods]]></category>
		<category><![CDATA[Mutability]]></category>
		<category><![CDATA[Records]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1842</guid>
		<description><![CDATA[When &#8220;record with methods&#8221; were introduced, an important feature was overlooked: mutability. This article discusses the problem, and introduces a possible syntax extension to solve it. Ideas &#38; comments welcome! The Problem Effectively, &#8220;records with methods&#8221; treat all record &#8220;const&#8221; elements as &#8220;var&#8220;, even when they shouldn&#8217;t, and effectively ignores the compiler option &#8220;assignable constants&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>When &#8220;record with methods&#8221; were introduced, an important feature was overlooked: mutability. This article discusses the problem, and introduces a possible syntax extension to solve it. Ideas &amp; comments welcome!</p>
<h4>The Problem</h4>
<p>Effectively, &#8220;<em>records with methods</em>&#8221; treat all record &#8220;<em>const</em>&#8221; elements as &#8220;<em>var</em>&#8220;, even when they shouldn&#8217;t, and effectively ignores the compiler option &#8220;assignable constants&#8221;. Witness the following record:</p>
<pre><strong>type</strong>
   TRec = <strong>record</strong>
      Field : Integer;
      <strong>procedure</strong> IncMe;
   <strong>end</strong>;
...
<strong>procedure</strong> TRec.IncMe;
<strong>begin</strong>
   Inc(Field);
<strong>end</strong>;</pre>
<p>Then the compiler will happily allow you to do:</p>
<pre><strong>const</strong> MyNullRec : TRec = (Field: 0);
...
MyNullRec.IncMe; // watch me, I'm magic!
WriteLn(MyNullRec.Field); // will write 1 !</pre>
<p>&#8230;it will also accept&#8230;</p>
<pre><strong>procedure</strong> Myproc(<strong>const</strong> r : TRec);
<strong>begin</strong>
   r.IncMe; // modified whatever r as if it had been a var
<strong>end</strong>;</pre>
<p>&#8230;and that as well&#8230;</p>
<pre><strong>type</strong>
   TMyClass = <strong>class</strong>
      <strong>private</strong>
         FRec : TRec;
         <strong>procedure</strong> SetRec(const aRec : TRec);
      <strong>public</strong>
         <strong>property</strong> RW : TRec <strong>read</strong> FRec <strong>write</strong> SetRec;
         <strong>property</strong> RO : TRec <strong>read</strong> FRec;
   <strong>end</strong>;
...
<strong>var</strong> myClass : TMyClass;
...
// everything's as it should be there
myClass.RO := aRec; // gives an error
myClass.RW := aRec; // uses SetRec
// but that compiles to...
myClass.RO.IncMe; // modifying a read-only property !
myClass.RW.IncMe; // modifies and bypasses SetRec !</pre>
<p>It would &#8220;compile&#8221; even if the getter was a function returning a record&#8230; or just in about any case, really.</p>
<p>And of course you can cascade all the above in a real-world case, so you end up with weird side-effects and really hard-to-track down bugs.</p>
<p>Besides bug, that also raises the issue of usability of records like <em>TPoint</em> and other simple vector/matrix types, as properties of objects. As long as they did not have methods, you would have to use the setter to modify such a property, so the objects had guaranteed notification of a position change f.i., with methods being able to magically mutate the records, you no longer have that guarantee. And adding all the baggage so that a <em>TPoint</em> can be owned and notify its owner of a change would be over-the-top, wouldn&#8217;t it?</p>
<h4>What&#8217;s Missing</h4>
<p>Two syntax elements are missing:</p>
<ul>
<li>the ability to specify if a method is mutating the record or not, ie. if it should get &#8220;<em>Self</em>&#8221; as a &#8220;<em>var</em>&#8221; or as a &#8220;<em>const</em>&#8220;, so that you can make the above behavior explicit, and the compiler can emit errors when it&#8217;s not appropriate</li>
<li>the ability to mark a record as mutable/immutable, to further remove the ambiguities</li>
</ul>
<p>Ideas for such a syntax, in explicit form, and reusing existing keywords:</p>
<pre><strong>type</strong>
   TRec = <strong>record</strong>
      Field : Integer;
      <strong>var procedure</strong> IncMe; // mutating
      <strong>const function</strong> ToString : String; // non-mutating
   <strong>end</strong>;</pre>
<p>Modifiers in Pascal (except &#8220;<em>class</em>&#8220;) usually follow the declaration, but &#8220;<em>var</em>&#8221; and &#8220;<em>const</em>&#8221; can&#8217;t, as they could be ambiguous with the declaration of a following constant/variant. So if reusing those, rather than introducing new keywords, they have to be in front.</p>
<p>Also you could mark a record as explicitly mutable or immutable, by prefixing it with &#8220;var&#8221; or &#8220;const&#8221;</p>
<pre><strong>type</strong>
   TImmutableRec = <strong>const record</strong>
      Field : Integer;
      <strong>var procedure</strong> IncMe; // mark as explicitly mutating ?
      <strong>function</strong> ToString : String; // non-mutating by default
   <strong>end</strong>;</pre>
<pre>   TMutableRec = <strong>var record</strong>
      Field : Integer;
      <strong>procedure</strong> IncMe; // implicitly mutating
      <strong>const function</strong> ToString : String; // mark as explicitly non-mutating
   <strong>end</strong>;</pre>
<p>For backward compatibility with existing records with methods, the implicit default would have to be &#8220;<em>var record</em>&#8221; as the records are currently all mutable.</p>
<p>With that extra information, the compiler could then perform proper checks and proper parameter passing, so the side-effects mentioned could happen only if you explicitly went for them, rather than by mistake as is currently the case.</p>
<p>Additionally, immutable records would implicitly have their fields as read-only everywhere outside the record constructor (which would then become truly useful as language syntax element). It might also be possible to extend the syntax to be able to declare explicitly immutable classes.</p>
<h4>The case of helpers</h4>
<p>When generalizing helpers (<a href="http://delphitools.info/2012/05/02/helpers-added-to-dwscript/">as in DWScript</a>), the above mutability issue also applies to helpers for value types, ie. records and static arrays, so a similar syntax would have to be introduced.</p>
<p>To minimize side-effects, helpers on record and static arrays currently pass their &#8220;<em>Self</em>&#8221; as const, this allows to use such helpers in all cases (including &#8220;<em>const</em>&#8221; parameters, function results, read-only properties&#8230;), but is restrictive, as it prevents mutation. So once the above syntax is decided upon, it could apply to them as well.</p>
<p>For helpers on reference types in DWScript (classes, interfaces, dynamic arrays), the issue doesn&#8217;t apply.</p>
<p>Note that in Delphi, helpers also have the design bug of being able to magically access private fields&#8230; but that&#8217;s another story.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/05/07/mutant-records-on-methods-and-helpers/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Helpers added to DWScript</title>
		<link>http://delphitools.info/2012/05/02/helpers-added-to-dwscript/</link>
		<comments>http://delphitools.info/2012/05/02/helpers-added-to-dwscript/#comments</comments>
		<pubDate>Wed, 02 May 2012 07:13:22 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[DWS]]></category>
		<category><![CDATA[helpers]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1825</guid>
		<description><![CDATA[In the SVN version, DWScript now has experimental support for helpers. This is a generalization of Delphi&#8217;s class helpers, which can be applied to (almost) any type. You can also have multiple helpers per type. The syntax is currently the following: type TMyHelper = helper for some_type_here private ...private helper methods, class vars &#38; class [...]]]></description>
			<content:encoded><![CDATA[<p>In the SVN version, DWScript now has experimental support for helpers. This is a generalization of Delphi&#8217;s class helpers, which can be applied to (almost) any type. You can also have multiple helpers per type.</p>
<p>The syntax is currently the following:</p>
<pre><strong>type</strong>
   TMyHelper = <strong>helper for</strong> some_type_here
      <strong>private</strong>
         ...private helper methods, class vars &amp; class consts...
      <strong>public</strong>
         ...public helper methods, class vars &amp; class consts...
   <strong>end</strong>;</pre>
<p>You can have helpers for base types, classes, records, interfaces or arrays.</p>
<p>For instance if you write</p>
<pre><strong>type</strong> TFloatHelper = <strong>helper for</strong> Float
      <strong>const</strong> PI = 3.141592;
      <strong>function</strong> ToString : <strong>String</strong>;
   <strong>end</strong>;
...
<strong>function</strong> TFloatHelper.ToString : <strong>String</strong>;
<strong>begin</strong>
   Result := FloatToStr(Self);
<strong>end</strong>;</pre>
<p>then it allows you to code things like &#8216;<em>Float.Pi</em>&#8216; or &#8216;<em>myFloatVar.ToString</em>&#8216;.</p>
<p>The literal form is also accepted (&#8216;<em>TFloatHelper.Pi</em>&#8216; and &#8216;<em>TFloatHelper.ToString(myFloatVar)</em>&#8216;).</p>
<p>It&#8217;s possible to have class methods in helpers, for types with a meta-symbol, Self will be that meta-symbol (f.i. for a TObject helper, Self would be TClass), for others (like Float or records), Self will not be defined.</p>
<p>Current limitations of the experimental support:</p>
<ul>
<li>priority/scope when multiple helpers introduce the same name isn&#8217;t fully spec&#8217;ed yet and may evolve</li>
<li>compiler may accept things it should reject, and vice-versa <img src='http://delphitools.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>parser performance was slightly reduced, optimization will happen when the spec has been completed</li>
<li><del>&#8216;<em>inherited</em>&#8216; isn&#8217;t yet supported to call a non-helped version of an helped member</del> added</li>
<li>suggestions class doesn&#8217;t yet support suggesting helpers</li>
</ul>
<p>The scope resolution when there are multiple-helpers introducing the same method is at the moment not fully defined, currently the compiler will pick the first one it finds in scope. Other options are under considerations: using the same resolution logic as overloads, allowing helpers to be &#8220;sub-classed&#8221; and then using class-like resolution logic&#8230; if you have good ideas pilfered from other languages, or bad approaches that should be avoided, now is the time to chime in!</p>
<p>The syntax will also probably be extended to encompass the Delphi syntax (&#8220;class helper&#8221;) so you can share code, and maybe others variations (&#8220;interface helper&#8221;, &#8220;type helper&#8221;&#8230;) though which/how remains to be determined.</p>
<p>Once all the syntax and scoping elements have been finalized, the compiler will get proper optimizations, but for now, it&#8217;s expected to be somewhat less efficient.</p>
<p>Helpers on functions pointers/delegates types aren&#8217;t yet allowed, mostly because of ambiguity, f.i. in</p>
<pre><strong>type</strong>
   TFunc = <strong>function</strong> : Integer;
   TFuncHelper = <strong>helper for</strong> TFunc
      <strong>function</strong> ToString : <strong>String</strong>;
   <strong>end</strong>;
   TIntegerHelper = <strong>helper for</strong> Integer
      <strong>function</strong> ToString : <strong>String</strong>;
   <strong>end</strong>;
...
<strong>var</strong> f : TFunc;
f.ToString;</pre>
<p>the &#8220;<em>f.ToString</em>&#8221; could be understood as meaning &#8220;<em>TFuncHelper.ToString(f)</em>&#8221; or &#8220;<em>TIntegerHelper.ToString(f())</em>&#8221; if helpers on function pointers were allowed. If a good resolution is found, they could be &#8220;helped&#8221; too, but helpers may not be very relevant to function pointers (?).</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/05/02/helpers-added-to-dwscript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dynamic arrays as stacks, tighter JavaScript</title>
		<link>http://delphitools.info/2012/04/30/dynamic-arrays-as-stacks-tighter-javascript/</link>
		<comments>http://delphitools.info/2012/04/30/dynamic-arrays-as-stacks-tighter-javascript/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 07:45:25 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[DWS]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1763</guid>
		<description><![CDATA[Here is a summary of the changes of recent happenings in the SVN, note that this list doesn&#8217;t include the very latest changes and features, which will get an article of their own. Language: dynamic arrays now support Pop(), Peek() and Push() and can be used as stacks. dynamic arrays Add() and Push() now accept [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a summary of the changes of recent happenings in the SVN, note that this list doesn&#8217;t include the very latest changes and features, which will get an article of their own.</p>
<p>Language:</p>
<ul>
<li>dynamic arrays now support <strong>Pop()</strong>, <strong>Peek()</strong> and <strong>Push()</strong> and can be used as stacks.</li>
<li>dynamic arrays <strong>Add()</strong> and <strong>Push()</strong> now accept a variable number of parameters, and in addition to elements, they now accept dynamic arrays too (which will be concatenated)</li>
<li><strong>Count()</strong> can now be used as an alternative to <strong>Length()</strong> for static and dynamic arrays.</li>
<li><strong>Class var</strong>iables are now supported, both by classes and records.</li>
<li><a href="http://wiki.oxygenelanguage.com/en/Enums">Oxygene-like</a> syntax for explicitly scoped &#8220;enum&#8221;  and &#8220;flags&#8221; is now supported:
<pre>MyEnum = enum (One, Two, Three)
MyFlags = flags (Alpha, Beta, Gamma)</pre>
<p>Both forms must be prefixed, as in <em>MyEnum.Two</em>, the &#8220;enum&#8221; form is otherwise similar to classic enumerations. The flags form is a special case in which the elements values are powers of two (f.i. <em>MyFlags.Beta</em> = 2, <em>MyFlags.Gamma</em> = 4)</li>
<li>class methods can now be marked as <strong>static</strong>.<br />
<strong></strong></li>
<li><strong>Class const</strong> syntax is now supported (had to be written as just &#8216;const&#8217; before)</li>
<li>multi-line indented strings can now be either <strong>#&#8221;</strong> or <strong>#&#8217;</strong></li>
<li>tweaked <strong>overload</strong> metric to give precedence to Float over Integer when Variants are involved</li>
<li>added a new hint if you redeclare a variable with the same name in a local sub-scope (doesn&#8217;t apply across sub-procedures)</li>
<li>improved some error locations, other minor fixes</li>
</ul>
<p>Built-in functions and interfacing:</p>
<ul>
<li>Partial RTTI support for indexed properties (Stefan Glienke)</li>
<li><strong>StrSplit()</strong> splits a string on a delimiter and returns an array of string<br />
StrSplit(&#8216;jan,feb,mar&#8217;, &#8216;,&#8217;) returns ['jan', 'feb', 'mar'] as a dynamic array</li>
<li><strong>StrJoin()</strong> takes an array of string and returns a string made by joining all the individual strings<br />
StrJoin(a, &#8216;,&#8217;) with a the above array would return &#8216;jan,feb,mar&#8217;</li>
</ul>
<p>JavaScript CodeGen:</p>
<ul>
<li>various improvements to the output when optimizing for size (about 10% of size reduction)</li>
<li>fixed an issue with var parameters of a parent procedure used in a local procedure or anonymous method</li>
<li>smart-linker is now capable of eliminating some cases of unused interfaces</li>
<li>fixed an issue with aliased types used as record fields</li>
</ul>
<p>Support Tools:</p>
<ul>
<li>added fledgling code metrics classes</li>
</ul>
<p>As a side note, the recent (and planned) improvements to dynamic arrays are currently tipping the generics vs templates balance towards templates, as they&#8217;re becoming capable enough &#8220;generic collections&#8221; on their own, meaning that &#8220;classic&#8221; generics wouldn&#8217;t bring much extra capability to the language for everyday usage.</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/04/30/dynamic-arrays-as-stacks-tighter-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>OptimalCode &#8211; &#8220;Delphi Optimization Guidelines&#8221;</title>
		<link>http://delphitools.info/2012/04/26/optimalcode-delphi-optimization-guidelines/</link>
		<comments>http://delphitools.info/2012/04/26/optimalcode-delphi-optimization-guidelines/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 06:17:39 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[OptimalCode]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Relics]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1807</guid>
		<description><![CDATA[If you recognize the title of this article by Robert Lee, then chances are you&#8217;ve been around Delphi for a while! Alas the optimalcode.com website and Robert Lee disappeared years ago without a trace, but the &#8220;Delphi Optimization Guidelines&#8221; (dating back from 2002-3003) has been safeguarded and preserved. Recently someone pointed to me that the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://delphitools.info/wp-content/uploads/2012/04/404.jpg"><img class="alignright size-medium wp-image-1808" style="box-shadow: 0px 0px 2px black; border-radius: 5px; margin-right: 5px;" title="404" src="http://delphitools.info/wp-content/uploads/2012/04/404-300x225.jpg" alt="" width="200" height="150" /></a>If you recognize the title of this article by <em>Robert Lee</em>, then chances are you&#8217;ve been around Delphi for a while! <img src='http://delphitools.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Alas the <em>optimalcode.com</em> website and <em>Robert Lee</em> disappeared years ago without a trace, but the &#8220;<em>Delphi Optimization Guidelines</em>&#8221; (dating back from 2002-3003) has been safeguarded and preserved. Recently someone pointed to me that the mirror I had in my <a href="http://delphitools.info/links/">Links</a> section had disappeared too&#8230;</p>
<p>I guess it&#8217;s my turn to host the sacred relics, so I&#8217;ve updated the link and placed not one, but three copies on this site:</p>
<ul>
<li><a href="http://delphitools.info/OptimalCode/opguide.htm">Delphi Optimization Guidelines</a>, browsable version in html</li>
<li><a href="http://delphitools.info/OptimalCode/OptimalCode-Guide-RobertLee.zip"> Delphi Optimization Guidelines</a>, as a zip of html files</li>
<li><a href="http://delphitools.info/OptimalCode/OptimalCode-Guide-RobertLee.pdf"> Delphi Optimization Guidelines</a>, as a PDF</li>
</ul>
<p>The guide is, at the time of this writing, nearly 10 years old, so read it with that in mind!<br />
That said many tips still apply to the 32bit Delphi XE2 compiler, and quite a few tips are valid regardless of compiler and programming language.</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/04/26/optimalcode-delphi-optimization-guidelines/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Delphi &#8220;Meteors&#8221; running Web-side</title>
		<link>http://delphitools.info/2012/04/24/delphi-meteors-running-web-side/</link>
		<comments>http://delphitools.info/2012/04/24/delphi-meteors-running-web-side/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 10:34:43 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[DWS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Meteors]]></category>
		<category><![CDATA[OP4JS]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1796</guid>
		<description><![CDATA[Amongst the samples included with Delphi, you can find a &#8220;Meteors&#8221; clone. With SmartMobileStudio approaching the next beta milestone, I gave it a run at compiling old Delphi code, VCL, TCanvas-based, that was never intended to run Web-side&#8230; but now does! Click here or the image below to test it! The controls are the same [...]]]></description>
			<content:encoded><![CDATA[<p>Amongst the samples included with Delphi, you can find a &#8220;Meteors&#8221; clone. With <a href="http://www.op4js.com/">SmartMobileStudio</a> approaching the next beta milestone, I gave it a run at compiling old Delphi code, VCL, <em>TCanvas</em>-based, that was never intended to run Web-side&#8230; but now does! Click <a href="http://delphitools.info/wp-content/uploads/2012/04/meteors.html">here</a> or the image below to test it!</p>
<p>The controls are the same as in Delphi: arrow keys to turn and accelerate, space bar to fire.</p>
<p style="text-align: left;"><a href="http://delphitools.info/wp-content/uploads/2012/04/meteors.html"><img class="aligncenter size-full wp-image-1800" style="margin-top: 10px; margin-bottom: 10px;" title="Delphi Meteors running Web-side" src="http://delphitools.info/wp-content/uploads/2012/04/meteors.png" alt="" width="619" height="416" /></a>Since the original code is under Embarcadero copyright, I can&#8217;t post the source here, but like with the <a href="http://delphitools.info/2012/03/13/old-school-maze-pascal-to-javascript/">Old School Maze</a>, the amount of adaptations required was minimal, and the old code is running in near-vanilla form (with all its quirks). You can find DMeteor source code in the Samples\Delphi\VCL\Meteor directory that came with Delphi or RAD Studio.</p>
<p style="text-align: left;">The old Delphi code was pegged at 20 FPS and 600&#215;400, and this version is too. Maybe once the <a href="http://www.pascalgamedevelopment.com/forumdisplay.php?72-2nd-PGD-Challenge-The-Journey">PGD Challenge</a> is over, I&#8217;ll try to find time to upgrade it to a 60 FPS, HD version, fix the difficulty and add <a href="http://playtomic.com/?ref=egrange">Playtomic</a> global leader-boards, just to show how simple it can be to leverage Pascal in the HTML5 era  <img src='http://delphitools.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/04/24/delphi-meteors-running-web-side/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Explicitly scoped enums</title>
		<link>http://delphitools.info/2012/03/30/explicitly-scoped-enums/</link>
		<comments>http://delphitools.info/2012/03/30/explicitly-scoped-enums/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 05:37:13 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[DWS]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1793</guid>
		<description><![CDATA[Oxygene syntax (aka Delphi Prism) for enumerations was recently added to DWScript, with both enum and flags contextual keywords. Enumerations scoping was already in, but optional, using these keywords make scoping explicitly required. type    TMyEnum = enum (Alpha, Beta, Gamma); ... e := TMyEnum.Alpha; // works e := Alpha; // syntax error Since the scoping [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.oxygenelanguage.com/en/Enums">Oxygene syntax</a> (aka Delphi Prism) for enumerations was recently added to <a href="http://delphitools.info/dwscript/">DWScript</a>, with both <strong>enum</strong> and <strong>flags</strong> contextual keywords. Enumerations scoping was already in, but optional, using these keywords make scoping explicitly required.</p>
<pre><strong>type</strong>
   TMyEnum = <strong>enum</strong> (Alpha, Beta, Gamma);
...
e := TMyEnum.Alpha; // works
e := Alpha; // syntax error</pre>
<p>Since the scoping with this declaration syntax is explicit, you&#8217;re encouraged not to use prefixing for the enumeration elements, removal of the leading &#8220;T&#8221; being optional.</p>
<p>Classic enumerations (without keyword) stay globally scoped and unchanged for now (so this addition is fully backward-compatible).</p>
<p>Besides adding support for one more Oxygene syntax elements (alongside method, implies, contracts, etc.), this also provides a cleaner syntax than the <em>{$SCOPEDENUMS}</em> directive-based  approach introduced with Delphi XE2, with which you end up having to wrap enum declarations between directives (cf. VCL &amp; FMX source).</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/03/30/explicitly-scoped-enums/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Rid of the Middleman</title>
		<link>http://delphitools.info/2012/03/28/getting-rid-of-the-middleman/</link>
		<comments>http://delphitools.info/2012/03/28/getting-rid-of-the-middleman/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 06:23:05 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[asm]]></category>
		<category><![CDATA[Bottleneck]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1775</guid>
		<description><![CDATA[On this StackOverflow question David Heffernan asked about a hack I&#8217;m using in DWScript&#8217;s UnifyAssignString. TStringListCracker The code of the function looks like: procedure UnifyAssignString(const fromStr : UnicodeString; var toStr : UnicodeString); var i : Integer; sl : TUnifierStringList; begin if fromStr = '' then toStr := '' else begin i := Ord(fromStr[1]) and High(vCharStrings); [...]]]></description>
			<content:encoded><![CDATA[<p>On this <a href="http://stackoverflow.com/questions/9885335/how-to-install-dwsscript/">StackOverflow question</a> David Heffernan asked about a hack I&#8217;m using in DWScript&#8217;s <em>UnifyAssignString</em>.</p>
<h4>TStringListCracker</h4>
<p>The code of the function looks like:</p>
<pre><strong>procedure </strong>UnifyAssignString(<strong>const</strong> fromStr : UnicodeString; <strong>var</strong> toStr : UnicodeString);
<strong>var</strong>
   i : Integer;
   sl : TUnifierStringList;
<strong>begin</strong>
   <strong>if</strong> fromStr = '' <strong>then</strong>
      toStr := ''
   <strong>else begin</strong>
      i := Ord(fromStr[1]) <strong>and</strong> High(vCharStrings);
      sl := vCharStrings[i];
      sl.FLock.Enter;
      i := sl.AddObject(fromStr, <strong>nil</strong>);
      <strong><span style="color: #0000ff;">toStr := TStringListCracker(sl).FList[i].FString; // HACK HERE</span></strong>
      sl.FLock.Leave;
   <strong>end</strong>;
<strong>end</strong>;</pre>
<p>The non-hacky variant would be to have that line just be</p>
<pre>toStr := sl[i];</pre>
<p>but if you use that simpler form, you could see a <em>performance drop by up to <strong>45%</strong></em> (Delphi XE and XE2 32bit) or <em><strong>38%</strong></em> (Delphi XE2 64bit).</p>
<p><strong>Ouch! Why is that?</strong></p>
<h4>The hacky version</h4>
<p>The hacky version compiles to a single <em>UStrAsg</em>, the internal function for string assignment which takes care of the reference-counting. So it&#8217;s just:</p>
<pre>dwsUtils.pas.487: toStr:=TStringListCracker(sl).FList[i].FString;
00511594 8B0424           <strong>mov eax,[esp]</strong>
00511597 8B532C           <strong>mov edx,[ebx+$2c]</strong>
0051159A 8B14F2           <strong>mov edx,[edx+esi*8]</strong>
0051159D E8A659EFFF       <strong>call @UStrAsg</strong></pre>
<p><em>i</em> having been returned by <em>AddObject</em>, no range-check is required.</p>
<p>(note that <em>TStrings.AddObject</em> is called directly because <em>TStrings.Add</em> is just an indirection to <em>AddObject</em>)</p>
<h4>What about the &#8220;<em>toStr := sl[i]</em>&#8221; version?</h4>
<p>The property is just syntax sugar on a getter method, so what is actually compiled is  &#8220;<em>toStr := sl.Get(i)</em>&#8220;, which itself, being a virtual call, looks like</p>
<pre>toStr := sl.VMT[ TStrings_Get ]( sl, i );</pre>
<p>However the virtual call to <em>TStringList.Get</em> on its own costs only a tiny bitsy of extra CPU cycles, though it also prevents inlining (at least, until the compiler gets de-virtualisation optimizations).</p>
<p>But there are other factors at work, the virtual call on its own can&#8217;t come close to explaining the performance differential, as after all, the rest of the code <em>UnifyAsstringString</em> is far from trivial (with a critical section and a binary search&#8230;)</p>
<p>First, it&#8217;s a function returning a string, which is a managed type, so it&#8217;s actually compiled to something like:</p>
<pre><strong>try</strong>
   temp := sl.getValue( i );
   UStrAsg( toStr, temp );
<strong>finally</strong>
   UStrClr( temp );
<strong>end</strong>;</pre>
<p>Second,<em> TStringList.GetValue</em> itself is compiled to</p>
<pre>TStringList.Get:
00448204 53               push ebx
00448205 56               push esi
00448206 57               push edi
00448207 8BF9             mov edi,ecx
00448209 8BF2             mov esi,edx
0044820B 8BD8             mov ebx,eax
0044820D 3B7330           cmp esi,[ebx+$30]
00448210 720F             jb $00448221
00448212 8B1544EA5100     mov edx,[$0051ea44]
00448218 8BCE             mov ecx,esi
0044821A 8BC3             mov eax,ebx
0044821C E8C3E3FFFF       call TStrings.Error
00448221 8BC7             mov eax,edi
00448223 8B532C           mov edx,[ebx+$2c]
00448226 8B14F2           mov edx,[edx+esi*8]
00448229 E81AEDFBFF       call @UStrAsg
0044822E 5F               pop edi
0044822F 5E               pop esi
00448230 5B               pop ebx
00448231 C3               ret</pre>
<p>That&#8217;s quite a lot of code, a fair share of it is spent juggling registers because TStringList.Get is implemented as</p>
<pre><strong>function</strong> TStringList.Get(Index: Integer): string;
<strong>begin</strong>
   <strong>if</strong> Cardinal(Index) &gt;= Cardinal(FCount) <strong>then</strong>
      Error(@SListIndexError, Index);
   Result := FList^[Index].FString;
<strong>end</strong>;</pre>
<p>If the range check fails, <em>Error</em> triggers an exception and the last line won&#8217;t ever be reached, but the compiler can&#8217;t know that, so it compiles everything assuming the last line can be reached even after an Error, thus has to save the parameters, hence the stack juggling.</p>
<p>(the fix to the juggling? use an &#8220;else&#8221;)</p>
<p>Apart from that issue, there remains in <em>TStringList.Get</em> a range check and an extra <em>UStrAsg</em> call.</p>
<p>And UStrAsg itself includes an atomic incrementation instruction (bus locking)</p>
<pre>lock inc dword ptr [edx-$08]</pre>
<p>Even though modern CPUs handle them far more efficiently than their ancestors, atomic instructions still cost quite a bit more than their non-atomic counterparts, and the more multi-threaded you are, the more expensive they get.</p>
<h4>Summary</h4>
<p>So when all is said and done, the hacky version has:</p>
<ul>
<li>1 atomic instruction (1 UStrAsg)</li>
<li>1 call</li>
</ul>
<p>While the non-hacky version has</p>
<ul>
<li>3 atomic instruction (2 UStrAsg, 1 UStrClr)</li>
<li>4 calls (2 UStrAsg, 1 UStrClr, 1 TStringList.Get)</li>
<li>1 exception frame (free in 64bit, not free in 32bit)</li>
<li>higher register pressure in <em>UnifyAssignString</em></li>
<li>1 range check</li>
<li>a lot of register juggling (especially in 32bit)</li>
</ul>
<p>So while &#8220;cracking&#8221; <em>TStringList</em> isn&#8217;t safe, depending on the circumstances, you can use it to achieve a boost for very little extra complexity.</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/03/28/getting-rid-of-the-middleman/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>2nd PGD Challenge Official Announcement</title>
		<link>http://delphitools.info/2012/03/20/2nd-pgd-challenge-official-announcement/</link>
		<comments>http://delphitools.info/2012/03/20/2nd-pgd-challenge-official-announcement/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 09:13:50 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[PGD]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1755</guid>
		<description><![CDATA[Planned dates are from March 30th to April 29th, below is an excerpt from the announcement, head over to the PGD Challenge page for more details: In a couple of weeks we are going to start the next PGD Challenge with a brand new theme. As promised it will be simple, yet fun for creating [...]]]></description>
			<content:encoded><![CDATA[<p><a title="2nd PGD Challenge Official Announcement" href="http://www.pascalgamedevelopment.com/content.php?323-2nd-PGD-Challenge-Official-Announcement"><img class="alignright size-medium wp-image-1758" title="2nd-PGD-Challenge-Poster" src="http://delphitools.info/wp-content/uploads/2012/03/2nd-PGD-Challenge-Poster-205x300.jpg" alt="" width="205" height="300" /></a>Planned dates are <strong>from March 30th to April 29th</strong>, below is an excerpt from the announcement, head over to the <a href="http://www.pascalgamedevelopment.com/content.php?323-2nd-PGD-Challenge-Official-Announcement">PGD Challenge</a> page for more details:</p>
<p>In a couple of weeks we are going to start the next PGD Challenge with a brand new theme. As promised it will be simple, yet fun for creating ideas. The development period will last about 4 weeks, plus a weekend to wrap things up. All are welcome to participate.</p>
<p>It&#8217;s going to be a lot of fun. There is lots of possibilities from the theme I&#8217;ve picked and I hope you will have fun with it.</p>
<p>All game entries must be made using a Pascal-based programming language or they will be disqualified. The game can take advantage of any game library or API written in another language, but the core of the game must be written in a Pascal-based language.</p>
<p>Allowed Pascal-based Languages:</p>
<ul>
<li>Pascal (aka Classic Pascal, Borland Pascal, etc)</li>
<li>Object Pascal (called &#8220;Delphi language&#8221; by some)</li>
<li>Objective-Pascal</li>
<li>Oxygene (new language based on Object Pascal)</li>
</ul>
<p>Key Development tools that support the above languages:</p>
<ul>
<li>Delphi</li>
<li>Free Pascal</li>
<li>Lazarus</li>
<li>Prism (Oxygene for .NET)</li>
<li>Oxygene for Java</li>
<li>Smart Mobile Studio</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/03/20/2nd-pgd-challenge-official-announcement/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Old School Maze Pascal to JavaScript</title>
		<link>http://delphitools.info/2012/03/13/old-school-maze-pascal-to-javascript/</link>
		<comments>http://delphitools.info/2012/03/13/old-school-maze-pascal-to-javascript/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 07:11:49 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://delphitools.info/?p=1740</guid>
		<description><![CDATA[Zarko Gajic recently reposted Kostas Symeonidis&#8217;s Maze, this is an old code (2004) that generates a random maze using Prim&#8217;s algorithm and solves it. I wondered how it would hold its own when compiled to JavaScript, and by that I mean compiling the old 2004 source&#8230; click on the picture to the right to run [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://delphi.about.com/b/2012/03/09/maze-creation-and-solving-tool-source-code-delphi-application.htm">Zarko Gajic</a> recently reposted <a href="http://www.cylog.org/sourcecode/maze.jsp">Kostas Symeonidis&#8217;s Maze</a>, this is an old code (2004) that generates a random maze using <a href="http://en.wikipedia.org/wiki/Prim%27s_algorithm">Prim&#8217;s algorithm</a> and solves it.</p>
<p><a title="Maze" href="http://delphitools.info/wp-content/uploads/2012/03/index.html"><img class="alignright size-full wp-image-1741" title="maze" src="http://delphitools.info/wp-content/uploads/2012/03/maze.png" alt="" width="212" height="218" /></a>I wondered how it would hold its own when compiled to JavaScript, and by that I mean compiling the old 2004 source&#8230; click on the picture to the right to run a version compiled with <a href="http://op4js.com/">SmartMobileStudio</a>. Works in all the usual desktop and mobile suspects. Click or touch the maze to solve between arbitrary locations.</p>
<p>The original source works on a large static array that is passed as var parameter and where the bytes are used in a bitwise fashion. All in all it does its job in a brute-force native-compiler friendly way, but is quite suboptimal for a JS execution. Anyway I compiled as close as possible to the original (update <a href="http://delphitools.info/wp-content/uploads/2012/03/Maze.zip">source zip</a>, 6kB).</p>
<p>Very few changes were required to get it to compile:</p>
<ul>
<li>changed the <em>TObjectList</em> to an &#8220;<em>array of TCell</em>&#8220;</li>
<li>replaced <em>Random()</em> with <em>RandomInt()</em></li>
<li>replaced the <em>FillChar()</em> with nested loops</li>
<li>mapped <em>TCanvas</em> to <em>TW3Canvas</em></li>
</ul>
<p>But the bulk of the code compiled without changes, and runs in Android, Chrome, IE9, etc. (only FireFox has a glitch, which is not related to the Maze code, but to the VJL and a Mozilla event name).</p>
]]></content:encoded>
			<wfw:commentRss>http://delphitools.info/2012/03/13/old-school-maze-pascal-to-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  delphitools.info/feed/ ) in 4.67746 seconds, on May 18th, 2012 at 7:02 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 19th, 2012 at 7:02 am UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  delphitools.info/feed/ ) in 0.00091 seconds, on May 18th, 2012 at 9:57 am UTC. -->
