public BigInteger Encode(UrmMachine machine)
        {
            IList<BigInteger> commandEncodings = machine.Commands.Select(EncodeCommand).ToList();

            BigInteger result = this.scheme.EncodeTuple(commandEncodings);
            return result;
        }
Exemplo n.º 2
0
        public BigInteger Encode(UrmMachine machine)
        {
            IList <BigInteger> commandEncodings = machine.Commands.Select(EncodeCommand).ToList();

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

            return(result);
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 6
0
 internal UrmMachine(UrmMachine machine)
 {
     this.commands = machine.commands;
     this.Registers = new int[machine.Memory + 1];
 }
Exemplo n.º 7
0
 internal UrmMachine(UrmMachine machine)
 {
     this.commands  = machine.commands;
     this.Registers = new int[machine.Memory + 1];
 }