Find beneath this paragraph a spring mishmash of recent happenings from the DWScript repository!

Overview Dialog, Lambdas and Templates.

Templates/Generics

The long planned support for templates has begun!

As it represents a significant workload (especially to ensure a good test coverage), it is being introduced piecemeal, type by type, expression by expression, with unit tests added along the way.

The syntax is similar to Delphi, and ultimately, the goal is to handle all the cases Delphi can… but it is really a template approach rather than a generic one. This means that while the templates are parsed, and while constraints are supported, the final strong typechecks occur when specializing a template rather than when compiling the template.

The aim here is to be able to support operators, so that you can write code like

function TWhatever<T>.Sum(a, b : T) : T; begin Result := a + b; end;

which will work for any type T that suports a ‘+’ operator, and similarly for all the comparison operators, helpers, and other basic functionality. All this with neither complex low-level machinery nor interface-based overhead.

If a type does not support ‘+’ then you will get that error when trying to write ‘TWhatever<Boolean>’ for instance.

The other immediate usage case for templates is in SmartPascal, to facilitate the declaration of strongly-typed external classes (for instance for Promises).

Currently, the template support does not extend much beyond what’s in the unit tests, for everything else, you will get errors like “TdwsWhateverInternalClass does not support specialization yet”.

Overview Dialog

The SourceUtils\dwsOverviewDlg unit implements a simple overview dialog for a code editor.

It is a tree view that lists all declared types and methods in a source files, and can be used to jump in a code editor across declaration, methods and implementations.



Partial Lambda support in Scripts

Lambdas (and anonymous methods) that are not closures are now allowed in scripts, formerly they were only accepted for the JavaScript codegen (SmartPascal).

Not being a closure means they cannot capture anything from their context. While this is very restrictive, this still opens a variety of uses, like for array sort and map functions, where you sometimes do not need any context, and where using a lambda can lead to clearer code than declaring a function and then referring it.

Miscellanious

The JavaScript codegen received a few minor improvements.

Imrpoved test coverage and some error reporting.