Sciter uses JavaScript from now and on

Without too much fanfares Sciter has officially transitioned from TIScript to JavaScript this week.

To be precise, there are two Sciter’s at the moment: Sciter.TIS and Sciter.JS. It is just from now and on Sciter is a synonym of Sciter.JS. And so Sciter.JS is the official, mainstream version.

But Sciter.TIS is still supported and maintained until I have customers that use it.

TIScript was serving Sciter exceptionally well all these 10 years, however 6 months ago I decided to switch to JavaScript. Reasons of why:

  • In ES2020 specification JavaScript finally has reached feature set of TIScript.
  • Fabrice Bellard have created his QuickJS embeddable JS engine, pretty compact and fast and Sciter uses slightly modified QuickJS version.
  • We’ve got tons of JavaScript libraries that can be used as they are in Sciter context.
  • Sciter can be used by any creative Web Front End developer without the need to learn new language.

Paying tributes to TIScript

TIScript is rooted at David Betz’ Bob Language that was published in DDJ in 2002. While I’ve made TIScript syntax explicitly close to JavaScript, its architecture and implementation inherits original structure and features of Bob:

  • Single pass compiler that produces bytecodes;
  • Stack based VM executing those bytecodes;
  • Compacting (copying) GC;

Such foundation worked very well and allowed to evolve original Bob to TIScript with a lot of features of modern PL: real classes, iterators and generators, await/async, built-in persistability, symbols, etc.

TIScript is good and is close to JavaScript but it is not JavaScript though. You cannot take existing JS library and use it in Sciter as it is. So, not without regret, I have decided to switch to JavaScript. QuickJS in particular.

QuickJS, new kid in the block

QuickJS is relatively recent addition to the list of JS implementations . And here are key reasons why I decided to use it:

  • API and integration principles are close to what TIScript uses – it took me just 1 month to add QuickJS to Sciter core. And 4 months more to expose HTML/CSS runtime to JS.
  • Relatively compact implementation – QuickJS is slightly more fatty (by 100 kb) but still in acceptable range. For the note: full version of V8 is about 40 mb – 5 times larger than Sciter itself;
  • Liberal MIT license. Sciter cannot use GPL/LGPL code – many customers expressed this requirement;
  • Readable source code. Well… almost readable.

Architecture of QuickJS:

  • Almost single pass bytecode compiler with additional bytecode passes;
  • Stack based VM;
  • Reference counting GC with loops detection;

If to compare with TIScript the only major difference is reference counting GC and I have mixed feeling about it. RC memory management has as pros as cons , in context of HTML/CSS/UI in particular. Anyway Python uses it all these years in similar circumstances so it definitely will work.

Major benefit of RC GC is that memory management is more deterministic. For example: an object created inside a function can be freed at its exit (if it is not stored anywhere). This may lead to better memory consumption.

On other hand there is a possibility of memory fragmentation on long runs. But we can use other than default memory allocator in QuickJS if this will be a problem. We will see.

TIScript features that are not in JavaScript. Yet?

JavaScript in general is quite foreign to HTML and CSS. While I’ve added better HTML support to QuickJS by adding JSX and reactivity (VNode literals), at the same time CSS constructs are still can be expressed only by their string representations. This involves parsing at runtime when you need to set CSS properties from script – not that good.

TIScript syntax and runtime has the following CSS helper features in this regard:

  • Length, Duration, Angle units.
    In TIScript we can write something like this element.timer(20ms, function() {}) where 20ms is a literal of type Duration. Same thing for length units : = 10em; Pretty convenient and expressive as for me…
  • Tuples.
    Tuples are tagged immutable arrays. Tuples are used in CSS to represent “CSS functions” like
    transform: translate(100px, 20px);
    which, with tuples, can be written as = [translate: 100px, 20px];
    Not an exact match of course, but close.
  • CSS name tokens.
    Name token in CSS is almost a JS one with the only exception: name token in CSS may contain dashes (-).
    It is problematic to use such name tokens in JS – dash there is operator minus, but with the only exception: we can safely add support of such name tokens to object literals so this will be possible: { border-width: 3px }

We can live without all these of course, sky will not fall on us, but aesthetics of our sources is what makes us, developers, at least a bit more happier among boring pages full of JSON and the like constructs.

So welcome to new Sciter!

Leave a Reply

Your email address will not be published. Required fields are marked *