Threaded script execution

The SVN trunk version of DWS now supports threaded script execution.

Things went quite smoothly given that practically all classes got affected, yet all tests pass, including a special threaded torture test, so I’m reasonably confident ;-). The changes are however breaking backward compatibility, hopefully for the best.

Here are the major changes that will affect your code:

  • Scripts used to compile to a TdwsProgram, they now compile to an IdwsProgram
  • An IdwsProgram is a factory for IdwsProgramExecution
  • Script executions now happen via IdwsProgramExecution
  • Messages are now split between IdwsProgram (compile time messages) and IdwsProgramExecution (runtime messages)

You can now have as many program executions for a given IdwsProgram as you wish, each execution will use memory for its heap & stack only, the compiled expression tree is shared. Both new interfaces use reference-counted memory management.

An IdwsProgramExecution is single threaded, but isn’t attached to any particular thread, meaning that it can be moved across threads freely, and re-run as many times as desired. A given TDelphiWebScript compiler component can still only compile one TdwsProgram at once. That said, you can have multiple TDelphiWebScript components, each compiling a different IdwsProgram in a different thread .

It goes without saying that of course, all the above is only valid if all the functions, classes and events you expose to the scripts are themselves thread-safe!

DWScript 2.1 branched

DWScript 2.1 RC2 has been promoted to stable 2.1.0 status, if you already have 2.1 RC2, you don’t need to download anything new.

If you use SVN, there is a now a “stable-2.1” branch which will see only fixes, evolutions and additions will now resume under “trunk”.

What can be expected for DWS 2.2?

In addition to the previously listed goals, which are still part of the background work, there are a few specific goals for 2.2:

  • separating execution context from the expression tree. Currently a compiled script can be run multiple times, but from only one thread at a a time, if you need to run two, you need to compile two instances (thus using up twice the memory). The goal is to allow the same program to be run from multiple threads at the same time.
  • language support for contracts programming.
  • 85% testing code coverage psychological threshold.
  • more demos/samples, at least a couple showcases of IDE/Debugger support features.

Delphi Web Script 2.1 now at RC2

Thanks to all those who reported issues with RC1!
DWScript 2.1 RC2, available there (186 kB) or from DWScript SVN.

  • fixed D2009 compatibility
  • fixed passing of “const” open arrays
  • fixed support of exceptions raised during optimization
  • fixed memory leaks in one of the demos and in some cases of script errors
  • component “uglicons” are now visible again
  • added hints for function calls with no effect (detected after optimization)
  • added some more unit tests
  • improved error messages for various cases of incorrect code

Unless anything major is uncovered, this should be it for 2.1, and a branch will be made in SVN before 2.2 begins.

DWScript RC1 now available

Delphi Web Script 2.1 RC1 is now available from google code DWS page, you can also download it directly as a zip here (184kB).

Changes since the last SVN update are:

  • Added support for FreePascal-like compile-time $INCLUDE “macros”:
    • %FILE% and %LINE% insert the current filename and line number into the source
    • %FUNCTION% inserts the current function name, or class.method name into the source
    • %DATE% and %TIME% allow inserting the compile date/time
  • Various minor optimizations for integers and maths
  • Fixes for some corner-cases, ambiguous error reporting, a few new test cases

Everything’s got to end some day…

…and DWScript will likely enter RC phase before the year ends, as almost all of what I had in mind for 2.1 will be there!

Recent SVN additions since the last update:

  • 75% of the DWScript core code is now covered by unit tests (this was a psychological milestone for 2.1!).
  • class operators have been added, currently those are “+=”, “-=”, “*=” and “/=”, they follow a syntax similar to properties, in that a class operator isn’t defined as a special method, but as syntax sugar for a regular method (see below).
  • Function call overhead has been reduced for in-script functions & methods, as well as TdwsUnit-based functions & methods.
  • TProgramInfo now has ParamAsXxx[] properties, which allow accessing parameters by index and in a more efficient (is less-safe)  fashion.
  • Sqr() became a special function, it will now return an integer and not a float when operating on an integer.
  • Various fixes and error message clarifications (thanks Alexey Kasantsev).

(more…)