libcwal  Artifact Content

Artifact e3f8882b79250ddff4ee0da86ff27087fdb3731c:

Wiki page [th1ish] by stephan 2016-02-16 11:40:52.
D 2016-02-16T11:40:52.346
L th1ish
P 7d1f6212e783ec1608eac210ef71382842c6b4c7
U stephan
W 5621
<strong>ACHTUNG:</strong> on 201602016, th1ish was remove from the trunk, placed into the [/info/th1ish-R.I.P.|th1ish-R.I.P. branch], kept only for historical interest. It is holding cwal back from several improvements and is not worth the effort to maintain. [s2] is its replacement (and the two are generally about 98% code-compatible when it comes to client-side cwal bindings).

<h1>th1ish - a cwal-based Scripting Language</h1>

<nowiki><pre>
[print "Hello, world!"]
$print 'Hello, world!'
print({Hello, world!})
$print <<<EOF
Hello, world!
EOF
api.io.output("Hello, world!\n")
</pre></nowiki>

th1ish is an experimental/toy scripting language initially (conceptually) based off of TH1, a lesser (and lesser-known) dialect of TCL. th1ish inherits much of TH1's syntax but is expression-centric (not command-centric), adds the richer types supported by cwal (which closely mimics JavaScript), and scoping/lifetime rules similar (but not identical) to C++. While there is still tweaking and experimentation to be done, th1ish is currently functional and ready to use in its original intended role: a simple-to-use platform with which to write scriptable test harnesses for C/C++ libraries and apps, and similar "light" scripting tasks. Binding client-side functionality to scripts is easy to do, including binding custom native types in such a way that th1ish can track their lifetimes and destroy them (using a client-provided finalizer) when the proper time comes.

th1ish is experimental and a toy, but can do far, far more than was originally envisioned/planned for it. (If nothing else, th1ish has proven to be an invaluable test-bed for the core cwal library.) th1ish is essentially feature-complete, but it is continually being tweaked.

See <tt>[/dir?ci=tip&name=th1ish|th1ish/th1ish*.c]</tt> for the current code, <tt>[/dir?ci=tip&name=th1ish|th1ish/shell.c]</tt> for the test app, and <tt>[/dir?ci=tip&name=th1ish/unit|th1ish/unit/*.th1ish]</tt> for various test scripts. th1ish is being documented in detail in a pair of public Google Documents:

   *  [https://docs.google.com/document/d/1PDi7lwufondH4GGRunh1kFSOYkrl1xqL9cXea8mVCLk/view|Main docs]
   *  [https://docs.google.com/document/d/16_SAgIYsQVEDLYAPL4hejcILwRgjw80krPjpe7Aq7Ys/view|Loadable modules docs]. sqlite3/MySQL db access, basic regex support, glob matching, SHA1 hashing, UUID generation, and CGI support all await in the loadable modules.

As of this writing (May 2014), those two docs weighs in at 265 kb of text, just over 100 pages, mostly about how to use it script-side, but also how to use it from C. The docs get updated as the code is written, so they always reflects the [/timeline?r=trunk|current trunk state] or what will be checked into the trunk shortly.


<h1>News</h1>

Newest items at the top.
   *  201405: ongoing experimentation with [/event/45c756c35197991b0312146bfbe53328aa3759e7|the vacuum algorithm] has yielded good results. th1ish now vacuums all scopes regularly except for the global one (where vacuuming breaks, apparently due to (as designed) non-script-visible values being cleaned up).
   *  20140407: th1ish is now being used to write CGI applications. [http://fossil.wanderinghorse.net/repos/cwal/ui2/|This demo site] is implemented entirely in th1ish.
   *  20130722: Added <tt>inherits</tt> keyword, which behaves almost the same as JavaScript's <tt>instanceof</tt>. Added <tt>-I</tt> flag to th1ish shell to dump the cwal string-interning table before cleaning up.
   *  20130720: Added <tt>toss</tt> keyword to replace use of <tt>return</tt> from inside <tt>catch</tt> blocks. Optimizations to how string memory is recycled cut the total memory allocation count anywhere from a few percent to 36%(!!!) in the test scripts.
   *  20130713: Added "popenish" loadable module, which opens a bi-directional read/write stream to a child process. Added "globish" module which provides two forms of glob-like string matching functions. Split loadable module docs into [https://docs.google.com/document/d/16_SAgIYsQVEDLYAPL4hejcILwRgjw80krPjpe7Aq7Ys/view|a separate document]. Started work on a CGI plugin, which sets up the environment based on CGI-related data. The basics are in place, but still deciding on the exact semantics of its output model.
   *  20130712: Added <tt>api.json.parse()</tt>, which converts JSON strings to an Object or Array.
   *  20130711: Added "uuidish" loadable module (adds a <tt>uuid()</tt> function).
   *  20130710: added "sha1ish" loadable module (adds a <tt>sha1()</tt> function). Added handling of <tt>\uXXXX</tt> Unicode character escaping (with 2, 4, 6, or 8 hex digits) in <em>quoted</em> string literals (not identifiers, though that's now possible with a tiny bit of refactoring).
   *  20130706: now skips over <tt>#!shebang</tt> at the start of script to support making scripts executable via the Unix-conventional mechanism. Stack trace optimizations: (1) defer calculation of script location information until an exception is thrown and (2) no longer allocate stack entries on the heap (they're on the stack, of course!). Added bitwise negation operator. Added <tt>-e SCRIPT_CODE</tt> option to the shell app. Moved PCRE code into a loadable module. Still seeing the lurker in the Google Doc.
   *  20130705: Added 'dirent' plugin which adds an <tt>opendir(3)</tt> wrapper.
   *  20130704: added "heredocs" and an "auto-sweep" option (on by default) which cleans temporaries up every few expressions. Started this news list. Someone other than me (no idea who) has been hanging out in the Google Doc for the past two days.
Z 6b83da8a3c6581ff4679ae56aee1fb59