コード例 #1
0
ファイル: BgErrorMgr.cs プロジェクト: BclEx/GpuStructs
        private ArrayList Errors = new ArrayList(10); // A list of the pending background error handlers.

        internal BgErrorMgr(Interp i)
        {
            Interp = i;
            BgerrorCmdObj = TclString.NewInstance("bgerror");
            BgerrorCmdObj.Preserve();
            Errors = new ArrayList(10);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: BclEx/GpuStructs
    public static void Main(string[] args)
    {
        // Array of command-line argument strings.
        {
            string fileName = null;

            // Create the interpreter. This will also create the built-in
            // Tcl commands.

            Interp interp = new Interp();

            // Make command-line arguments available in the Tcl variables "argc"
            // and "argv".  If the first argument doesn't start with a "-" then
            // strip it off and use it as the name of a script file to process.
            // We also set the argv0 and TCL.Tcl_interactive vars here.

            if ((args.Length > 0) && !(args[0].StartsWith("-")))
            {
                fileName = args[0];
            }

            TclObject argv = TclList.NewInstance();
            argv.Preserve();
            try
            {
                int i    = 0;
                int argc = args.Length;
                if ((System.Object)fileName == null)
                {
                    interp.SetVar("argv0", "tcl.lang.Shell", TCL.VarFlag.GLOBAL_ONLY);
                    interp.SetVar("tcl_interactive", "1", TCL.VarFlag.GLOBAL_ONLY);
                }
                else
                {
                    interp.SetVar("argv0", fileName, TCL.VarFlag.GLOBAL_ONLY);
                    interp.SetVar("tcl_interactive", "0", TCL.VarFlag.GLOBAL_ONLY);
                    i++;
                    argc--;
                }
                for (; i < args.Length; i++)
                {
                    TclList.Append(interp, argv, TclString.NewInstance(args[i]));
                }
                interp.SetVar("argv", argv, TCL.VarFlag.GLOBAL_ONLY);
                interp.SetVar("argc", System.Convert.ToString(argc), TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
                throw new TclRuntimeError("unexpected TclException: " + e.Message);
            }
            finally
            {
                argv.Release();
            }

            // Normally we would do application specific initialization here.
            // However, that feature is not currently supported.
            // If a script file was specified then just source that file
            // and quit.

            Console.WriteLine("C#-TCL version " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
            Console.WriteLine("==============================================================");
            Console.WriteLine("");

            if ((System.Object)fileName != null)
            {
                try
                {
                    interp.evalFile(fileName);
                }
                catch (TclException e)
                {
                    TCL.CompletionCode code = e.GetCompletionCode();
                    if (code == TCL.CompletionCode.RETURN)
                    {
                        code = interp.updateReturnInfo();
                        if (code != TCL.CompletionCode.OK)
                        {
                            System.Console.Error.WriteLine("command returned bad code: " + code);
                            if (Tcl.Lang.ConsoleThread.debug)
                            {
                                System.Diagnostics.Debug.WriteLine("command returned bad code: " + code);
                            }
                        }
                    }
                    else if (code == TCL.CompletionCode.ERROR)
                    {
                        System.Console.Error.WriteLine(interp.GetResult().ToString());
                        if (Tcl.Lang.ConsoleThread.debug)
                        {
                            System.Diagnostics.Debug.WriteLine(interp.GetResult().ToString());
                        }
                        System.Diagnostics.Debug.Assert(false, interp.GetResult().ToString());
                    }
                    else
                    {
                        System.Console.Error.WriteLine("command returned bad code: " + code);
                        if (Tcl.Lang.ConsoleThread.debug)
                        {
                            System.Diagnostics.Debug.WriteLine("command returned bad code: " + code);
                        }
                    }
                }

                // Note that if the above interp.evalFile() returns the main
                // thread will exit.  This may bring down the VM and stop
                // the execution of Tcl.
                //
                // If the script needs to handle events, it must call
                // vwait or do something similar.
                //
                // Note that the script can create AWT widgets. This will
                // start an AWT event handling thread and keep the VM up. However,
                // the interpreter thread (the same as the main thread) would
                // have exited and no Tcl scripts can be executed.

                interp.Dispose();

                System.Environment.Exit(0);
            }

            if ((System.Object)fileName == null)
            {
                // We are running in interactive mode. Start the ConsoleThread
                // that loops, grabbing stdin and passing it to the interp.

                ConsoleThread consoleThread = new ConsoleThread(interp);
                consoleThread.IsBackground = true;
                consoleThread.Start();

                // Loop forever to handle user input events in the command line.

                Notifier notifier = interp.GetNotifier();
                while (true)
                {
                    // process events until "exit" is called.

                    notifier.doOneEvent(TCL.ALL_EVENTS);
                }
            }
        }
    }
コード例 #3
0
ファイル: Interp.cs プロジェクト: BclEx/GpuStructs
        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 == _result)
            {
                // Setting to current value (including m_nullResult) is a no-op.
                return;
            }

            if (_result != _nullResult)
            {
                _result.Release();
            }

            _result = r;

            if (_result != _nullResult)
            {
                _result.Preserve();
            }
        }
コード例 #4
0
ファイル: Interp.cs プロジェクト: BclEx/GpuStructs
        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.
            _nullResult = TclString.NewInstance(string.Empty);
            _nullResult.Preserve(); // Increment refCount to 1
            _nullResult.Preserve(); // Increment refCount to 2 (shared)
            _result = TclString.NewInstance(string.Empty); // _nullResult; // correcponds to iPtr->objResultPtr
            _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 = 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)
            {
                Debug.WriteLine(GetResult().ToString());
                SupportClass.WriteStackTrace(e, Console.Error);
                throw new TclRuntimeError("unexpected TclException: " + e.Message, e);
            }
        }
コード例 #5
0
ファイル: Interp.cs プロジェクト: BclEx/GpuStructs
 public void ResetResult()
 {
     if (_result != _nullResult)
     {
         _result.Release();
         _result = TclString.NewInstance(""); //m_nullResult;
         _result.Preserve();
         if (!_nullResult.Shared)
         {
             throw new TclRuntimeError("m_nullResult is not shared");
         }
     }
     _errAlreadyLogged = false;
     _errInProgress = false;
     _errCodeSet = false;
     _returnCode = TCL.CompletionCode.OK;
 }