Exemplo n.º 1
0
        public static unsafe int CsList(IntPtr clientData, IntPtr interp, int objc, IntPtr *argv)
        {
            if (objc < 2)
            {
                return(1);
            }

            object targetObj = null;

            // If only converting an object
            if (objc == 2)
            {
                targetObj = TclAPI.FindCsObject(argv[1]);
            }
            // If invoking cs first
            else
            {
                int r = Cs(clientData, interp, objc, argv);
                if (r != 0)
                {
                    return(r);
                }

                targetObj = TclAPI.FindCsObject(TclDLL.Tcl_GetObjResult(interp));
            }

            if (targetObj == null)
            {
                return(0);
            }

            IEnumerable <object> e = null;

            try
            {
                e = ((IEnumerable)targetObj).Cast <object>();
            }
            catch (Exception)
            {
                e = null;
            }
            if (e == null)
            {
                return(1);
            }

            IntPtr list = TclAPI.GetTclList(e);

            TclDLL.Tcl_SetObjResult(interp, list);

            return(0);
        }
Exemplo n.º 2
0
        //source
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.InitialDirectory = "C:\\";
            fileDialog.Title            = "Select path";
            fileDialog.CheckFileExists  = false;
            fileDialog.CheckPathExists  = true;
            fileDialog.DefaultExt       = "txt";
            fileDialog.Filter           = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            fileDialog.FilterIndex      = 2;
            fileDialog.RestoreDirectory = true;
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string script = File.ReadAllText(fileDialog.FileName);

                /*for(int i=0; i<lines.Length; i++)
                 * {
                 *  int r = Program.mainInterpreter.EvalScript(lines[i]);
                 *  string result = Program.mainInterpreter.Result;
                 *  m_txtTCLInput.AppendText(result + (result == "" ? "" : Environment.NewLine));
                 * }*/
                int r = Program.mainInterpreter.EvalScript(script);
                if (r != 0)
                {
                    TclDLL.Tcl_SetObjResult(Program.mainInterpreter.ptr, TclAPI.Cs2Tcl("ERROR"));
                }
                // TODO: 'Switch (r)' or something of the sort

                string result = Program.mainInterpreter.Result;
                TCL_input.AppendText(result + (result == "" ? "" : Environment.NewLine));
                TCL_input.SelectAll();
                TCL_input.SelectionProtected = true;
                TCL_input.SelectionStart     = TCL_input.Text.Length;
                TCL_input.SelectionLength    = 0;
                TCL_input.ScrollToCaret();
            }
        }
        protected override void DoCommandAction()
        {
            List <Tile> startTiles  = FPGA.FPGA.Instance.GetAllTiles().Where(t => Regex.IsMatch(t.Location, StartLocation)).OrderBy(t => t.Location).ToList();
            List <Tile> targetTiles = FPGA.FPGA.Instance.GetAllTiles().Where(t => Regex.IsMatch(t.Location, TargetLocation)).OrderBy(t => t.Location).ToList();

            // All matched regex start tiles
            for (int i = 0; i < startTiles.Count; i++)
            {
                List <Port> startPorts = startTiles[i].SwitchMatrix.Ports.Where(p => Regex.IsMatch(p.Name, StartPort)).OrderBy(p => p.Name).ToList();

                // All matched regex target tiles
                for (int j = 0; j < targetTiles.Count; j++)
                {
                    List <Port> targetPorts = targetTiles[j].SwitchMatrix.Ports.Where(p => Regex.IsMatch(p.Name, TargetPort)).OrderBy(p => p.Name).ToList();

                    // All matched regex start ports
                    for (int k = 0; k < startPorts.Count; k++)
                    {
                        Location startLocation = new Location(startTiles[i], startPorts[k]);

                        // All matched regex target ports
                        for (int l = 0; l < targetPorts.Count; l++)
                        {
                            Location targetLocation = new Location(targetTiles[j], targetPorts[l]);

                            ExecutePathSearch(startLocation, targetLocation);
                        }
                    }
                }
            }

            if (OutputMode.ToUpper().Equals("TCL"))
            {
                TclDLL.Tcl_SetObjResult(Program.mainInterpreter.ptr, TclAPI.Cs2Tcl(TCL_output));
            }
        }
Exemplo n.º 4
0
        public static unsafe int Cs(IntPtr clientData, IntPtr interp, int objc, IntPtr *argv)
        {
            Program.mainInterpreter.ErrorMessage = "";

            if (objc < 3)
            {
                Program.mainInterpreter.ErrorMessage =
                    "Not enough parameters provided for the command." + NL +
                    "Correct command format: 'cs $object $member $parameters'." + NL +
                    "For more info type 'cshelp'.";
                return(TclInterpreter.TCL_ERROR);
            }

            Type   objType = null;
            object obj     = TclAPI.FindCsObject(argv[1]);

            if (obj == null)
            {
                string str = TclAPI.GetCsString(argv[1]);

                objType = TclAPI.GetCsTypeFromName(str);

                if (objType == null)
                {
                    Program.mainInterpreter.ErrorMessage =
                        "The parameter '" + str + "' could not be linked to any C# object or type.";
                    return(TclInterpreter.TCL_ERROR);
                }
            }
            else
            {
                objType = obj.GetType();
            }

            object result = null;

            // Required data - can be Method or Property
            string requiredMember = TclAPI.GetCsString(argv[2]);
            IEnumerable <MemberInfo> candidates =
                objType.GetMembers().Where(m => m.Name == requiredMember && TclAPI.IsAPICompatibleMember(m));

            // Method
            if (candidates.FirstOrDefault() is MethodInfo)
            {
                int totalParams = objc - 3;

                IEnumerable <MethodInfo> matchedMethods = candidates.Where(m => m.MemberType == MemberTypes.Method)
                                                          .Cast <MethodInfo>().Where(m => m.GetParameters().Count() == totalParams);

                // Convert the tcl parameters to cs objects
                object[] parameters = new object[totalParams];
                for (int i = 0; i < totalParams; i++)
                {
                    object csObj = TclAPI.Tcl2Cs(argv[3 + i]);
                    if (csObj == null)
                    {
                        string args = "Parameters:" + Environment.NewLine;
                        for (int j = 0; j < objc; j++)
                        {
                            args += j + ": " + TclAPI.GetCsString(argv[j]) + Environment.NewLine;
                        }
                        throw new ArgumentException("Invalid parameter provided at index: " + (3 + i).ToString() + Environment.NewLine + args);
                    }
                    parameters[i] = csObj;
                }

                // Try the candidate methods until one works
                bool success = false;
                foreach (MethodInfo method in matchedMethods)
                {
                    try
                    {
                        result = method.Invoke(obj, parameters);

                        /*if(result != null && !result.GetType().Equals(method.ReturnType))
                         *  Console.WriteLine("Type Difference");*/
                        success = true;
                        break;
                    }
                    catch (Exception) { }
                }

                // If invoked method was void
                if (success)
                {
                    if (result == null)
                    {
                        TclDLL.Tcl_ResetResult(interp);
                        return(0);
                    }
                }
                else
                {
                    Program.mainInterpreter.ErrorMessage +=
                        "No method overload could be executed for the method " + requiredMember + NL;
                }
            }
            // Property
            else if (candidates.Count() == 1 && candidates.FirstOrDefault() is PropertyInfo p)
            {
                result = p.GetValue(obj, null);
            }

            TclDLL.Tcl_SetObjResult(interp, TclAPI.Cs2Tcl(result));

            if (result == null)
            {
                Program.mainInterpreter.ErrorMessage +=
                    "'" + requiredMember + "' returned null.";
                return(TclInterpreter.TCL_WARNING);
            }

            return(0);
        }
Exemplo n.º 5
0
        private void TCL_input_KeyPress(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)Keys.Return)
            {
                e.SuppressKeyPress = true;
                TCL_input.Text     = TCL_input.Text.Trim();
                TCLTerminal_MaintainMemory(TCL_input.Text);

                // TODO: handle r better
                int    r      = Program.mainInterpreter.EvalScript(TCL_input.Text);
                string result = Program.mainInterpreter.Result;

                // Echo the input unless it's 'clear'
                if (TCL_input.Text != "clear" && TCL_input.Text != "clearcontext")
                {
                    // Try to recognize the first word as a TCL command
                    bool   appended = false;
                    string firstWord = TCL_input.Text, restOfStr = "";
                    int    firstSpace = TCL_input.Text.IndexOf(' ');
                    if (firstSpace > 0)
                    {
                        firstWord = TCL_input.Text.Substring(0, firstSpace);
                        restOfStr = TCL_input.Text.Substring(firstSpace);
                    }
                    if (CommandsList.Commands.Contains(firstWord))
                    {
                        TCL_output.AppendText(firstWord, TCL.Procs.cshelp.CsHelp_GUI.color_standardTcl);
                        TCL_output.AppendText(restOfStr);
                        appended = true;
                    }
                    else if (CommandsList.ExtraCommands.Contains(firstWord))
                    {
                        TCL_output.AppendText(firstWord, TCL.Procs.cshelp.CsHelp_GUI.color_extraTcl);
                        TCL_output.AppendText(restOfStr);
                        appended = true;
                    }
                    if (!appended)
                    {
                        TCL_output.AppendText(TCL_input.Text);
                    }
                    TCL_output.AppendText(Environment.NewLine);
                }

                // Input's success
                if (r != 0)
                {
                    string errormsg = "ERROR" + Environment.NewLine;
                    string msg      = Program.mainInterpreter.ErrorMessage;
                    if (msg != "")
                    {
                        errormsg += msg + Environment.NewLine;
                    }
                    if (result != "")
                    {
                        errormsg += result + Environment.NewLine;
                    }

                    TCL_output.AppendText(errormsg, Color.Red);
                    TclDLL.Tcl_ResetResult(Program.mainInterpreter.ptr);
                }
                else if (result.Length > 0)
                {
                    if (result.Length > 2000)
                    {
                        TCL_output.AppendText(result.Substring(0, 2000) + "...", Color.Blue);
                    }
                    else
                    {
                        TCL_output.AppendText(result, Color.Blue);
                    }

                    TCL_output.AppendText(Environment.NewLine);
                }

                // Clear input
                TCL_input.Text             = "";
                TCL_output.SelectionStart  = TCL_output.Text.Length;
                TCL_output.SelectionLength = 0;
                TCL_output.ScrollToCaret();

                //TCL_input.Focus();
            }
            else if (e.KeyValue == (char)Keys.Down)
            {
                e.SuppressKeyPress = true;
                if (TCL_input_memory_navigator <= -1)
                {
                    return;
                }

                if (TCL_input_memory_navigator > 0)
                {
                    TCL_input_memory_navigator--;
                }
                TCL_input.Text            = TCL_input_memory[TCL_input_memory_navigator];
                TCL_input.SelectionStart  = TCL_input.Text.Length;
                TCL_input.SelectionLength = 0;
            }
            else if (e.KeyValue == (char)Keys.Up)
            {
                e.SuppressKeyPress = true;
                if (TCL_input_memory_navigator <= -1 || TCL_input_memory_navigator == TCL_input_memory.Count)
                {
                    return;
                }

                if (TCL_input_memory_navigator < TCL_input_memory.Count - 1)
                {
                    TCL_input_memory_navigator++;
                }
                TCL_input.Text            = TCL_input_memory[TCL_input_memory_navigator];
                TCL_input.SelectionStart  = TCL_input.Text.Length;
                TCL_input.SelectionLength = 0;
            }

            /*else if (e.KeyValue == (char)Keys.Space)
             * {
             *  string text = TCL_input.Text;
             *  if (!text.Contains(' '))
             *  {
             *      if (CommandsList.Commands.Contains(text))
             *      {
             *          TCL_input.Text = "";
             *          TCL_input.AppendText(text, Color.Red);
             *      }
             *  }
             * }*/
        }