Skip to content

calc v1.0.20

Latest

Choose a tag to compare

@rocketship88 rocketship88 released this 14 Nov 00:56
· 4 commits to main since this release
0c945d1

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) and calcext.dll (Windows, x64) for Tcl 9.x
  • tcl86.zip: calcext.so and calcext.dll for 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::debug and 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 and transform=, 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 procs no longer lists them; the debug-only depth counter is not kept.
  • calc.c (the older extension that only provided ::) is kept for history.

New language features

  • ++ and --, prefix and postfix, compiled to incrImm
  • && and || short-circuit like expr
  • Nested ?: without parentheses, right-associative like expr
  • Tuples: (x,y,z) = list, list -> (x,y,z), nested patterns, _ to skip, (a,b,c) to build a list, and strict =>
  • Calc::transformProcs compiles 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 the return.
  • An unterminated block (: { with no closing brace) now gives line N: Calc: unterminated block instead of looping forever.

Tests and docs

  • New calc.test (324 tests: 322 pass, 2 skipped, 0 fail); colon_test.tcl extended. 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