aboutsummaryrefslogtreecommitdiff
path: root/stdlib.tcl
AgeCommit message (Collapse)AuthorFilesLines
2023-06-21stackdump: truncate command at first newlineSteve Bennett1-0/+4
Often the command in a stack trace will be a long script. This makes it hard to read the stacktrace, so in this case truncate at the first newline and add ... Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-06-21core: Display errors in a more "pythonesque" waySteve Bennett1-26/+13
A typical error message now looks like this: t4.tcl:2: Error: syntax error in expression: "blah" Traceback (most recent call last): File "t4.tcl", line 14 c 1 2 3 File "t4.tcl", line 10, in c b a c File "t4.tcl", line 6, in b a A14 File "t4.tcl", line 2, in a expr blah This is produced by stackdump (that can be replaced), called by errorInfo. Note that now stacktraces (stacktrace, info stacktrace, $opts(-errorinfo)) include the running command at each level in addition to proc, file, line. In order for scripts to detect this new format, a new entry tcl_platform entry has been added: tcl_platform(stackFormat) = 4 (to signify 4 elements per frame) In addition, instead of building the error stack frame as the stack is unwound in response to an error, instead the entire current stack trace is captured by stacktrace. This means that the trace extends beyond the try/catch right back to the initial interpreter command. The 'stacktrace' command is now implemented in C based on the same code that generates the error stacktrace. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-06-21core: improve eval frame handlingSteve Bennett1-2/+2
Now callers to JimInvokeCommand() are expected to push and eval frame. Then we no longer need to carry currentScriptObj, argc, argv in the interp since these are in the current eval frame. Note that this change simply renames some unused fields in Jim_Interp for ABI compatibility, but these will be removed in due course. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-05-06jim: info frame improvementsSteve Bennett1-23/+5
always include 'proc' even if introspection disabled correctly set 'proc' at the eval frame level that is currently running in the given proc. This makes it easier to produce an accurate level stacktrace even across uplevel, etc. Update stacktrace to use the new info frame. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-04-13stacktrace: handle missing cmd in [info frame]Steve Bennett1-1/+1
Some stack frames may have no cmd (e.g. with eval). Ensure that [stacktrace] still handles such frames by setting an empty proc name in that case. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-13Tcl-compatible 'info frame'Steve Bennett1-3/+23
Returns a dictionary with file, line, cmd, (possibly) proc and level. And support 'info frame 0' for the current command. Note that now all evaluation frames are captured, not just call frames. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-09-15Implement defer, $jim::deferSteve Bennett1-0/+7
Allows commands to run when a proc or interpreter exits. If the $jim::defer variables exists at proc or interp exit, it is treated as a list of scripts to evaluate (in reverse order). The [defer] command is a helper to add scripts to $jim::defer See tests/defer.test Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-09-01Support lambda even if references are disabledSteve Bennett1-0/+7
It's convenient to support a non-gc lambda, even if references are disabled. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-11-14dict: Fix [dict values] with duplicate valuesSteve Bennett1-5/+0
The script implementation of dict values was not correctly handling the case where a dictionary had duplicate values. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-09-28jim.c: Replace 'dict with' with a C versionSteve Bennett1-21/+0
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-09-28jim.c: replace 'dict merge' with a C versionSteve Bennett1-13/+0
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-12-09jim: change the output of errorInfoSteve Bennett1-1/+1
Rather than "Runtime Error: <file>:<line>: ...", use use "<file>:<line>: Error: ..." This latter format is both shorter and more consistent with other tools (e.g. gcc). This also allows errors to be reported with the default errorfmt of vim's quickfix feature. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-10-28Fix [info nameofexecutable] after [cd]Steve Bennett1-13/+4
If argv0 is a relative path, [info nameofexecutable] returned the wrong result after changing directory. So calculate and stash the result during init. Also move internal $jim_argv0 into namespace jim as $jim::argv0 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-21many comment changes, some small code changesSteve Bennett1-0/+2
Sweep through and clean up all (most) of the comments in the code. While there, adjust some variable and function names to be more consistent, and make a few small code changes - again, mostly for consistency. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2014-01-15stdlib: errorInfo includes the live stacktraceSteve Bennett1-15/+17
Rather than just the error backtrace ([info stacktrace]), include the live stacktrace. This means it is possible to do: if {[catch $script msg]} puts [errorInfo $msg] } to output the stack trace from the top level, not just from the point of capture. It is still possible to pass a stacktrace to errorInfo to override this behaviour. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2013-12-21Implement more dict sub commandsSteve Bennett1-6/+86
dict for, values, incr, append, lappend, update, replace and info Also implement array stat (the same as dict info) Note that [dict info] and [array stat] are for useful for checking the behaviour of the hash randomiser Add Jim_EvalEnsemble() Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-12-12Implement curry with aliasSteve Bennett1-6/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-12-02Implement the lassign command in CSteve Bennett1-8/+0
For efficiency since it can be heavily used Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-12-02Correct the documentation for 'local'Steve Bennett1-1/+1
Also some general documentation cleanups and trailing white space removal. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-11-28Implement [alias] in CSteve Bennett1-10/+0
And allow commands to set a temporary name for the purpose of generating error messages Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-11-07Allow building with MSVC on windowsSteve Bennett1-1/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2011-07-12Return an absolute path for [info nameofexec]Steve Bennett1-4/+4
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-11-24Add support for [dict] size, merge, withSteve Bennett1-0/+35
Implement 'dict with' and 'dict merge' as scripts since this is simpler. Use 'dict size' to implement 'array size' Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-11-08Don't hardcode /lib/jimSteve Bennett1-0/+17
Instead, set TCL_LIBRARY based on where jim is installed. This defaults to /usr/local (thus /usr/local/lib/jim), or can be modified with either configure or make. e.g. ./configure --prefix=/usr or make prefix=/usr install Now auto_path is initialised only to TCL_LIBRARY, and doesn't include "." which could be undesirable. At the same time, simplify jimsh initialisation using a script instead of C code. Add the path to the executable to auto_path. Also, no longer use JIM_TCL_COMPAT. Always use the tcl-compatible names, $auto_path and $tcl_interactive. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Only indicate 'Runtime Error' from a scriptSteve Bennett1-2/+2
This makes for cleaner output from a console session and is compatible with earlier versions of Jim. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Remove dependence of jim core on stderrSteve Bennett1-0/+25
Remove Jim_PrintErrorMessage() and create Jim_MakeErrorMessage() instead. Move errorInfo to stdlib since it is now required. Also move lassign from tclcompat to stdlib as a core command. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Implement 'info frame' and some related procsSteve Bennett1-4/+37
info frame allows access to source file/line for earler call frames Implement 'stacktrace' to give a live stacktrace And 'stackdump' to convert a stack trace to readable form Update 'errorInfo' to use 'stackdump' Also fix tailcall to retain source info And implement alias, lambda and curry with tailcall Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Move some core procs into the (Tcl) stdlib extensionSteve Bennett1-0/+40
Also implement 'local' to declare/delete local procs * Add tests/alias.test for testing alias, current, local * proc now returns the name of the proc created * Add helper 'function' to stdlib Reimplement glob and case to use local procs * This keeps these internal procs out of the global namespace Signed-off-by: Steve Bennett <steveb@workware.net.au>