File tree Expand file tree Collapse file tree 4 files changed +54
-6
lines changed
Expand file tree Collapse file tree 4 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -126,13 +126,31 @@ void Compiler::addInput(int id)
126126 addInstruction (OP_CONST, { constIndex (in->primaryValue ()) });
127127 break ;
128128
129- case Input::Type::NoShadow:
130- addInstruction (OP_NULL);
129+ case Input::Type::NoShadow: {
130+ auto previousBlock = m_block;
131+ m_block = in->valueBlock ();
132+ assert (m_block);
133+ if (m_block->compileFunction ())
134+ m_block->compile (this );
135+ else
136+ std::cout << " warning: unsupported reporter block: " << m_block->opcode () << std::endl;
137+ m_block = previousBlock;
131138 break ;
132-
133- case Input::Type::ObscuredShadow:
134- // TODO
139+ }
140+
141+ case Input::Type::ObscuredShadow: {
142+ auto previousBlock = m_block;
143+ m_block = in->valueBlock ();
144+ if (m_block) {
145+ if (m_block->compileFunction ())
146+ m_block->compile (this );
147+ else
148+ std::cout << " warning: unsupported reporter block: " << m_block->opcode () << std::endl;
149+ } else
150+ in->primaryValue ()->compile (this );
151+ m_block = previousBlock;
135152 break ;
153+ }
136154 }
137155}
138156
Original file line number Diff line number Diff line change @@ -47,9 +47,9 @@ class LIBSCRATCHCPP_EXPORT Compiler
4747 std::shared_ptr<Block> inputBlock (int id) const ;
4848 unsigned int variableIndex (std::shared_ptr<IEntity> varEntity);
4949 unsigned int listIndex (std::shared_ptr<IEntity> listEntity);
50+ unsigned int constIndex (InputValue *value);
5051
5152 private:
52- unsigned int constIndex (InputValue *value);
5353 void substackEnd ();
5454
5555 Engine *m_engine;
Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: Apache-2.0
22
33#include " inputvalue.h"
4+ #include " ../engine/compiler.h"
45#include < map>
56
67using namespace libscratchcpp ;
@@ -22,6 +23,32 @@ InputValue::InputValue(Type type) :
2223{
2324}
2425
26+ /* ! Compiles the input value. */
27+ void InputValue::compile (Compiler *compiler)
28+ {
29+ switch (m_type) {
30+ case Type::Color:
31+ // TODO: Add support for colors
32+ break ;
33+
34+ case Type::Broadcast:
35+ // TODO: Add support for broadcasts
36+ break ;
37+
38+ case Type::Variable:
39+ compiler->addInstruction (vm::OP_READ_VAR, { compiler->variableIndex (m_valuePtr) });
40+ break ;
41+
42+ case Type::List:
43+ compiler->addInstruction (vm::OP_READ_LIST, { compiler->listIndex (m_valuePtr) });
44+ break ;
45+
46+ default :
47+ compiler->addInstruction (vm::OP_CONST, { compiler->constIndex (this ) });
48+ break ;
49+ }
50+ }
51+
2552/* ! Returns the type of the value. */
2653InputValue::Type InputValue::type () const
2754{
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ namespace libscratchcpp
1010{
1111
1212class LIBSCRATCHCPP_EXPORT Block;
13+ class LIBSCRATCHCPP_EXPORT Compiler;
1314
1415/* ! \brief The InputValue class provides methods for the value of an Input. */
1516class LIBSCRATCHCPP_EXPORT InputValue
@@ -32,6 +33,8 @@ class LIBSCRATCHCPP_EXPORT InputValue
3233 InputValue ();
3334 InputValue (Type type);
3435
36+ void compile (Compiler *compiler);
37+
3538 Type type () const ;
3639 void setType (Type newType);
3740
You can’t perform that action at this time.
0 commit comments