Skip to content

Commit 1ce8e6f

Browse files
committed
Implement operator_and
1 parent d3ef6a1 commit 1ce8e6f

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/dev/blocks/operatorblocks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
2828
engine->addCompileFunction(this, "operator_lt", &compileLt);
2929
engine->addCompileFunction(this, "operator_equals", &compileEquals);
3030
engine->addCompileFunction(this, "operator_gt", &compileGt);
31+
engine->addCompileFunction(this, "operator_and", &compileAnd);
3132
}
3233

3334
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
@@ -71,3 +72,8 @@ CompilerValue *OperatorBlocks::compileGt(Compiler *compiler)
7172
{
7273
return compiler->createCmpGT(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
7374
}
75+
76+
CompilerValue *OperatorBlocks::compileAnd(Compiler *compiler)
77+
{
78+
return compiler->createAnd(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
79+
}

src/dev/blocks/operatorblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class OperatorBlocks : public IExtension
2626
static CompilerValue *compileLt(Compiler *compiler);
2727
static CompilerValue *compileEquals(Compiler *compiler);
2828
static CompilerValue *compileGt(Compiler *compiler);
29+
static CompilerValue *compileAnd(Compiler *compiler);
2930
};
3031

3132
} // namespace libscratchcpp

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,40 @@ TEST_F(OperatorBlocksTest, Gt)
256256
ASSERT_EQ(Value(values[1]), true);
257257
ASSERT_EQ(Value(values[2]), false);
258258
}
259+
260+
TEST_F(OperatorBlocksTest, And)
261+
{
262+
auto target = std::make_shared<Sprite>();
263+
ScriptBuilder builder(m_extension.get(), m_engine, target);
264+
265+
builder.addBlock("operator_and");
266+
builder.addValueInput("OPERAND1", false);
267+
builder.addValueInput("OPERAND2", false);
268+
builder.captureBlockReturnValue();
269+
270+
builder.addBlock("operator_and");
271+
builder.addValueInput("OPERAND1", true);
272+
builder.addValueInput("OPERAND2", false);
273+
builder.captureBlockReturnValue();
274+
275+
builder.addBlock("operator_and");
276+
builder.addValueInput("OPERAND1", false);
277+
builder.addValueInput("OPERAND2", true);
278+
builder.captureBlockReturnValue();
279+
280+
builder.addBlock("operator_and");
281+
builder.addValueInput("OPERAND1", true);
282+
builder.addValueInput("OPERAND2", true);
283+
builder.captureBlockReturnValue();
284+
285+
builder.build();
286+
builder.run();
287+
288+
List *valueList = builder.capturedValues();
289+
ValueData *values = valueList->data();
290+
ASSERT_EQ(valueList->size(), 4);
291+
ASSERT_EQ(Value(values[0]), false);
292+
ASSERT_EQ(Value(values[1]), false);
293+
ASSERT_EQ(Value(values[2]), false);
294+
ASSERT_EQ(Value(values[3]), true);
295+
}

0 commit comments

Comments
 (0)