Ejemplo n.º 1
0
 public InterpreterState(Instruction[] code, int argumentStackSize) {
   this.code = code;
   this.ProgramCounter = 0;
   this.InLaggedContext = false;
   if (argumentStackSize > 0) {
     this.argumentStack = new double[argumentStackSize];
   }
   this.argumentStackPointer = 0;
 }
 private static IEnumerable<Instruction> Compile(ISymbolicExpressionTreeNode branch, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper, IEnumerable<Func<Instruction, Instruction>> postInstructionCompiledHooks) {
   foreach (var node in branch.IterateNodesPrefix()) {
     Instruction instr = new Instruction();
     int subtreesCount = node.SubtreeCount;
     if (subtreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)");
     instr.nArguments = (byte)subtreesCount;
     instr.opCode = opCodeMapper(node);
     if (node.Symbol is Argument) {
       var argNode = (ArgumentTreeNode)node;
       instr.data = (ushort)argNode.Symbol.ArgumentIndex;
     }
     instr.dynamicNode = node;
     foreach (var hook in postInstructionCompiledHooks) {
       instr = hook(instr);
     }
     yield return instr;
   }
 }