Repository navigation
calc v1.0.20
Calc is now also available as a C extension. One load replaces package require colon, with the same results and faster loading and compiling. This release also adds ++/--, short-circuit &&/||, nested ?:, tuples, Calc::transformProcs, a much larger test suite and a mutation-testing harness.
Downloads
- tcl9x.zip:
calcext.so(Linux) andcalcext.dll(Windows, x64) for Tcl 9.x - tcl86.zip:
calcext.soandcalcext.dllfor Tcl 8.6
Use the build that matches your Tcl version. Loading the wrong one gives a clear error. Then:
load ./calcext.so ;# Windows: load ./calcext.dll
No .tm file, tm::path or rename is needed. After the load, package require colon just returns 1.0 without loading anything, so existing scripts that start with it keep working. Load the extension first, and don't load both the module and the extension in the same interpreter.
The C extension (calcext.c)
- The whole module is now C:
:,=,calc=,proc=,method=,Calc::transformProcs,Calc::debugand the compiler itself. Names, arguments, error messages and generated assembly are the same as the Tcl module. - Compiled procs run at the same speed with either version. The gain is in startup and compile time: about 2x for compiling expressions, about 4x for
proc=definitions andtransform=, a first start about a third of the module's, and each extra interpreter or thread costs about 0.05 ms instead of several ms (10 threads: about 7 ms vs about 25 ms). These timings were measured on Linux; I haven't timed the Windows DLLs. - Verified identical to the Tcl module: both test files, a differential test of about 9,000 cases, and 6,000 random
transform=bodies, on Tcl 8.6.14 and 9.1.1 (Linux). The Windows DLLs were checked to load and work with Tcl 8.6 and 9.x. - Differences: the compiler commands are C commands, so
info procsno longer lists them; the debug-onlydepthcounter is not kept. calc.c(the older extension that only provided::) is kept for history.
New language features
++and--, prefix and postfix, compiled toincrImm&&and||short-circuit likeexpr- Nested
?:without parentheses, right-associative likeexpr - Tuples:
(x,y,z) = list,list -> (x,y,z), nested patterns,_to skip,(a,b,c)to build a list, and strict=> Calc::transformProcscompiles existing procs by name or pattern
Fixes
- Code after a braced block on the same line is kept:
proc= f {args} {: { args -> (a, b, c) }; return "$a $b $c"}used to drop thereturn. - An unterminated block (
: {with no closing brace) now givesline N: Calc: unterminated blockinstead of looping forever.
Tests and docs
- New
calc.test(324 tests: 322 pass, 2 skipped, 0 fail);colon_test.tclextended. Both work with the module or the extension. - Mutation-testing harness in
mutation/: about 1,000 small changes to the module, most of them caught by the tests; the survivors are listed. - Rewritten UserGuide (tuples,
++/--, the C extension) and readme.
Full Changelog: v1.0.19...v1.0.20