public BigInteger Encode(UrmMachine machine) { IList<BigInteger> commandEncodings = machine.Commands.Select(EncodeCommand).ToList(); BigInteger result = this.scheme.EncodeTuple(commandEncodings); return result; }
public BigInteger Encode(UrmMachine machine) { IList <BigInteger> commandEncodings = machine.Commands.Select(EncodeCommand).ToList(); BigInteger result = this.scheme.EncodeTuple(commandEncodings); return(result); }
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(); } }
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); }
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)); }
internal UrmMachine(UrmMachine machine) { this.commands = machine.commands; this.Registers = new int[machine.Memory + 1]; }