コード例 #1
0
        public BigInteger Encode(UrmMachine machine)
        {
            IList<BigInteger> commandEncodings = machine.Commands.Select(EncodeCommand).ToList();

            BigInteger result = this.scheme.EncodeTuple(commandEncodings);
            return result;
        }
コード例 #2
0
        public BigInteger Encode(UrmMachine machine)
        {
            IList <BigInteger> commandEncodings = machine.Commands.Select(EncodeCommand).ToList();

            BigInteger result = this.scheme.EncodeTuple(commandEncodings);

            return(result);
        }
コード例 #3
0
        private void ExecuteMetaCommand(string normalized)
        {
            string includeCommand = "#INCLUDE";

            if (normalized.ToUpperInvariant().StartsWith(includeCommand))
            {
                UrmMachine machine     = ProgramLoader.Instance.LoadProgram(normalized.Remove(0, includeCommand.Length).Trim());
                int        memoryLimit = Math.Min(machine.Memory, this.Memory);
                for (int i = 0; i < memoryLimit; i++)
                {
                    machine.Registers[i] = this.Registers[i];
                }
                this.Registers[1] = machine.ExecuteProgram();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #4
0
        public UrmMachine LoadProgram(string fileName)
        {
            UrmMachine machine;
            if (!preloadedMachines.TryGetValue(fileName, out machine))
            {
                string programText = File.ReadAllText(Path.Combine(DefaultFolder, fileName) + UrmExtension);
                string[] commands = programText.Split(NewLineDelimiter, StringSplitOptions.RemoveEmptyEntries);
                commands =
                    (from command in commands
                    where !command.StartsWith(CommentSymbol)
                    let normalized = Regex.Replace(command, @"\(", " ")
                    let secondNormalization = Regex.Replace(normalized, @"\)|,", string.Empty)
                    select secondNormalization)
                    .ToArray();

                machine = new UrmMachine(commands, CalculateUsedMemory(programText));
                preloadedMachines.TryAdd(fileName, machine);
            }
            return new UrmMachine(machine);
        }
コード例 #5
0
        public UrmMachine LoadProgram(string fileName)
        {
            UrmMachine machine;

            if (!preloadedMachines.TryGetValue(fileName, out machine))
            {
                string   programText = File.ReadAllText(Path.Combine(DefaultFolder, fileName) + UrmExtension);
                string[] commands    = programText.Split(NewLineDelimiter, StringSplitOptions.RemoveEmptyEntries);
                commands =
                    (from command in commands
                     where !command.StartsWith(CommentSymbol)
                     let normalized = Regex.Replace(command, @"\(", " ")
                                      let secondNormalization = Regex.Replace(normalized, @"\)|,", string.Empty)
                                                                select secondNormalization)
                    .ToArray();

                machine = new UrmMachine(commands, CalculateUsedMemory(programText));
                preloadedMachines.TryAdd(fileName, machine);
            }
            return(new UrmMachine(machine));
        }
コード例 #6
0
 internal UrmMachine(UrmMachine machine)
 {
     this.commands = machine.commands;
     this.Registers = new int[machine.Memory + 1];
 }
コード例 #7
0
 internal UrmMachine(UrmMachine machine)
 {
     this.commands  = machine.commands;
     this.Registers = new int[machine.Memory + 1];
 }