Exemple #1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (this.soureCodeTb.IsReadOnly)
     {
         this.cplBtn.Content = International.GetString("LIC");
     }
     else
     {
         this.cplBtn.Content = International.GetString("UIC");
     }
     this.soureCodeTb.IsReadOnly = !this.soureCodeTb.IsReadOnly;
 }
Exemple #2
0
        private async void SoureCodeTb_TextChangedAsync(object sender, TextChangedEventArgs e)
        {
            if (this.resultTb != null && this.soureCodeTb != null)
            {
                this.cplBtn.IsEnabled      = false;
                this.soureCodeTb.IsEnabled = false;
                this.resultTb.Text         = International.GetString("Compiling") + " ...";
                this.resultTb.IsEnabled    = false;

                this.resultTb.Text = await cpl.WorkAsync(soureCodeTb.Text);

                this.rowBox.Text = cpl.RowString.ToString();

                this.cplBtn.IsEnabled      = true;
                this.soureCodeTb.IsEnabled = true;
                this.resultTb.IsEnabled    = true;
            }
            e.Handled = true;
        }
Exemple #3
0
        virtual public string Work(string soureCode)
        {
            result.Clear();
            rowString.Clear();
            int           counter = -1, offset = 0;
            int           rdi = 0, rsi = 0;
            StringBuilder op = new StringBuilder(10);

            if (string.IsNullOrWhiteSpace(soureCode))
            {
                return(result.Append(International.GetString("WFYC")).ToString());
            }
            string soure = string.Copy(soureCode).ToUpper();
            int    index = 0, len = soure.Length;

            while (index < len)
            {
                if (IsAlpha(soure[index]))
                {
                    counter++;
                    op.Clear();
                    while (index < len && IsAlpha(soure[index]))
                    {
                        op.Append(soure[index]);
                        index++;
                    }
                    string opStr = Table.ContainsKey(op.ToString())?Table[op.ToString()]:null;
                    if (opStr != null)
                    {
                        result.Append(opStr);
                    }
                    else
                    {
                        return(result.Append(International.GetString("CFTOP")).Append('"').Append(op).Append("\" !!!").ToString());
                    }
                    int opCount = GetOperandsCount(op.ToString());
                    if (opCount == 0)
                    {
                        result.Append("XXXX");
                        continue;
                    }

                    while (index < len && (soure[index] == ' ' || soure[index] == '\r' || soure[index] == ';' || soure[index] == '\n'))
                    {
                        if (soure[index] == ';')
                        {
                            while (index < len && soure[index] != '\n')
                            {
                                result.Append(soureCode[index]);
                                index++;
                            }
                        }
                        else
                        {
                            result.Append(soureCode[index]);
                            index++;
                        }
                    }

                    if (opCount == 2)
                    {
                        string rd = GetRegr(soure, ref index);
                        if (rd == null)
                        {
                            return(result.Append(International.GetString("CFTFO")).Append('"').Append(op).Append("\" !!!").ToString());
                        }
                        string orStr = Table.ContainsKey(rd) ? Table[rd] : null;
                        if (orStr != null)
                        {
                            result.Append(orStr);
                        }
                        else
                        {
                            return(result.Append(International.GetString("CFTFO")).Append('"').Append(op).Append("\" !!!").ToString());
                        }

                        rdi = result.Length - 2;

                        while (index < len && (soure[index] == ' ' || soure[index] == '\r' || soure[index] == ';' || soure[index] == '\n'))
                        {
                            if (soure[index] == ';')
                            {
                                while (index < len && soure[index] != '\n')
                                {
                                    result.Append(soureCode[index]);
                                    index++;
                                }
                            }
                            else
                            {
                                result.Append(soureCode[index]);
                                index++;
                            }
                        }
                        if (index >= len || soure[index++] != ',')
                        {
                            return(result.Append(International.GetString("CFTDO")).Append(" !!!").ToString());
                        }
                        if ((string.Equals(op.ToString(), "LD") || string.Equals(op.ToString(), "ST")) && (index >= len || soure[index++] != '['))
                        {
                            return(result.Append(International.GetString("CFTLO")).Append(" !!!").ToString());
                        }
                        string rs = GetRegr(soure, ref index);
                        if (rs == null)
                        {
                            return(result.Append(International.GetString("CFTSO")).Append('"').Append(op).Append("\" !!!").ToString());
                        }
                        orStr = Table.ContainsKey(rs) ? Table[rs] : null;
                        if (orStr != null)
                        {
                            result.Append(orStr);
                        }
                        else
                        {
                            return(result.Append(International.GetString("CFTSO")).Append('"').Append(op).Append("\" !!!").ToString());
                        }

                        rsi = result.Length - 2;

                        if ((string.Equals(op.ToString(), "LD") || string.Equals(op.ToString(), "ST")) && (index >= len || soure[index++] != ']'))
                        {
                            return(result.Append(International.GetString("CFTRO")).Append(" !!!").ToString());
                        }
                        if (string.Equals(op.ToString(), "ST"))
                        {
                            char ch0 = result[rdi];
                            char ch1 = result[rdi + 1];
                            result[rdi]     = result[rsi];
                            result[rdi + 1] = result[rsi + 1];
                            result[rsi]     = ch0;
                            result[rsi + 1] = ch1;
                            //char[] tmpResult = result.ToCharArray();
                            //tmp = result[rdi];
                            //tmpResult[rdi] = tmpResult[rsi];
                            //tmpResult[rsi] = tmp;
                            //tmp = result[rdi + 1];
                            //tmpResult[rdi + 1] = tmpResult[rsi + 1];
                            //tmpResult[rsi + 1] = tmp;
                            //result = new string(tmpResult);
                        }
                    }
                    else
                    if (opCount == 1)
                    {
                        if (string.Equals(op.ToString(), "JC") || string.Equals(op.ToString(), "JZ"))
                        {
                            string num = GetOffset(soure, ref index);
                            if (num == null)
                            {
                                return(result.Append(International.GetString("TOOP")).Append('"').Append(op).Append('"').Append(International.GetString("MBAHN")).Append(" !!!").ToString());
                            }

                            if (Int32.TryParse(num, System.Globalization.NumberStyles.HexNumber, null, out offset))
                            {
                                offset = offset - counter - 1;
                                if (offset < 0)
                                {
                                    if (offset < -8)
                                    {
                                        return(result.Append(International.GetString("TVLIUR")).Append(" .").ToString());
                                    }
                                    offset += 16;
                                }
                                else
                                {
                                    if (offset > 7)
                                    {
                                        return(result.Append(International.GetString("TVLIUR")).Append(" .").ToString());
                                    }
                                }
                            }
                            else
                            {
                                return(result.Append(International.GetString("TOOP")).Append('"').Append(op).Append('"').Append(International.GetString("MBAHN")).Append(" !!!").ToString());
                            }
                            result.Append(hexcode[offset]);
                            continue;
                        }
                        else
                        if (string.Equals(op.ToString(), "OUT"))
                        {
                            result.Append("XX");
                        }
                        if (string.Equals(op.ToString(), "JMP") && (index >= len || soure[index++] != '['))
                        {
                            return(result.Append(International.GetString("CFTLO")).Append(" !!!").ToString());
                        }
                        string rd = GetRegr(soure, ref index);
                        if (rd == null)
                        {
                            return(result.Append(International.GetString("CFTFO")).Append('"').Append(op).Append("\" !!!").ToString());
                        }
                        string orStr = Table.ContainsKey(rd) ? Table[rd] : null;
                        if (Table != null)
                        {
                            result.Append(orStr);
                        }
                        else
                        {
                            return(result.Append(International.GetString("CFTFO")).Append('"').Append(op).Append("\" !!!").ToString());
                        }
                        if (string.Equals(op.ToString(), "INC") || string.Equals(op.ToString(), "JMP"))
                        {
                            result.Append("XX");
                        }
                        if (string.Equals(op.ToString(), "JMP") && (index >= len || soure[index++] != ']'))
                        {
                            return(result.Append(International.GetString("CFTRO")).Append(" !!!").ToString());
                        }
                    }
                }
                if (index < len && (soure[index] == ' ' || soure[index] == '\r' || soure[index] == '\t' || soure[index] == ';' || soure[index] == '\n'))
                {
                    while (index < len && (soure[index] == ' ' || soure[index] == '\r' || soure[index] == '\t' || soure[index] == ';' || soure[index] == '\n'))
                    {
                        if (soure[index] == '\r')
                        {
                            rowString.AppendFormat("{0:X2}H\r\n", counter == -1 ? 0 : counter);
                        }
                        if (soure[index] == ';')
                        {
                            while (index < len && soure[index] != '\n')
                            {
                                if (soure[index] == '\r')
                                {
                                    rowString.AppendFormat("{0:X2}H\r\n", counter == -1 ? 0 : counter);
                                }
                                result.Append(soureCode[index]);
                                index++;
                            }
                        }
                        else
                        {
                            result.Append(soureCode[index]);
                            index++;
                        }
                    }
                }
                else
                if (index == len)
                {
                    break;
                }
                else
                if (index < len)
                {
                    return(result.Append(International.GetString("BI")).Append(" !!!").ToString());
                }
            }
            return(result.ToString());
        }