File tree Expand file tree Collapse file tree 5 files changed +39
-0
lines changed
Expand file tree Collapse file tree 5 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,9 @@ class LIBSCRATCHCPP_EXPORT Block : public Entity
7070 BlockComp compileFunction () const ;
7171 void setCompileFunction (BlockComp newCompileFunction);
7272
73+ BlockComp hatPredicateCompileFunction () const ;
74+ void setHatPredicateCompileFunction (HatPredicateCompileFunc newHatPredicateCompileFunction);
75+
7376 bool mutationHasNext () const ;
7477 void setMutationHasNext (bool newMutationHasNext);
7578
Original file line number Diff line number Diff line change @@ -62,6 +62,13 @@ using MonitorNameFunc = const std::string &(*)(Block *);
6262 */
6363using MonitorChangeFunc = void (*)(Block *, const Value &newValue);
6464
65+ /* !
66+ * \typedef HatPredicateCompileFunc
67+ *
68+ * HatPredicateCompileFunc is a function pointer for functions which are used to compile edge-activated hat predicates to bytecode.
69+ */
70+ using HatPredicateCompileFunc = void (*)(Compiler *vm);
71+
6572} // namespace libscratchcpp
6673
6774#endif // LIBSCRATCHCPP_GLOBAL_H
Original file line number Diff line number Diff line change 44#include < scratchcpp/input.h>
55#include < scratchcpp/field.h>
66#include < scratchcpp/comment.h>
7+ #include < iostream>
78
89#include " block_p.h"
910
@@ -41,6 +42,24 @@ void Block::setCompileFunction(BlockComp newCompileFunction)
4142 impl->compileFunction = newCompileFunction;
4243}
4344
45+ /* ! Returns the edge-activated hat predicate compile function. \see <a href="blockSections.html">Block sections</a> */
46+ BlockComp Block::hatPredicateCompileFunction () const
47+ {
48+ return impl->hatPredicateCompileFunction ;
49+ }
50+
51+ /* ! Sets the edge-activated hat predicate compile function. \see <a href="blockSections.html">Block sections</a> */
52+ void Block::setHatPredicateCompileFunction (HatPredicateCompileFunc newHatPredicateCompileFunction)
53+ {
54+ if (newHatPredicateCompileFunction && !topLevel ()) {
55+ std::cerr << " error: predicate compile functions can be only used on top-level blocks" << std::endl;
56+ assert (false );
57+ return ;
58+ }
59+
60+ impl->hatPredicateCompileFunction = newHatPredicateCompileFunction;
61+ }
62+
4463/* ! Returns true if the block can have a block following it. */
4564bool Block::mutationHasNext () const
4665{
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ struct BlockPrivate
2323
2424 std::string opcode;
2525 BlockComp compileFunction = nullptr ;
26+ HatPredicateCompileFunc hatPredicateCompileFunction = nullptr ;
2627 std::shared_ptr<Block> next = nullptr ;
2728 std::string nextId;
2829 std::shared_ptr<Block> parent = nullptr ;
Original file line number Diff line number Diff line change @@ -247,6 +247,15 @@ TEST_F(BlockTest, CompileFunction)
247247 ASSERT_EQ (block.compileFunction (), &compileTest);
248248}
249249
250+ TEST_F (BlockTest, HatPredicateCompileFunction)
251+ {
252+ Block block (" " , " " );
253+ ASSERT_EQ (block.hatPredicateCompileFunction (), nullptr );
254+
255+ block.setHatPredicateCompileFunction (&compileTest);
256+ ASSERT_EQ (block.hatPredicateCompileFunction (), &compileTest);
257+ }
258+
250259TEST_F (BlockTest, Compile)
251260{
252261 Block block (" " , " " );
You can’t perform that action at this time.
0 commit comments