From b807e3c1640870464ced1859c29d200188df12ab Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 3 Dec 2014 13:50:38 +1000 Subject: [PATCH] add support for [info source ?filename line?] Allows a script to be created with explicit source info Signed-off-by: Steve Bennett --- Tcl_shipped.html | 27 +++++++++++++++++---------- jim.c | 41 +++++++++++++++++++++++++---------------- jim_tcl.txt | 9 ++++++--- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/Tcl_shipped.html b/Tcl_shipped.html index 1bcf6ff..d1b5829 100644 --- a/Tcl_shipped.html +++ b/Tcl_shipped.html @@ -888,10 +888,10 @@ Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
  • file copy -force handles source and target as the same file -

    -
  • -
  • -

    +

    +
  • +
  • +

    format now supports %b for binary conversion

  • @@ -928,16 +928,21 @@ Add --random-hash to randomise hash tables for greater security
  • Add support for file link +

    +
  • +
  • +

    +glob now supports the --tails option

  • -glob now supports the --tails option +Add support for string cat

  • -Add support for string cat +Allow info source to add source info

  • @@ -4696,13 +4701,15 @@ The legal option's (which may be abbreviated) are:

    -info source script +info source script ?filename line?

    - Returns the original source location of the given script as a list of + With a single argument, returns the original source location of the given script as a list of {filename linenumber}. If the source location can’t be determined, the - list {{} 0} is returned. + list {{} 0} is returned. If filename and line are given, returns a copy + of script with the associate source information. This can be useful to produce + useful messages from eval, etc. if the original source information may be lost.

    @@ -8206,7 +8213,7 @@ official policies, either expressed or implied, of the Jim Tcl Project.
    diff --git a/jim.c b/jim.c index 7db453a..be5406a 100644 --- a/jim.c +++ b/jim.c @@ -14495,30 +14495,39 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg break; case INFO_SOURCE:{ - int line; + jim_wide line; Jim_Obj *resObjPtr; Jim_Obj *fileNameObj; - if (argc != 3) { - Jim_WrongNumArgs(interp, 2, argv, "source"); + if (argc != 3 && argc != 5) { + Jim_WrongNumArgs(interp, 2, argv, "source ?filename line?"); return JIM_ERR; } - if (argv[2]->typePtr == &sourceObjType) { - fileNameObj = argv[2]->internalRep.sourceValue.fileNameObj; - line = argv[2]->internalRep.sourceValue.lineNumber; - } - else if (argv[2]->typePtr == &scriptObjType) { - ScriptObj *script = Jim_GetScript(interp, argv[2]); - fileNameObj = script->fileNameObj; - line = script->firstline; + if (argc == 5) { + if (Jim_GetWide(interp, argv[4], &line) != JIM_OK) { + return JIM_ERR; + } + resObjPtr = Jim_NewStringObj(interp, Jim_String(argv[2]), Jim_Length(argv[2])); + JimSetSourceInfo(interp, resObjPtr, argv[3], line); } else { - fileNameObj = interp->emptyObj; - line = 1; + if (argv[2]->typePtr == &sourceObjType) { + fileNameObj = argv[2]->internalRep.sourceValue.fileNameObj; + line = argv[2]->internalRep.sourceValue.lineNumber; + } + else if (argv[2]->typePtr == &scriptObjType) { + ScriptObj *script = Jim_GetScript(interp, argv[2]); + fileNameObj = script->fileNameObj; + line = script->firstline; + } + else { + fileNameObj = interp->emptyObj; + line = 1; + } + resObjPtr = Jim_NewListObj(interp, NULL, 0); + Jim_ListAppendElement(interp, resObjPtr, fileNameObj); + Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line)); } - resObjPtr = Jim_NewListObj(interp, NULL, 0); - Jim_ListAppendElement(interp, resObjPtr, fileNameObj); - Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line)); Jim_SetResult(interp, resObjPtr); break; } diff --git a/jim_tcl.txt b/jim_tcl.txt index 36c4e70..959aff2 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -65,6 +65,7 @@ Changes between 0.74 and 0.75 10. Add support for `file link` 11. `glob` now supports the '--tails' option 12. Add support for `string cat` +13. Allow `info source` to add source info Changes between 0.73 and 0.74 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2735,10 +2736,12 @@ The legal +'option'+'s (which may be abbreviated) are: of the innermost file being processed. Otherwise the command returns an empty string. -+*info source* 'script'+:: - Returns the original source location of the given script as a list of ++*info source* 'script ?filename line?'+:: + With a single argument, returns the original source location of the given script as a list of +{filename linenumber}+. If the source location can't be determined, the - list +{{} 0}+ is returned. + list +{{} 0}+ is returned. If +'filename'+ and +'line'+ are given, returns a copy + of +'script'+ with the associate source information. This can be useful to produce + useful messages from `eval`, etc. if the original source information may be lost. +*info stacktrace*+:: After an error is caught with `catch`, returns the stack trace as a list -- 2.11.4.GIT