Exemple #1
0
        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);
            }
        }