DWS WebServer with JavaScript CodeGen

dws web serverThe pre-compiled 2014.10.13 version of the DWScript WebServer is now available!

This version includes the Pascal to JavaScript CodeGen!

Here is the download link for the installer:

DWSWebServer 2014.10.13 (1541 kB)

This version also includes all fixes and improvements in DWScript, but the main attraction is the Pascal to JavaScript compiler, which bundles a limited version of SmartMobile Studio compiler. It can be invoked in two ways:

  • inline in a “.dws” file, through the use of a <script type=”pascal”> section, which will be compiled to a <script type=”javascript”> section
  • as a library, through a “.p2js” file, which will be compiled and served as a “.js” file would be

There is only one sample currently, “op4js.dws”, which is a minimalistic illustration of both script execution contexts:

<html><body>
<h3 style="color:blue">Hello OP4JS!</h3>
<div id="count">???</div>
<?pas
// executed server-side when generating page
var i : Integer;
for i := 1 to 5 do
 PrintLn(Format('Test %d<br/>', [i]));
?>
<script type="pascal">
// compiled into javascript
var 
   doc external "document",
   win external "window" : Variant;

var counter : Integer;

procedure IncrementCounter;
begin
   var countDiv := doc.getElementById('count');
   countDiv.innerHTML := IntToStr(counter);
   Inc(counter);
   win.setTimeout(@IncrementCounter, 1000);
end;

IncrementCounter;
</script>

</body></html>

it gets compiled into

<html><body>

<h3 style="color:blue">Hello OP4JS!</h3>
<div id="count">???</div>

Test 1<br/>
Test 2<br/>
Test 3<br/>
Test 4<br/>
Test 5<br/>

<script>
function IncrementCounter() {
 var countDiv;
 countDiv = document.getElementById("count");
 countDiv.innerHTML = counter.toString();
 ++counter;
 window.setTimeout(IncrementCounter,1000);
};
var counter = 0;
IncrementCounter()
</script>

</body></html>

Future posts will introduce more advanced usage scenarios!

6 thoughts on “DWS WebServer with JavaScript CodeGen

  1. Great news!
    Having a compiled official version of pas2js is great, even if the source is still closed. What will be the licensing terms, if we want to include the pas2js compiler as binary to an application (or framework like our little mORMot)?
    This introduces the feasibility of sharing code between server and client side, e.g. for an AJAX application which would share some high-level structures (like record, class or enumerates) on both client and server side.

  2. After looking at the source+exe, sounds like if the pas2j codegen is linked statically to DWSServer.
    It was proposed that the op4js codegen may be released as a binary dll – would it be the case in the close future?

  3. Some time ago SmartMobileStudio announced a FREE command line compiler …but still no news. Is this the actual CLI compiler from SMS ?

  4. @A. Bouchez not sure about licensing terms, best would probably to ask Jorn directly (directly or through a support ticket)

    @Dev Stonez I thought it had been released back in June, but the post does not have the link. I’ll ask where the download is!

    @Andrew Tierney you don’t need an ISAPI, the DWS Web Server uses http.sys and so can share the same port(s) as IIS (and WCF) without the overhead of an ISAPI. Since it runs as a service, it’s also more flexible in terms of maintenance and permissions (see http://www.delphitools.info/2013/08/21/dws-webserver-guide-part-1-getting-started/)

Comments are closed.