String concatenation redux
In addition to several fixes and improved error detection and messages (thanks Alexey Kasantsev), the DWScript SVN version now includes string concatenation improvement for the common “s := s + …” case.
DelphiTools, SamplingProfiler and General Delphi News
In addition to several fixes and improved error detection and messages (thanks Alexey Kasantsev), the DWScript SVN version now includes string concatenation improvement for the common “s := s + …” case.
Here is a highlight of recent changes on the SVN side of DWScript:
BASM may not be in the Delphi 64 preview, but a proof of concept of “BASM-for-DWS” is now available for DWScript in the SVN!
It builds upon recently introduced “language extensions”, to allow “asm” blocks, which will be pre-parsed (to allow BASM-like references to local variables), and then fed to NASM for actual assembling (which you’ll need to download).
Here is a summary of the recent changes:
for i := 0 to 10 step 2 do ... for i := 100 downto 1 step 3 do ...
Result := value; exit; Exit( value ); exit value;
value not in [...alternatives...] not (value in [...alternatives...])
The first elements to support language extensions are also in, more details coming in a future post!
Delphi arrays have a few quirks (as mentionned here on TURBU f.i.), which arise from there being actually four different types arrays in Delphi, with limited interoperability:
Thing is, all of these arrays have pitfalls of their own, the dynamic array f.i. is a classical trap, and you don’t really want to use it as anything else but a field or local variable. Why? Because it is a reference type which the RTL treats as a value type, f.i.
var a, b : array of Integer; SetLength(a, 1); a[0] := 1; b := a; b[0] := 2; // after that a[0] is 2 SetLength(a, 2); // that effectively decouples a and b a[0] := 3; // after that b[0] is still 2
In other words, the dynamic arrays stays a reference as long as you don’t change its size… If you wonder why using TBytes for holding binary buffer is frowned upon, that is one of the reasons. Things quickly turn to mush if pass a dynamic array around functions (think Java-like deep vs shallow copy mess).
This could all be solved and improved by providing RTL functions that would treat dynamic arrays as a reference type, and ideally by having a new flavor of dynamic arrays with copy-on-write semantics (like what String does for Char, but that would allow any element type).
Though arguably, once you have that new dynamic array, the old dynamic array as a reference type only value would be useful for optimization (to bypass the reference count check when writing to the elements of the array).
Another issue, is that there is little to no cross-array type support, f.i. you can’t initialize a dynamic arrays by assigning to it a constant array f.i., or have inline or default values for typed array parameters, etc.
Why am I mentioning all this? Because I’m currently investigating array support in DWS. Currently DWS doesn’t have dynamic arrays (apart from COM variant arrays), that isn’t too problematic in a scripting language, as you usually don’t code basic containers script-side, and once you have various base TXxxList, you don’t really “need” dynamic arrays, but still, they would be convenient is a variety of situations.
Having more “cooperative” array types is high on the DWS priority list, as uncooperative array types are a recurring PITA in Delphi. Ideally, this cooperativeness would extend to containers (being able to initialize a dynamic array from an enumerator, etc.). But I also don’t want to fork a whole new incompatible Pascal language branch on that aspect, just for DWS.
Hopefully, there will be some debate on this issue, and good ideas may be flown around. ^_^
Current SVN version of Delphi Web Script now supports the following directives (all new but include and filter):
{$INCLUDE 'mysource.inc'}
{$DEFINE SPECIAL_CODE}
{$IFDEF SPECIAL_CODE}
...special code here...
{$ELSE}
...not so special code here...
{$ENDIF}
{$HINT 'That is not wise...'}
{$WARNING 'You should NOT be doing that!'}
{$ERROR 'Do not do that. Period.'}
{$FATAL 'After that, I won''t even try to compile your code!'}
Conditionals are case-insensitive names, conditional blocks can be nested.
Default conditionals when compiling can be adjusted via a new property in the TdwsConfiguration.
edit: added $FATAL
Here is a summary of recent changes for DWScript, available in the SVN version:
Last DWS preview zip was already a while back, so I posted a new preview zip of Delphi Web Script for the SVN-averse.
For the changes since the previous zip, you may want to check here, here and here), as while you’re at it, you may as well check the following:
if (n in [4, 6..8, 10]) then ... if (s in ['abc', 'def']) then ...
Thanks go to Alexey Kazantsev for the testing efforts!
Here is a quick summary of what changed in the SVN since the last update:
var abc : array [1..3] of String = ['a', 'b', 'c']; abc := [ 'hello', 'world', '!'];
A quick update on recent changes in the SVN:
procedure TMyClass.MyMethodWithNoResult; function TMyClass.ReturnsAString : String;
can now alternatively be written as
method TMyClass.MyMethodWithNoResult; method TMyClass.ReturnsAString : String;
both forms are supported, though if you declared as a ‘method‘ in the class, you’ll have to implement as a ‘method‘.