/// <summary> /// Factor a new program node, based on an opcode name and arguments. /// </summary> /// <param name="name">The name of the opcode.</param> /// <param name="program">The program to factor for.</param> /// <param name="args">The arguements.</param> /// <returns>The newly created ProgramNode.</returns> public ProgramNode FactorProgramNode(String name, EncogProgram program, ProgramNode[] args) { String key = EncogOpcodeRegistry.CreateKey(name, args.Length); if (!_templateMap.ContainsKey(key)) { throw new EACompileError("Undefined function/operator: " + name + " with " + args.Length + " args."); } IProgramExtensionTemplate temp = _templateMap[key]; return(new ProgramNode(program, temp, args)); }
/// <summary> /// Add an opcode to the function factory from the opcode registry. /// </summary> /// <param name="name">The name of the opcode.</param> /// <param name="args">The number of arguments.</param> public void AddExtension(String name, int args) { String key = EncogOpcodeRegistry.CreateKey(name, args); if (!_templateMap.ContainsKey(key)) { IProgramExtensionTemplate temp = EncogOpcodeRegistry.Instance .FindOpcode(name, args); if (temp == null) { throw new EACompileError("Unknown extension " + name + " with " + args + " arguments."); } _opcodes.Add(temp); _templateMap[key] = temp; } }
/// <summary> /// Determine if an opcode is in the function factory. /// </summary> /// <param name="name">The name of the opcode.</param> /// <param name="l">The argument count for the opcode.</param> /// <returns>True if the opcode exists.</returns> public bool IsDefined(String name, int l) { String key = EncogOpcodeRegistry.CreateKey(name, l); return(_templateMap.ContainsKey(key)); }