Beispiel #1
0
        public void Compile()
        {
            var cpu = new Cpu(2048, 256);
            cpu.IdleProcess.Code.Append(cpu.Ram.Allocate(cpu.IdleProcess));

            var ms = cpu.GetMemoryStream(cpu.IdleProcess.Code);
            var writer = new CodeWriter(ms);
            Array.ForEach(IdleProcess.TerminatingIdle, writer.Write);
            writer.Close();

            var codeReader = new CodeReader(cpu.GetMemoryStream(cpu.IdleProcess.Code));

            var actual = codeReader.GetEnumerator();
            var expected = IdleProcess.TerminatingIdle.Cast<Instruction>().GetEnumerator();

            while ( actual.MoveNext() )
            {
                if ( expected.MoveNext() )
                {
                    Assert.That(actual.Current.OpCode, Is.EqualTo(expected.Current.OpCode));
                    Assert.That(actual.Current.Parameters, Is.EqualTo(expected.Current.Parameters));
                    Assert.That(actual.Current.Comment, Is.EqualTo(expected.Current.Comment));
                    continue;
                }

                Assert.That(actual.Current.OpCode, Is.EqualTo(OpCode.Noop));
            }
        }
Beispiel #2
0
        public static void Initialise(Cpu cpu, Instruction[] code = null)
        {
            var ms = new MemoryStream();
            using (var writer = new CodeWriter(ms))
            {
                Array.ForEach(code ?? Instructions, writer.Write);
                writer.Close();

                var codeBlock = cpu.AllocateCodeBlock(cpu.IdleProcess, (uint )ms.Length);
                ms.WriteTo(codeBlock);
            }
        }
        public static uint Compile(this Cpu cpu, ProcessContextBlock pcb, string source)
        {
            var ms = new MemoryStream();
            using (var writer = new CodeWriter(ms))
            {
                var assembler = new Assembler(source);
                foreach (var i in assembler.Assemble())
                    writer.Write(i);

                writer.Close();

                var codeBlock = cpu.AllocateCodeBlock(pcb, (uint)ms.Length);
                ms.WriteTo(codeBlock);

                return (uint )ms.Length;
            }
        }
Beispiel #4
0
        public static uint Compile(this Cpu cpu, ProcessContextBlock pcb, IEnumerable<Instruction> instructions)
        {
            var stream = new MemoryStream();
            using (var writer = new CodeWriter(stream))
            {
                foreach (var instruction in instructions)
                    writer.Write(instruction);

                writer.Close();
                using (var ps = cpu.AllocateCodeBlock(pcb, (uint) stream.Length))
                    stream.WriteTo(ps);

                return (uint) stream.Length;
            }
        }
Beispiel #5
0
        private byte[] Compile(string file)
        {
            var ms = new MemoryStream();
            using (var writer = new CodeWriter(ms))
            {
                string source = File.ReadAllText(file);
                var assembler = new Assembler(source);
                assembler.Assemble().ToList().ForEach(writer.Write);
            }

            return ms.ToArray();
        }