using System; using System.Collections.Generic; using System.Reflection.Emit; using System.Text; namespace Sunweaver.DataPrototypes { public class DNA { public List Chromosomes; public Dictionary PersonalConstants; private delegate void ExecuteDelegate(Memory baseMemory); private ExecuteDelegate Run; public DNA() { Chromosomes = new List(); PersonalConstants = new Dictionary(); Chromosomes.Add(new Chromosome(this)); Run = Interpret; } public void Execute(Memory baseMemory) { Run(baseMemory); } public void Interpret(Memory baseMemory) { foreach (Chromosome c in Chromosomes) { c.Excecute(baseMemory); } } public void Compile() { var method = new DynamicMethod(string.Empty, typeof(void), new Type[] { typeof(DNA), typeof(Memory) }, typeof(DNA).Module); ILGenerator il = method.GetILGenerator(); Locals locals = new Locals(il); foreach (Chromosome c in Chromosomes) { c.Compile(il, locals); } il.Emit(OpCodes.Ret); Run = (ExecuteDelegate) method.CreateDelegate(typeof(ExecuteDelegate), this); } } }