Tcl Validation
Weld provides validation of Tcl by checking call and variable usage in user code.
Validation in Tcl can be more challenging than in other languages because
of how highly dynamic the language is. For example, in Tcl a proc does not
get compiled
(nor consequently checked) until it's first invocation.
Even then, sub-eval blocks such as while, if and switch
are not compiled until they are actually executed into.
This lazy evaluation makes it difficult to detect even
basic syntax errors.
Weld overcomes this by forcing all Tcl code to compile, when it first tets sourced.
Then, during the compilation phase
extensive checks can be applied to identify common programming errors.
Essentially, lazy evaluation is short-circuited during the development cycle
in order to provide a greater level of
validation and assurance than would normally be possible.
When errors or warnings are output from the
validation phase, they appear in the same form as gcc warning messages.
A side benefit of this is that Weld can share a common debugger front-end with gdb,
allowing simultaneous debugging of both script and C code.
Checks
The following checks are performed when running under Weld:
- All code in proc bodies gets compiled, including nested switch/if/while blocks.
- Syntax error detection such as unbalanced braces or quotes.
- Check for commands calls before define or extern.
- Parameters to all static calls are checked for count (and possibly types).
- Virtually all calls to builtin commands are validated
- Detection of missing upvar, variable or global statements.
- Data access to all static elements in _ array are checked for pre-initialization.
- A declare statement to allow defining other pre-initialized Array elements.
Tk Validation
Validation of Tk code presents a special challenge. This is because Tk widgets
are normally
created as object-commands, and subcommands later accessed via the dot-widget path (or a variable).
Unfortunately, this use of object-cmds provides a compiler with no effective way to check or validate calls. Similarly within an editor, command completion of Tk calls after creation isn't really feasible.
To address this Tk widgets are re-factored. That is
for each widget, a Module command is defined using the class name within the
::Tk namespace. Each sub-command therein is passed the Tk window-path as an argument. This provides Weld with a way to
check Tk call arguments at compile time and Ted to provide argument completion.
Tk code can use either method.
See TkMod and Extern Docs for more details.
Ted is written in Validated Tk.
Tod Validation
Tod is also validatable by Weld. Dispatch calls are validated by looking
up the command from the first argument of the call. This validates
local as well as imported call and Uses calls. Data elements are also validated by verifying
that accesses to $() are initialized in the namespace variable "_".
© 2008 Peter MacDonald