@@ -69,32 +69,20 @@ void Engine::compile()
6969 // Compile scripts to bytecode
7070 for (auto target : m_targets) {
7171 std::cout << " Compiling scripts in target " << target->name () << " ..." << std::endl;
72- std::vector<Variable *> variables;
73- std::vector<List *> lists;
74- std::vector<InputValue *> constInputValues;
75- std::vector<std::string> procedures;
7672 std::unordered_map<std::string, unsigned int *> procedureBytecodeMap;
73+ Compiler compiler (this );
7774 auto blocks = target->blocks ();
7875 for (auto block : blocks) {
7976 if (block->topLevel ()) {
8077 auto section = blockSection (block->opcode ());
8178 if (section) {
82- Compiler compiler (this , block);
83- compiler.setConstInputValues (constInputValues);
84- compiler.setVariables (variables);
85- compiler.setLists (lists);
86- compiler.setProcedures (procedures);
87- compiler.compile ();
88- variables = compiler.variables ();
89- lists = compiler.lists ();
90- constInputValues = compiler.constInputValues ();
91- procedures = compiler.procedures ();
79+ compiler.compile (block);
9280
9381 auto vm = std::make_shared<VirtualMachine>(target.get (), this );
9482 vm->setFunctions (m_functions);
9583 vm->setConstValues (compiler.constValues ());
9684 vm->setVariables (compiler.variablePtrs ());
97- vm->setLists (lists);
85+ vm->setLists (compiler. lists () );
9886 vm->setBytecode (compiler.bytecode ());
9987 if (block->opcode () == " procedures_definition" ) {
10088 auto b = block->inputAt (block->findInput (" custom_block" ))->valueBlock ();
@@ -106,6 +94,7 @@ void Engine::compile()
10694 }
10795 }
10896
97+ const std::vector<std::string> &procedures = compiler.procedures ();
10998 std::vector<unsigned int *> procedureBytecodes;
11099 for (const std::string &code : procedures)
111100 procedureBytecodes.push_back (procedureBytecodeMap[code]);
0 commit comments