@@ -103,7 +103,7 @@ const std::vector<List *> &Compiler::lists() const
103103}
104104
105105/* ! Adds an instruction to the bytecode. */
106- void Compiler::addInstruction (Opcode opcode, std::initializer_list<unsigned int > args)
106+ void Compiler::addInstruction (Opcode opcode, const std::initializer_list<unsigned int > & args)
107107{
108108 impl->addInstruction (opcode, args);
109109}
@@ -165,8 +165,15 @@ void Compiler::addFunctionCall(BlockFunc f)
165165}
166166
167167/* ! Adds an argument to a procedure (custom block). */
168- void Compiler::addProcedureArg (std::string procCode, std::string argName)
168+ void Compiler::addProcedureArg (const std::string & procCode, const std::string & argName)
169169{
170+ if (impl->procedureArgs .find (procCode) != impl->procedureArgs .cend ()) {
171+ const auto &procedure = impl->procedureArgs [procCode];
172+
173+ if (std::find (procedure.begin (), procedure.end (), argName) != procedure.end ())
174+ return ;
175+ }
176+
170177 impl->procedureArgs [procCode].push_back (argName);
171178}
172179
@@ -254,7 +261,7 @@ unsigned int Compiler::constIndex(InputValue *value)
254261}
255262
256263/* ! Returns the index of the procedure code of the given block. */
257- unsigned int Compiler::procedureIndex (std::string proc)
264+ unsigned int Compiler::procedureIndex (const std::string & proc)
258265{
259266 auto it = std::find (impl->procedures .begin (), impl->procedures .end (), proc);
260267 if (it != impl->procedures .end ())
@@ -264,7 +271,7 @@ unsigned int Compiler::procedureIndex(std::string proc)
264271}
265272
266273/* ! Returns the index of the argument of the given procedure (custom block). */
267- long Compiler::procedureArgIndex (std::string procCode, std::string argName)
274+ long Compiler::procedureArgIndex (const std::string & procCode, const std::string & argName)
268275{
269276 if (impl->procedureArgs .count (procCode) == 0 ) {
270277 std::cout << " warning: could not find custom block '" << procCode << " '" << std::endl;
0 commit comments