Abstracted file system for DWS, and other news

The DWScript SVN version introduced a file system abstraction (via the dwsFileSystem unit). This is a both a security fix (restrict what scripts see and what the compiler can include) and an enhancement. You can f.i. run your scripts within a virtualized file system limited to a directory, a database, or whatever. At the moment this is still quite experimental and subject to change.

In other news, only in the SVN:

  • format() function: it is seen as taking an array of variant from the script side, but on the Delphi side that array can be seen as a TVarRec array (Delphi’s array of const).
  • multiple fixes for mis-detected or improper compile-time error messages (thanks Alexey Kazantsev!)
  • unit tests coverage for the core compiler and runtime units is now around 70%, still some way to go, but improving.

DWScript 2.1 preview 3 – now with type inference

A DWS 2.1 preview 3 7z archive is available at googlecode Delphi Web Script page, you can also get the same code via SVN of course.

This versions fixes several reported and unreported  issues, and adds support for type inference and Delphi Prism variable initialization syntax. Before you could write code like:

var myInteger : Integer = 1234;
var myObj : TSomeObject = TSomeObject.Create;

where ‘=‘ was used as assignment operator (using the same syntax as for constant declaration or default parameter values), you can now write the above using ‘:=‘ as well

var myInteger : Integer := 1234;
var myObj : TSomeObject := TSomeObject.Create;

and you additionally can make use of type inference and write just

var myInteger := 1234;
var myObj = TSomeObject.Create;

Type inference is currently limited to the variable declaration, this will probably stay for code clarity (opinions?). The inferred type isn’t restricted at the moment, but that will probably change (so you can disallow to inferring to a Variant type f.i.).

DWScript extended language features

DWScript has supported several extensions to the Delphi language since the beginning. Here are a few you may wish the Delphi compiler supported too (and not just Delphi Prism…):

  • generalized case of, which supports non-ordinal type, for instance you can write
    case myString of
      'hello': PrintLn('Hello!');
      'goodbye': PrintLn('See you!');
    end;
  • variables can be declared in-line anywhere in the script, allowing code like
    for i:=1 to 10 do begin
       var k : Integer;
       ...
    end;
  • variables are always initialized, not just global or managed variables
    procedure MyProc;
    var
       k : Integer;
    begin
       ...k is guaranteed to be zero here (unlike in Delphi)
  • variables can be initialized to custom values upon declaration
    var obj : TMyObject = TMyObject.Create;

Delphi Web Script preview 2

A DWS 2.1 preview 2 7z archive is available at googlecode DWScript page, you can also get the same code via SVN of course.

  • added support for the Delphi “Exit” syntax, which allows passing a return value as in Exit(“my return value”)
  • TConfiguration renamed to TdwsConfiguration, some DFM persistence tweaks (less verbose by default, should be backward compatible)
  • improved unit test coverage
  • minor tweaks to runtime or compile-time error messages

As the unit tests “safety net” spreads, I’ll add support for more modern-era Delphi language additions.

DWScript status update

DWScript SVN repository has been fleshed out during the last days:

  • there are now several samples, an half-decent collection of unit tests, and the “classes” library module which offers basic containers.
  • code should be compatible with from Delphi 2009 to Delphi XE.
  • some more optimizations got enabled.
  • timeouts for script execution are now specified in milliseconds (used to be seconds).

A 7zip snapshot of the SVN is available here and will serve as preview.

On a side note, I re-ran the informal performance tests: they are now running about twice faster than during my previous post. Also, one of the demos is used as a floating-point benchmark, and renders a Mandelbrot fractal (once with Delphi, once with DWS). It’ll serve as reference for future progress and help detect performance regressions.

SamplingProfiler v1.7.5

A new version has been released which adds support for the new Delphi XE paths, you can download it here.

Note that there is still a pseudo-random issue of unknown origin under Windows 7, where the utility may or may not be able to gather profiling information. If that happens, close the application and launch it again. The issue doesn’t happen with Windows OSes before 7.

Things on the radar for DWS

Or a roadmap of sorts. The basic idea is to maintain forward compatibility for the “external” aspects: the language and the components. At the same time, the internals of DWS will be subject to evolution, incremental Darwinian evolution, rather than a straight break into some next-gen architecture.

(more…)