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.