aboutsummaryrefslogtreecommitdiff
path: root/jim.c
AgeCommit message (Collapse)AuthorFilesLines
2023-11-23expr: better error message on nested $()expr-sugarSteve Bennett1-0/+8
And explain in the manual that it isn't allowed. Fixes: #285 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-31core: fix error level in try/catchSteve Bennett1-4/+4
When the multi-level break/continue support was added in 1b151f816f14b11f1c1ef10b171411e21b9a504e it reused returnLevel, but this interferred with the return level returned by try/catch. Use a separate variable for the break/continue level. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-13core: Fix 'for' with JIM_OPTIMIZATION disabledSteve Bennett1-7/+12
And allow -DJIM_TINY to disable optimisation, and use that with bootstrap jimsh. Fixes #273 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-10info script: return real current source fileSteve Bennett1-3/+36
And allow current source file to be set Fixes: #268 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04core: add support for proc statics by referenceSteve Bennett1-87/+150
set a 5 proc b {} {&a} { incr a } b Now a is 6 because b captured a by reference instead of by value Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04debug: convert to use subcmdSteve Bennett1-140/+124
This means we get -commands and usage via -help Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04info: convert to use subcmdSteve Bennett1-97/+92
This means we get -commands and usage via -help Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04dict: convert to use subcmdSteve Bennett1-75/+66
This means we get -commands and usage via -help And update dict2.test for minor difference in usage Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04string: convert to subcmdSteve Bennett1-100/+89
This means we get -commands and usage via -help Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-07-04aio: change to use unix io, not stdioSteve Bennett1-26/+36
This changes especially makes buffered I/O work with non-blocking channels. - separate read and write buffering - support for timeout on blocking read - read/write on same channel in event loop with buffering - read buffer is the same across read, gets, copyto - autoflush non-blocking writes via event loop - copyto can now copy to any filehandle-like command - add some copyto tests Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-06-21core: Display errors in a more "pythonesque" waySteve Bennett1-167/+116
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-108/+59
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-25core: support multi-level while, break from loopsSteve Bennett1-16/+61
loop i 5 { loop j 6 { # This breaks out of both loops break 2 } } Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-05-09core: avoid rare crash on shutdownSteve Bennett1-14/+11
If deferred commands run on shutdown as stack frames are unwound, it is possible that a command is deleted but a later command still has a reference to it. So instead of trying to optimise this case by freeing immediately, cache deleted commands and let the be freed once all stack frames are destroyed. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-05-06jim: info frame improvementsSteve Bennett1-10/+31
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-03-20Add support for ./configure --disable-introspectionSteve Bennett1-12/+33
Sometimes it can be useful to provide an embedded interpreter where introspection is not permitted. This includes: - info commands, procs, channels: only allow exact match, not glob pattern - info frame: don't include cmd and proc in the returned dict - info level: only return the command name, not the command arguments - info body, args, statics: do not allow these to be called Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-03-20build: define _GNU_SOURCE only on the command lineSteve Bennett1-3/+0
Not in source files See https://ariadne.space/2021/12/21/stop-defining-feature-test-macros-in-your-code/ Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-25jim: fix crash on infinite eval recursion0.82Steve Bennett1-2/+2
When this condition was caught, eval frame was incorrectly popped even though it was never pushed. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-24dict with: return script resultSteve Bennett1-5/+13
Previously dict with returned the new dict value. Also fix an issue in the case where a dict element mirrors the name of the dictionary. Fixes: #241 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-13clock millis, time: now use monotonic raw time if possibleSteve Bennett1-13/+33
Instead of using all time, these commands now use a monotonically increasing system timer so that they are not affected by time (e.g. ntp) adjustments. (But not on Windows since it doesn't work reliably) Fixes #240 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-13core: New timerate commandSteve Bennett1-0/+66
Based on TIP 527, but not 100% compatible Needs documentation Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-13Tcl-compatible 'info frame'Steve Bennett1-39/+174
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>
2023-02-13jim: make the Jim memory allocator replaceableSteve Bennett1-12/+13
Allows for a specialised allocator or debugging allocator. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-13Jim_StrDupLen: minor optimisationSteve Bennett1-2/+2
No need to copy a char that will be overwritten in the next line. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-10Optimisation for Jim_GetWideExpr()Steve Bennett1-0/+4
If the expression is a simple integer, use it as-is rather than converting to an expression and evaluating. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-09build: fix check for isinf/isnanSteve Bennett1-2/+2
Needs to be #if not #ifdef for 'decl' checks. Otherwise build fails on systems without these. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-03Convert some errant malloc/free to Jim_Alloc()/Jim_Free()Steve Bennett1-1/+1
Go through the Jim versions where it makes sense so we can add debugging or other features as required. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2023-02-01Silence compiler warningprpr19xx1-1/+1
The Appveyor build generates this otherwise: In function 'Jim_WhileCoreCommand', inlined from 'Jim_WhileCoreCommand' at jim.c:12096:12: jim.c:12109:12: warning: 'boolean' may be used uninitialized [-Wmaybe-uninitialized] 12109 | if (!boolean) | ^ jim.c: In function 'Jim_WhileCoreCommand': jim.c:12105:13: note: 'boolean' was declared here 12105 | int boolean, retval; | ^~~~~~~
2022-12-26jim: garbage collection fixSteve Bennett1-26/+38
Improve the check for an object that exists only in the command table with reference count of one. The object being checked needs to be the same object as the one in the command table. And also objects of type reference can be in the command table so check those too. Fixes #245 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-09-18build: isinf and isnan are macros in CSteve Bennett1-2/+2
So don't try to find them as functions Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-07-31jim: fix sometimes overly zealous garbage collectionSteve Bennett1-3/+6
When checking for "weak" references where the only reference is in the command hash table, need to check the reference count of the key in the hash table (this is the command name), not the reference count of the object we are using to look up the command. Without this it is possible that a reference (typically a lambda) will be collected even though there is still a reference to it. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-07-25unset: don't return a result with -nocomplainSteve Bennett1-0/+2
unset -nocomplain abc(missing) was still returning an error message, but as a normal return. It should return an empty result. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-07-25jim.c: minor comment fixupsSteve Bennett1-8/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-04-14try: add support for trapSteve Bennett1-34/+64
In addition to "on codes ..." it is now possible to trap on errorcode with "trap sublist ..." e.g. try { ... } trap CHILDSTATUS {msg opts} { ... } Fixes #204 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-04-12getref, setref: No need to allow for leading, trailing spaceSteve Bennett1-15/+6
There is no reason to allow a reference to contain leading and/or trailing white space, so remove this check and simply treat it as an invalid reference. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2022-04-11getref, setref: reference may be qualifiedSteve Bennett1-0/+4
oo.tcl returns globally qualified names like ::<reference.<tree___>.00000000000000000000> So allow getref and setref to handle these qualified references Fixes #218 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-12-16dict: consider dummy entries when determining when to expand hash tableSteve Bennett1-1/+7
This issue was caused by the fix in 24b234543c7322d2dd20339b45367fa3f4c53495 Because we used closed hashing for the dict hash table, it is important that the table doesn't get too full, as it gets very inefficient due to hash collisions. When allowing for space, also consider dummy entries that consume slots. If there are too many dummy slots, the hash table is expanded, clearing out the dummy slots. Without this fix it is possible to get unlucky when filling a dictionary and emptying it again (twice) will result all slots become dummy slots and thus no more entries can be added. See REGTEST 54 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-12-13dict: Fix possible duplicate entries when settingSteve Bennett1-5/+10
Due to the way hash collisions are managed it is possible to have a sequence where an entry is removed and then another entry is replaced, however the replacement adds an additional entry instead of updating the existing entry. Can be reproduced like this as there is a hash collision between these two keys: dict set d 0,13 X dict set d 8,4 Y dict unset d 0,13 dict set d 8,4 Z Should result in one entry in the dictionary, but instead ends with two. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-11-08core: avoid some gcc 11 warningsSteve Bennett1-0/+2
Fixes: #210 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-07-08collect: correctly handle references as globally scoped namesSteve Bennett1-3/+11
When a reference is used as a command name (e.g. in oo.tcl) it is created in the global namespace as ::<reference... The current check for references that are commands with a reference count of 1 doesn't take this into account so these references were not being garbage collected. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-04-03expr: allow existing multiple argument support with --compatSteve Bennett1-3/+23
Some users may not be ready to immediately move to the single-argument expr, so provide a --compat option to configure to support the previous behaviour as a transition strategy. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-03-19core: Fix memory leak replacing existing commandsSteve Bennett1-3/+11
Fixes #198 Reported-by: Antonio Borneo <borneo.antonio@gmail.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-03-09expr: TIP 526, only support a single argSteve Bennett1-18/+3
Avoid unexpected issues by concatenating multiple arguments. This does create an incompatibility with early versions, but it is generally trivial to convert existing code to one of two forms: 1. expr {$a + $b} -- usually correct 2. expr "$a + $b" -- usually incorrect Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-02-20jim.c: Fix compiler warningSteve Bennett1-0/+2
When namespace is disabled, Jim_memrchr is not needed Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-02-05build: quieten compiler warningsSteve Bennett1-0/+2
Irrelevant warnings from some compilers Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-30lsearch, lsort: support for -stride and -indexSteve Bennett1-62/+223
Add -stride support to both lsearch and lsort Add -index support to lsearch Improve -index for lsort to support multiple indices Also harmonise some error messages with Tcl 8.7 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-10package: add ABI version checkingSteve Bennett1-0/+13
jim.h now includes JIM_ABI_VERSION that should be incremented whenever the ABI changes. Then all loadable modules should call Jim_CheckAbiVersion() to make sure they are loaded against the correct version. Add Jim_PackageProvideCheck() that does both Jim_CheckAbiVersion() and Jim_PackageProvide() to simplify the implementation of loadable extensions. Also rename the "big" sqlite3 extension to just sqlite to avoid a naming conflict with the smaller jim-sqlite3 extension. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-09Add the [xtrace] commandSteve Bennett1-10/+80
Allows a debugger or tracing facility to be implemented Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-03bootstrap jimsh: pass all testsSteve Bennett1-0/+1
In order to test bootstrap jimsh, it is very helpful if it can pass all the unit tests. - Set tcl_platform(bootstrap) to 1 for bootstrap jimsh or 0 otherwise - Use getref to determine in we have references, not ref since we implement a poor-man's ref for bootstrap jimsh - bootstrap jimsh package doesn't return a "Can't load package" message if loading the package fails - exec tests using [open |command] need pipe - bootstrap jimsh can't set file times with [file mtime] Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-03core: fix parsing of booleansSteve Bennett1-35/+23
When boolean parsing was combined in commit 982ec4f524bc81a240cb729cf09bd3c677aea485 it broken parsing of boolean values in expressions that weren't standalone. e.g. expr {true} was fine, but expr {true ? 4 : 5} was not. Signed-off-by: Steve Bennett <steveb@workware.net.au>