/// <summary> Chain this frame into the call frame stack and binds the parameters /// values to the formal parameters of the procedure. /// /// </summary> /// <param name="proc">the procedure. /// </param> /// <param name="proc">argv the parameter values. /// </param> /// <exception cref=""> TclException if wrong number of arguments. /// </exception> internal void chain( Procedure proc, TclObject[] objv ) { // FIXME: double check this ns thing in case where proc is renamed to different ns. this.ns = proc.ns; this.objv = objv; // FIXME : quick level hack : fix later level = ( interp.varFrame == null ) ? 1 : ( interp.varFrame.level + 1 ); caller = interp.frame; callerVar = interp.varFrame; interp.frame = this; interp.varFrame = this; // parameter bindings int numArgs = proc.argList.Length; if ( ( !proc.isVarArgs ) && ( objv.Length - 1 > numArgs ) ) { wrongNumProcArgs( objv[0], proc ); } int i, j; for ( i = 0, j = 1; i < numArgs; i++, j++ ) { // Handle the special case of the last formal being // "args". When it occurs, assign it a list consisting of // all the remaining actual arguments. TclObject varName = proc.argList[i][0]; TclObject value = null; if ( ( i == ( numArgs - 1 ) ) && proc.isVarArgs ) { value = TclList.newInstance(); value.preserve(); for ( int k = j; k < objv.Length; k++ ) { TclList.append( interp, value, objv[k] ); } interp.setVar( varName, value, 0 ); value.release(); } else { if ( j < objv.Length ) { value = objv[j]; } else if ( proc.argList[i][1] != null ) { value = proc.argList[i][1]; } else { wrongNumProcArgs( objv[0], proc ); } interp.setVar( varName, value, 0 ); } } }
internal static void eval(Interp interp, Interp slaveInterp, int objIx, TclObject[] objv) { TCL.CompletionCode result; slaveInterp.preserve(); slaveInterp.allowExceptions(); try { if (objIx + 1 == objv.Length) { slaveInterp.eval(objv[objIx], 0); } else { TclObject obj = TclList.newInstance(); for (int ix = objIx; ix < objv.Length; ix++) { TclList.append(interp, obj, objv[ix]); } obj.preserve(); slaveInterp.eval(obj, 0); obj.release(); } result = slaveInterp.returnCode; } catch (TclException e) { result = e.getCompletionCode(); } slaveInterp.release(); interp.transferResult(slaveInterp, result); }
internal static void create(Interp interp, Interp slaveInterp, Interp masterInterp, TclObject name, TclObject targetName, int objIx, TclObject[] objv) { string inString = name.ToString(); InterpAliasCmd alias = new InterpAliasCmd(); alias.name = name; name.preserve(); alias.slaveInterp = slaveInterp; alias.targetInterp = masterInterp; alias.prefix = TclList.newInstance(); alias.prefix.preserve(); TclList.append(interp, alias.prefix, targetName); TclList.insert(interp, alias.prefix, 1, objv, objIx, objv.Length - 1); slaveInterp.createCommand(inString, alias); alias.slaveCmd = NamespaceCmd.findCommand(slaveInterp, inString, null, 0); try { interp.preventAliasLoop(slaveInterp, alias.slaveCmd); } catch (TclException e) { // Found an alias loop! The last call to Tcl_CreateObjCommand made // the alias point to itself. Delete the command and its alias // record. Be careful to wipe out its client data first, so the // command doesn't try to delete itself. slaveInterp.deleteCommandFromToken(alias.slaveCmd); throw; } // Make an entry in the alias table. If it already exists delete // the alias command. Then retry. if (slaveInterp.aliasTable.ContainsKey(inString)) { InterpAliasCmd oldAlias = (InterpAliasCmd)slaveInterp.aliasTable[inString]; slaveInterp.deleteCommandFromToken(oldAlias.slaveCmd); } alias.aliasEntry = inString; SupportClass.PutElement(slaveInterp.aliasTable, inString, alias); // Create the new command. We must do it after deleting any old command, // because the alias may be pointing at a renamed alias, as in: // // interp alias {} foo {} bar # Create an alias "foo" // rename foo zop # Now rename the alias // interp alias {} foo {} zop # Now recreate "foo"... SupportClass.PutElement(masterInterp.targetTable, alias.slaveCmd, slaveInterp); interp.setResult(name); }
public static void Tcl_SetLongObj(TclObject to, long result) { while (to.Shared) { to.release(); } TclLong.set(to, result); to.preserve(); }
internal BgErrorMgr( Interp i ) { InitBlock(); interp = i; bgerrorCmdObj = TclString.newInstance( "bgerror" ); bgerrorCmdObj.preserve(); errors = new ArrayList( 10 ); }
internal BgErrorMgr(Interp i) { InitBlock(); interp = i; bgerrorCmdObj = TclString.newInstance("bgerror"); bgerrorCmdObj.preserve(); errors = new ArrayList(10); }
public static void Tcl_SetIntObj(TclObject to, int result ) { while (to.Shared) { to.release(); } TclInteger.set(to, result); to.preserve(); }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { targetInterp.preserve(); targetInterp.nestLevel++; targetInterp.resetResult(); targetInterp.allowExceptions(); // Append the arguments to the command prefix and invoke the command // in the target interp's global namespace. TclObject[] prefv = TclList.getElements(interp, prefix); TclObject cmd = TclList.newInstance(); cmd.preserve(); TclList.replace(interp, cmd, 0, 0, prefv, 0, prefv.Length - 1); TclList.replace(interp, cmd, prefv.Length, 0, argv, 1, argv.Length - 1); TclObject[] cmdv = TclList.getElements(interp, cmd); TCL.CompletionCode result = targetInterp.invoke(cmdv, Interp.INVOKE_NO_TRACEBACK); cmd.release(); targetInterp.nestLevel--; // Check if we are at the bottom of the stack for the target interpreter. // If so, check for special return codes. if (targetInterp.nestLevel == 0) { if (result == TCL.CompletionCode.RETURN) { result = targetInterp.updateReturnInfo(); } if (result != TCL.CompletionCode.OK && result != TCL.CompletionCode.ERROR) { try { targetInterp.processUnexpectedResult(result); } catch (TclException e) { result = e.getCompletionCode(); } } } targetInterp.release(); interp.transferResult(targetInterp, result); return(TCL.CompletionCode.RETURN); }
/// <summary> DupListInternalRep -> duplicate /// /// Returns a dupilcate of the current object. /// /// </summary> /// <param name="obj">the TclObject that contains this internalRep. /// </param> public InternalRep duplicate() { int size = vector.Count; TclList newList = new TclList(size); for (int i = 0; i < size; i++) { TclObject tobj = (TclObject)vector[i]; tobj.preserve(); newList.vector.Add(tobj); } return(newList); }
/// <summary> Tcl_ListObjAppendElement -> TclList.append() /// /// Appends a TclObject element to a list object. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="tobj">the TclObject to append an element to. /// </param> /// <param name="elemObj">the element to append to the object. /// </param> /// <exception cref=""> TclException if tobj cannot be converted into a list. /// </exception> public static void append(Interp interp, TclObject tobj, TclObject elemObj) { if (tobj.Shared) { throw new TclRuntimeError("TclList.append() called with shared object"); } setListFromAny(interp, tobj); tobj.invalidateStringRep(); TclList tlist = (TclList)tobj.InternalRep; elemObj.preserve(); tlist.vector.Add(elemObj); }
/// <summary> Tcl_ListObjAppendElement -> TclList.append() /// /// Appends a TclObject element to a list object. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="tobj">the TclObject to append an element to. /// </param> /// <param name="elemObj">the element to append to the object. /// </param> /// <exception cref=""> TclException if tobj cannot be converted into a list. /// </exception> public static void append(Interp interp, TclObject tobj, TclObject elemObj) { if (tobj.Shared) { throw new TclRuntimeError("TclList.append() called with shared object"); } setListFromAny(interp, tobj); tobj.invalidateStringRep(); TclList tlist = (TclList)tobj.InternalRep; if (!String.IsNullOrEmpty(elemObj.stringRep) && elemObj.stringRep[0] == '{') { elemObj = TclString.newInstance(elemObj.stringRep.Substring(1, elemObj.stringRep.Length - 2)); } elemObj.preserve(); tlist.vector.Add(elemObj); }
/// <summary> See Tcl user documentation for details.</summary> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { TclObject list = TclList.newInstance(); list.preserve(); try { for (int i = 1; i < argv.Length; i++) { TclList.append(interp, list, argv[i]); } interp.setResult(list); } finally { list.release(); } return(TCL.CompletionCode.RETURN); }
/// <summary> Splits a list (in string rep) up into its constituent fields. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="v">store the list elements in this vector. /// </param> /// <param name="s">the string to convert into a list. /// </param> /// <exception cref=""> TclException if the object doesn't contain a valid list. /// </exception> private static void splitList(Interp interp, ArrayList v, string s) { int len = s.Length; int i = 0; while (i < len) { FindElemResult res = Util.findElement(interp, s, i, len); if (res == null) { break; } else { TclObject tobj = TclString.newInstance(res.elem); tobj.preserve(); v.Add(tobj); } i = res.elemEnd; } }
public static void Tcl_DStringInit(ref TclObject str) { str = TclString.newInstance(""); str.preserve(); }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { int i; Notifier notifier = (Notifier)interp.getNotifier(); Object info; if (assocData == null) { /* * Create the "after" information associated for this * interpreter, if it doesn't already exist. */ assocData = (AfterAssocData)interp.getAssocData("tclAfter"); if (assocData == null) { assocData = new AfterAssocData(this); interp.setAssocData("tclAfter", assocData); } } if (argv.Length < 2) { throw new TclNumArgsException(interp, 1, argv, "option ?arg arg ...?"); } /* * First lets see if the command was passed a number as the first argument. */ bool isNumber = false; int ms = 0; if (argv[1].InternalRep is TclInteger) { ms = TclInteger.get(interp, argv[1]); isNumber = true; } else { string s = argv[1].ToString(); if ((s.Length > 0) && (System.Char.IsDigit(s[0]))) { ms = TclInteger.get(interp, argv[1]); isNumber = true; } } if (isNumber) { if (ms < 0) { ms = 0; } if (argv.Length == 2) { /* * Sleep for at least the given milliseconds and return. */ long endTime = System.DateTime.Now.Ticks / 10000 + ms; while (true) { try { System.Threading.Thread.Sleep(ms); return(TCL.CompletionCode.RETURN); } catch (System.Threading.ThreadInterruptedException e) { /* * We got interrupted. Sleep again if we havn't slept * long enough yet. */ long sysTime = System.DateTime.Now.Ticks / 10000; if (sysTime >= endTime) { return(TCL.CompletionCode.RETURN); } ms = (int)(endTime - sysTime); continue; } } } TclObject cmd = getCmdObject(argv); cmd.preserve(); assocData.lastAfterId++; TimerInfo timerInfo = new TimerInfo(this, notifier, ms); timerInfo.interp = interp; timerInfo.command = cmd; timerInfo.id = assocData.lastAfterId; assocData.handlers.Add(timerInfo); interp.setResult("after#" + timerInfo.id); return(TCL.CompletionCode.RETURN); } /* * If it's not a number it must be a subcommand. */ int index; try { index = TclIndex.get(interp, argv[1], validOpts, "option", 0); } catch (TclException e) { throw new TclException(interp, "bad argument \"" + argv[1] + "\": must be cancel, idle, info, or a number"); } switch (index) { case OPT_CANCEL: if (argv.Length < 3) { throw new TclNumArgsException(interp, 2, argv, "id|command"); } TclObject arg = getCmdObject(argv); arg.preserve(); /* * Search the timer/idle handler by id or by command. */ info = null; for (i = 0; i < assocData.handlers.Count; i++) { Object obj = assocData.handlers[i]; if (obj is TimerInfo) { TclObject cmd = ((TimerInfo)obj).command; if ((cmd == arg) || cmd.ToString().Equals(arg.ToString())) { info = obj; break; } } else { TclObject cmd = ((IdleInfo)obj).command; if ((cmd == arg) || cmd.ToString().Equals(arg.ToString())) { info = obj; break; } } } if (info == null) { info = getAfterEvent(arg.ToString()); } arg.release(); /* * Cancel the handler. */ if (info != null) { if (info is TimerInfo) { ((TimerInfo)info).cancel(); ((TimerInfo)info).command.release(); } else { ((IdleInfo)info).cancel(); ((IdleInfo)info).command.release(); } SupportClass.VectorRemoveElement(assocData.handlers, info); } break; case OPT_IDLE: if (argv.Length < 3) { throw new TclNumArgsException(interp, 2, argv, "script script ..."); } TclObject cmd2 = getCmdObject(argv); cmd2.preserve(); assocData.lastAfterId++; IdleInfo idleInfo = new IdleInfo(this, notifier); idleInfo.interp = interp; idleInfo.command = cmd2; idleInfo.id = assocData.lastAfterId; assocData.handlers.Add(idleInfo); interp.setResult("after#" + idleInfo.id); break; case OPT_INFO: if (argv.Length == 2) { /* * No id is given. Return a list of current after id's. */ TclObject list = TclList.newInstance(); for (i = 0; i < assocData.handlers.Count; i++) { int id; Object obj = assocData.handlers[i]; if (obj is TimerInfo) { id = ((TimerInfo)obj).id; } else { id = ((IdleInfo)obj).id; } TclList.append(interp, list, TclString.newInstance("after#" + id)); } interp.resetResult(); interp.setResult(list); return(TCL.CompletionCode.RETURN); } if (argv.Length != 3) { throw new TclNumArgsException(interp, 2, argv, "?id?"); } /* * Return command and type of the given after id. */ info = getAfterEvent(argv[2].ToString()); if (info == null) { throw new TclException(interp, "event \"" + argv[2] + "\" doesn't exist"); } TclObject list2 = TclList.newInstance(); TclList.append(interp, list2, ((info is TimerInfo)?((TimerInfo)info).command:((IdleInfo)info).command)); TclList.append(interp, list2, TclString.newInstance((info is TimerInfo)?"timer":"idle")); interp.resetResult(); interp.setResult(list2); break; } return(TCL.CompletionCode.RETURN); }
public TCL.CompletionCode cmdProc(Interp interp, TclObject[] objv) { int len; if (objv.Length < 2) { throw new TclNumArgsException(interp, 1, objv, "option [arg arg ...]"); } int opt = TclIndex.get(interp, objv[1], validCmds, "option", 0); switch (opt) { case OPT_VARIABLE: case OPT_VDELETE: if (objv.Length != 5) { if (opt == OPT_VARIABLE) { throw new TclNumArgsException(interp, 1, objv, "variable name ops command"); } else { throw new TclNumArgsException(interp, 1, objv, "vdelete name ops command"); } } TCL.VarFlag flags = 0; string ops = objv[3].ToString(); len = ops.Length; { for (int i = 0; i < len; i++) { switch (ops[i]) { case 'r': flags |= TCL.VarFlag.TRACE_READS; break; case 'w': flags |= TCL.VarFlag.TRACE_WRITES; break; case 'u': flags |= TCL.VarFlag.TRACE_UNSETS; break; default: flags = 0; goto check_ops_brk; } } } check_ops_brk: ; if (flags == 0) { throw new TclException(interp, "bad operations \"" + objv[3] + "\": should be one or more of rwu"); } if (opt == OPT_VARIABLE) { CmdTraceProc trace = new CmdTraceProc(objv[4].ToString(), flags); Var.traceVar(interp, objv[2], flags, trace); } else { // Search through all of our traces on this variable to // see if there's one with the given command. If so, then // delete the first one that matches. ArrayList traces = Var.getTraces(interp, objv[2].ToString(), 0); if (traces != null) { len = traces.Count; for (int i = 0; i < len; i++) { TraceRecord rec = (TraceRecord)traces[i]; if (rec.trace is CmdTraceProc) { CmdTraceProc proc = (CmdTraceProc)rec.trace; if (proc.flags == flags && proc.command.ToString().Equals(objv[4].ToString())) { Var.untraceVar(interp, objv[2], flags, proc); break; } } } } } break; case OPT_VINFO: if (objv.Length != 3) { throw new TclNumArgsException(interp, 2, objv, "name"); } ArrayList traces2 = Var.getTraces(interp, objv[2].ToString(), 0); if (traces2 != null) { len = traces2.Count; TclObject list = TclList.newInstance(); TclObject cmd = null; list.preserve(); try { for (int i = 0; i < len; i++) { TraceRecord rec = (TraceRecord)traces2[i]; if (rec.trace is CmdTraceProc) { CmdTraceProc proc = (CmdTraceProc)rec.trace; TCL.VarFlag mode = proc.flags; mode &= (TCL.VarFlag.TRACE_READS | TCL.VarFlag.TRACE_WRITES | TCL.VarFlag.TRACE_UNSETS); int modeInt = (int)mode; modeInt /= ((int)TCL.VarFlag.TRACE_READS); cmd = TclList.newInstance(); TclList.append(interp, cmd, opStr[modeInt]); TclList.append(interp, cmd, TclString.newInstance(proc.command)); TclList.append(interp, list, cmd); } } interp.setResult(list); } finally { list.release(); } } break; } return(TCL.CompletionCode.RETURN); }
/// <summary> This procedure is invoked to process the "split" Tcl /// command. See Tcl user documentation for details. /// /// </summary> /// <param name="interp">the current interpreter. /// </param> /// <param name="argv">command arguments. /// </param> /// <exception cref=""> TclException If incorrect number of arguments. /// </exception> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { char[] splitChars = null; string inString; if (argv.Length == 2) { splitChars = defSplitChars; } else if (argv.Length == 3) { splitChars = argv[2].ToString().ToCharArray(); } else { throw new TclNumArgsException(interp, 1, argv, "string ?splitChars?"); } inString = argv[1].ToString(); int len = inString.Length; int num = splitChars.Length; /* * Handle the special case of splitting on every character. */ if (num == 0) { TclObject list = TclList.newInstance(); list.preserve(); try { for (int i = 0; i < len; i++) { TclList.append(interp, list, TclString.newInstance(inString[i])); } interp.setResult(list); } finally { list.release(); } return(TCL.CompletionCode.RETURN); } /* * Normal case: split on any of a given set of characters. * Discard instances of the split characters. */ TclObject list2 = TclList.newInstance(); int elemStart = 0; list2.preserve(); try { int i, j; for (i = 0; i < len; i++) { char c = inString[i]; for (j = 0; j < num; j++) { if (c == splitChars[j]) { TclList.append(interp, list2, TclString.newInstance(inString.Substring(elemStart, (i) - (elemStart)))); elemStart = i + 1; break; } } } if (i != 0) { TclList.append(interp, list2, TclString.newInstance(inString.Substring(elemStart))); } interp.setResult(list2); } finally { list2.release(); } return(TCL.CompletionCode.RETURN); }
internal static void create( Interp interp, Interp slaveInterp, Interp masterInterp, TclObject name, TclObject targetName, int objIx, TclObject[] objv ) { string inString = name.ToString(); InterpAliasCmd alias = new InterpAliasCmd(); alias.name = name; name.preserve(); alias.slaveInterp = slaveInterp; alias.targetInterp = masterInterp; alias.prefix = TclList.newInstance(); alias.prefix.preserve(); TclList.append( interp, alias.prefix, targetName ); TclList.insert( interp, alias.prefix, 1, objv, objIx, objv.Length - 1 ); slaveInterp.createCommand( inString, alias ); alias.slaveCmd = NamespaceCmd.findCommand( slaveInterp, inString, null, 0 ); try { interp.preventAliasLoop( slaveInterp, alias.slaveCmd ); } catch ( TclException e ) { // Found an alias loop! The last call to Tcl_CreateObjCommand made // the alias point to itself. Delete the command and its alias // record. Be careful to wipe out its client data first, so the // command doesn't try to delete itself. slaveInterp.deleteCommandFromToken( alias.slaveCmd ); throw; } // Make an entry in the alias table. If it already exists delete // the alias command. Then retry. if ( slaveInterp.aliasTable.ContainsKey( inString ) ) { InterpAliasCmd oldAlias = (InterpAliasCmd)slaveInterp.aliasTable[inString]; slaveInterp.deleteCommandFromToken( oldAlias.slaveCmd ); } alias.aliasEntry = inString; SupportClass.PutElement( slaveInterp.aliasTable, inString, alias ); // Create the new command. We must do it after deleting any old command, // because the alias may be pointing at a renamed alias, as in: // // interp alias {} foo {} bar # Create an alias "foo" // rename foo zop # Now rename the alias // interp alias {} foo {} zop # Now recreate "foo"... SupportClass.PutElement( masterInterp.targetTable, alias.slaveCmd, slaveInterp ); interp.setResult( name ); }
/// <summary> This procedure is invoked to process the "subst" Tcl command. /// See the user documentation for details on what it does. /// /// </summary> /// <param name="interp">the current interpreter. /// </param> /// <param name="argv">command arguments. /// </param> /// <exception cref=""> TclException if wrong # of args or invalid argument(s). /// </exception> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { int currentObjIndex, len, i; int objc = argv.Length - 1; bool doBackslashes = true; bool doCmds = true; bool doVars = true; System.Text.StringBuilder result = new System.Text.StringBuilder(); string s; char c; for (currentObjIndex = 1; currentObjIndex < objc; currentObjIndex++) { if (!argv[currentObjIndex].ToString().StartsWith("-")) { break; } int opt = TclIndex.get(interp, argv[currentObjIndex], validCmds, "switch", 0); switch (opt) { case OPT_NOBACKSLASHES: doBackslashes = false; break; case OPT_NOCOMMANDS: doCmds = false; break; case OPT_NOVARS: doVars = false; break; default: throw new TclException(interp, "SubstCmd.cmdProc: bad option " + opt + " index to cmds"); } } if (currentObjIndex != objc) { throw new TclNumArgsException(interp, currentObjIndex, argv, "?-nobackslashes? ?-nocommands? ?-novariables? string"); } /* * Scan through the string one character at a time, performing * command, variable, and backslash substitutions. */ s = argv[currentObjIndex].ToString(); len = s.Length; i = 0; while (i < len) { c = s[i]; if ((c == '[') && doCmds) { ParseResult res; try { interp.evalFlags = Parser.TCL_BRACKET_TERM; interp.eval(s.Substring(i + 1, (len) - (i + 1))); TclObject interp_result = interp.getResult(); interp_result.preserve(); res = new ParseResult(interp_result, i + interp.termOffset); } catch (TclException e) { i = e.errIndex + 1; throw; } i = res.nextIndex + 2; result.Append(res.value.ToString()); res.release(); } else if (c == '\r') { /* * (ToDo) may not be portable on Mac */ i++; } else if ((c == '$') && doVars) { ParseResult vres = Parser.parseVar(interp, s.Substring(i, (len) - (i))); i += vres.nextIndex; result.Append(vres.value.ToString()); vres.release(); } else if ((c == '\\') && doBackslashes) { BackSlashResult bs = tcl.lang.Interp.backslash(s, i, len); i = bs.nextIndex; if (bs.isWordSep) { break; } else { result.Append(bs.c); } } else { result.Append(c); i++; } } interp.setResult(result.ToString()); return(TCL.CompletionCode.RETURN); }
internal ParseResult( string s, int ni ) { value = TclString.newInstance( s ); value.preserve(); nextIndex = ni; }
internal ParseResult(System.Text.StringBuilder sbuf, int ni) { value = TclString.newInstance(sbuf.ToString()); value.preserve(); nextIndex = ni; }
internal ParseResult(string s, int ni) { value = TclString.newInstance(s); value.preserve(); nextIndex = ni; }
/// <summary> Create an empty parsed word.</summary> internal ParseResult() { value = TclString.newInstance(""); value.preserve(); }
public static void Tcl_IncrRefCount(TclObject to) { to.preserve(); }
public static void Tcl_SetBooleanObj(TclObject to, int result) { to.stringRep = TclBoolean.newInstance(result != 0).ToString(); to.preserve(); }
/// <summary> Create an empty parsed word.</summary> internal ParseResult() { value = TclString.newInstance( "" ); value.preserve(); }
public void setResult( TclObject r ) // A Tcl Object to be set as the result. { if ( r == null ) { throw new System.NullReferenceException( "Interp.setResult() called with null TclObject argument." ); } if ( r == m_result ) { // Setting to current value (including m_nullResult) is a no-op. return; } if ( m_result != m_nullResult ) { m_result.release(); } m_result = r; if ( m_result != m_nullResult ) { m_result.preserve(); } }
public void resetResult() { if ( m_result != m_nullResult ) { m_result.release(); m_result = TclString.newInstance( "" ); //m_nullResult; m_result.preserve(); if ( !m_nullResult.Shared ) { throw new TclRuntimeError( "m_nullResult is not shared" ); } } errAlreadyLogged = false; errInProgress = false; errCodeSet = false; returnCode = TCL.CompletionCode.OK; }
/// <summary> Tcl_ListObjAppendElement -> TclList.append() /// /// Appends a TclObject element to a list object. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="tobj">the TclObject to append an element to. /// </param> /// <param name="elemObj">the element to append to the object. /// </param> /// <exception cref=""> TclException if tobj cannot be converted into a list. /// </exception> public static void append( Interp interp, TclObject tobj, TclObject elemObj ) { if ( tobj.Shared ) { throw new TclRuntimeError( "TclList.append() called with shared object" ); } setListFromAny( interp, tobj ); tobj.invalidateStringRep(); TclList tlist = (TclList)tobj.InternalRep; if ( !String.IsNullOrEmpty( elemObj.stringRep ) && elemObj.stringRep[0] == '{' ) elemObj = TclString.newInstance( elemObj.stringRep.Substring( 1, elemObj.stringRep.Length - 2 ) ); elemObj.preserve(); tlist.vector.Add( elemObj ); }
public Interp() { InitBlock(); //freeProc = null; errorLine = 0; // An empty result is used pretty often. We will use a shared // TclObject instance to represent the empty result so that we // don't need to create a new TclObject instance every time the // interpreter result is set to empty. m_nullResult = TclString.newInstance( "" ); m_nullResult.preserve(); // Increment refCount to 1 m_nullResult.preserve(); // Increment refCount to 2 (shared) m_result = TclString.newInstance( "" ); //m_nullResult; // correcponds to iPtr->objResultPtr m_result.preserve(); expr = new Expression(); nestLevel = 0; maxNestingDepth = 1000; frame = null; varFrame = null; returnCode = TCL.CompletionCode.OK; errorInfo = null; errorCode = null; packageTable = new Hashtable(); packageUnknown = null; cmdCount = 0; termOffset = 0; resolvers = null; evalFlags = 0; scriptFile = null; flags = 0; isSafe = false; assocData = null; globalNs = null; // force creation of global ns below globalNs = NamespaceCmd.createNamespace( this, null, null ); if ( globalNs == null ) { throw new TclRuntimeError( "Interp(): can't create global namespace" ); } // Init things that are specific to the Jacl implementation workingDir = new FileInfo( System.Environment.CurrentDirectory ); noEval = 0; notifier = Notifier.getNotifierForThread( System.Threading.Thread.CurrentThread ); notifier.preserve(); randSeedInit = false; deleted = false; errInProgress = false; errAlreadyLogged = false; errCodeSet = false; dbg = initDebugInfo(); slaveTable = new Hashtable(); targetTable = new Hashtable(); aliasTable = new Hashtable(); // init parser variables Parser.init( this ); TclParse.init( this ); // Initialize the Global (static) channel table and the local // interp channel table. interpChanTable = TclIO.getInterpChanTable( this ); // Sets up the variable trace for tcl_precision. Util.setupPrecisionTrace( this ); // Create the built-in commands. createCommands(); try { // Set up tcl_platform, tcl_version, tcl_library and other // global variables. setVar( "tcl_platform", "platform", "windows", TCL.VarFlag.GLOBAL_ONLY ); setVar( "tcl_platform", "byteOrder", "bigEndian", TCL.VarFlag.GLOBAL_ONLY ); setVar( "tcl_platform", "os", Environment.OSVersion.Platform.ToString(), TCL.VarFlag.GLOBAL_ONLY ); setVar( "tcl_platform", "osVersion", Environment.OSVersion.Version.ToString(), TCL.VarFlag.GLOBAL_ONLY ); setVar( "tcl_platform", "machine", Util.tryGetSystemProperty( "os.arch", "?" ), TCL.VarFlag.GLOBAL_ONLY ); setVar( "tcl_version", TCL_VERSION, TCL.VarFlag.GLOBAL_ONLY ); setVar( "tcl_patchLevel", TCL_PATCH_LEVEL, TCL.VarFlag.GLOBAL_ONLY ); setVar( "tcl_library", "resource:/tcl/lang/library", TCL.VarFlag.GLOBAL_ONLY ); if ( Util.Windows ) { setVar( "tcl_platform", "host_platform", "windows", TCL.VarFlag.GLOBAL_ONLY ); } else if ( Util.Mac ) { setVar( "tcl_platform", "host_platform", "macintosh", TCL.VarFlag.GLOBAL_ONLY ); } else { setVar( "tcl_platform", "host_platform", "unix", TCL.VarFlag.GLOBAL_ONLY ); } // Create the env array an populated it with proper // values. Env.initialize( this ); // Register Tcl's version number. Note: This MUST be // done before the call to evalResource, otherwise // calls to "package require tcl" will fail. pkgProvide( "Tcl", TCL_VERSION ); // Source the init.tcl script to initialize auto-loading. evalResource( "/tcl/lang/library/init.tcl" ); } catch ( TclException e ) { System.Diagnostics.Debug.WriteLine( getResult().ToString() ); SupportClass.WriteStackTrace( e, Console.Error ); throw new TclRuntimeError( "unexpected TclException: " + e.Message, e ); } }
/// <summary> See Tcl user documentation for details.</summary> /// <exception cref=""> TclException If incorrect number of arguments. /// </exception> public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv) { if (argv.Length != 4) { throw new TclNumArgsException(interp, 1, argv, "list first last"); } int size = TclList.getLength(interp, argv[1]); int first; int last; first = Util.getIntForIndex(interp, argv[2], size - 1); last = Util.getIntForIndex(interp, argv[3], size - 1); if (last < 0) { interp.resetResult(); return(TCL.CompletionCode.RETURN); } if (first >= size) { interp.resetResult(); return(TCL.CompletionCode.RETURN); } if (first <= 0 && last >= size) { interp.setResult(argv[1]); return(TCL.CompletionCode.RETURN); } if (first < 0) { first = 0; } if (first >= size) { first = size - 1; } if (last < 0) { last = 0; } if (last >= size) { last = size - 1; } if (first > last) { interp.resetResult(); return(TCL.CompletionCode.RETURN); } TclObject list = TclList.newInstance(); list.preserve(); try { for (int i = first; i <= last; i++) { TclList.append(interp, list, TclList.index(interp, argv[1], i)); } interp.setResult(list); } finally { list.release(); } return(TCL.CompletionCode.RETURN); }
internal ParseResult( StringBuilder sbuf, int ni ) { value = TclString.newInstance( sbuf.ToString() ); value.preserve(); nextIndex = ni; }
public override int processEvent(int flags) { // See if the command is a complete Tcl command if (Interp.commandComplete(command)) { if (tcl.lang.ConsoleThread.debug) { WriteLine("line was a complete command"); } bool eval_exception = true; TclObject commandObj = TclString.newInstance(command); try { commandObj.preserve(); Enclosing_Instance.interp.recordAndEval(commandObj, 0); eval_exception = false; } catch (TclException e) { if (tcl.lang.ConsoleThread.debug) { WriteLine("eval returned exceptional condition"); } TCL.CompletionCode code = e.getCompletionCode(); switch (code) { case TCL.CompletionCode.ERROR: Enclosing_Instance.putLine(Enclosing_Instance.err, Enclosing_Instance.interp.getResult().ToString()); break; case TCL.CompletionCode.BREAK: Enclosing_Instance.putLine(Enclosing_Instance.err, "invoked \"break\" outside of a loop"); break; case TCL.CompletionCode.CONTINUE: Enclosing_Instance.putLine(Enclosing_Instance.err, "invoked \"continue\" outside of a loop"); break; default: Enclosing_Instance.putLine(Enclosing_Instance.err, "command returned bad code: " + code); break; } } finally { commandObj.release(); } if (!eval_exception) { if (tcl.lang.ConsoleThread.debug) { WriteLine("eval returned normally"); } string evalResult = Enclosing_Instance.interp.getResult().ToString(); if (tcl.lang.ConsoleThread.debug) { WriteLine("eval result was \"" + evalResult + "\""); } if (evalResult.Length > 0) { Enclosing_Instance.putLine(Enclosing_Instance.out_Renamed, evalResult); } } // Empty out the incoming command buffer Enclosing_Instance.sbuf.Length = 0; // See if the user set a custom shell prompt for the next command TclObject prompt; try { prompt = Enclosing_Instance.interp.getVar("tcl_prompt1", TCL.VarFlag.GLOBAL_ONLY); } catch (TclException e) { prompt = null; } if (prompt != null) { try { Enclosing_Instance.interp.eval(prompt.ToString(), TCL.EVAL_GLOBAL); } catch (TclException e) { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, "% "); } } else { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, "% "); } return(1); } else { // Interp.commandComplete() returned false if (tcl.lang.ConsoleThread.debug) { WriteLine("line was not a complete command"); } // We don't have a complete command yet. Print out a level 2 // prompt message and wait for further inputs. TclObject prompt; try { prompt = Enclosing_Instance.interp.getVar("tcl_prompt2", TCL.VarFlag.GLOBAL_ONLY); } catch (TclException) { prompt = null; } if (prompt != null) { try { Enclosing_Instance.interp.eval(prompt.ToString(), TCL.EVAL_GLOBAL); } catch (TclException e) { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, ""); } } else { Enclosing_Instance.put(Enclosing_Instance.out_Renamed, ""); } return(1); } } // end processEvent method
/// <summary> Tcl_ListObjAppendElement -> TclList.append() /// /// Appends a TclObject element to a list object. /// /// </summary> /// <param name="interp">current interpreter. /// </param> /// <param name="tobj">the TclObject to append an element to. /// </param> /// <param name="elemObj">the element to append to the object. /// </param> /// <exception cref=""> TclException if tobj cannot be converted into a list. /// </exception> public static void append( Interp interp, TclObject tobj, TclObject elemObj ) { if ( tobj.Shared ) { throw new TclRuntimeError( "TclList.append() called with shared object" ); } setListFromAny( interp, tobj ); tobj.invalidateStringRep(); TclList tlist = (TclList)tobj.InternalRep; elemObj.preserve(); tlist.vector.Add( elemObj ); }