Skip to content

Commit 22d16c5

Browse files
committed
Add empty block implementations to dev folder
1 parent 5b475d6 commit 22d16c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+981
-3
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
99
option(LIBSCRATCHCPP_BUILD_UNIT_TESTS "Build unit tests" ON)
1010
option(LIBSCRATCHCPP_NETWORK_SUPPORT "Support for downloading projects" ON)
1111
option(LIBSCRATCHCPP_COMPUTED_GOTO "Support for computed goto" ON)
12+
option(LIBSCRATCHCPP_USE_LLVM "Compile scripts to LLVM IR (work in progress)" OFF)
1213

1314
if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
1415
# Computed goto not supported on anything except GCC
@@ -65,6 +66,10 @@ target_sources(scratchcpp
6566
include/scratchcpp/imonitorhandler.h
6667
)
6768

69+
if (LIBSCRATCHCPP_USE_LLVM)
70+
target_compile_definitions(scratchcpp PUBLIC USE_LLVM)
71+
endif()
72+
6873
include(FetchContent)
6974
set(ZIP_SRC thirdparty/zip/src)
7075
set(UTFCPP_SRC thirdparty/utfcpp/source)

src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ target_sources(scratchcpp
1111
rect_p.h
1212
)
1313

14-
add_subdirectory(blocks)
14+
if (NOT LIBSCRATCHCPP_USE_LLVM)
15+
add_subdirectory(blocks)
16+
endif()
17+
1518
add_subdirectory(engine)
1619
add_subdirectory(internal)
1720
add_subdirectory(scratch)
1821
add_subdirectory(audio)
22+
23+
if (LIBSCRATCHCPP_USE_LLVM)
24+
add_subdirectory(dev)
25+
endif()

src/dev/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(blocks)

src/dev/blocks/CMakeLists.txt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
target_sources(scratchcpp
2+
PRIVATE
3+
blocks.cpp
4+
blocks.h
5+
)
6+
7+
# Motion blocks
8+
option(LIBSCRATCHCPP_ENABLE_MOTION_BLOCKS "Motion blocks support" ON)
9+
if (LIBSCRATCHCPP_ENABLE_MOTION_BLOCKS)
10+
target_compile_definitions(scratchcpp PRIVATE ENABLE_MOTION_BLOCKS)
11+
target_sources(scratchcpp
12+
PRIVATE
13+
motionblocks.cpp
14+
motionblocks.h
15+
)
16+
endif()
17+
18+
# Looks blocks
19+
option(LIBSCRATCHCPP_ENABLE_LOOKS_BLOCKS "Looks blocks support" ON)
20+
if (LIBSCRATCHCPP_ENABLE_LOOKS_BLOCKS)
21+
target_compile_definitions(scratchcpp PRIVATE ENABLE_LOOKS_BLOCKS)
22+
target_sources(scratchcpp
23+
PRIVATE
24+
looksblocks.cpp
25+
looksblocks.h
26+
)
27+
endif()
28+
29+
# Sound blocks
30+
option(LIBSCRATCHCPP_ENABLE_SOUND_BLOCKS "Sound blocks support" ON)
31+
if (LIBSCRATCHCPP_ENABLE_SOUND_BLOCKS)
32+
target_compile_definitions(scratchcpp PRIVATE ENABLE_SOUND_BLOCKS)
33+
target_sources(scratchcpp
34+
PRIVATE
35+
soundblocks.cpp
36+
soundblocks.h
37+
)
38+
endif()
39+
40+
# Event blocks
41+
option(LIBSCRATCHCPP_ENABLE_EVENT_BLOCKS "Event blocks support" ON)
42+
if (LIBSCRATCHCPP_ENABLE_EVENT_BLOCKS)
43+
target_compile_definitions(scratchcpp PRIVATE ENABLE_EVENT_BLOCKS)
44+
target_sources(scratchcpp
45+
PRIVATE
46+
eventblocks.cpp
47+
eventblocks.h
48+
)
49+
endif()
50+
51+
# Control blocks
52+
option(LIBSCRATCHCPP_ENABLE_CONTROL_BLOCKS "Control blocks support" ON)
53+
if (LIBSCRATCHCPP_ENABLE_CONTROL_BLOCKS)
54+
target_compile_definitions(scratchcpp PRIVATE ENABLE_CONTROL_BLOCKS)
55+
target_sources(scratchcpp
56+
PRIVATE
57+
controlblocks.cpp
58+
controlblocks.h
59+
)
60+
endif()
61+
62+
# Sensing blocks
63+
option(LIBSCRATCHCPP_ENABLE_SENSING_BLOCKS "Sensing blocks support" ON)
64+
if (LIBSCRATCHCPP_ENABLE_SENSING_BLOCKS)
65+
target_compile_definitions(scratchcpp PRIVATE ENABLE_SENSING_BLOCKS)
66+
target_sources(scratchcpp
67+
PRIVATE
68+
sensingblocks.cpp
69+
sensingblocks.h
70+
)
71+
endif()
72+
73+
# Operator blocks
74+
option(LIBSCRATCHCPP_ENABLE_OPERATOR_BLOCKS "Operator blocks support" ON)
75+
if (LIBSCRATCHCPP_ENABLE_OPERATOR_BLOCKS)
76+
target_compile_definitions(scratchcpp PRIVATE ENABLE_OPERATOR_BLOCKS)
77+
target_sources(scratchcpp
78+
PRIVATE
79+
operatorblocks.cpp
80+
operatorblocks.h
81+
)
82+
endif()
83+
84+
# Variable blocks
85+
option(LIBSCRATCHCPP_ENABLE_VARIABLE_BLOCKS "Variable blocks support" ON)
86+
if (LIBSCRATCHCPP_ENABLE_VARIABLE_BLOCKS)
87+
target_compile_definitions(scratchcpp PRIVATE ENABLE_VARIABLE_BLOCKS)
88+
target_sources(scratchcpp
89+
PRIVATE
90+
variableblocks.cpp
91+
variableblocks.h
92+
)
93+
endif()
94+
95+
# List blocks
96+
option(LIBSCRATCHCPP_ENABLE_LIST_BLOCKS "List blocks support" ON)
97+
if (LIBSCRATCHCPP_ENABLE_LIST_BLOCKS)
98+
target_compile_definitions(scratchcpp PRIVATE ENABLE_LIST_BLOCKS)
99+
target_sources(scratchcpp
100+
PRIVATE
101+
listblocks.cpp
102+
listblocks.h
103+
)
104+
endif()
105+
106+
# Custom blocks
107+
option(LIBSCRATCHCPP_ENABLE_CUSTOM_BLOCKS "Custom blocks support" ON)
108+
if (LIBSCRATCHCPP_ENABLE_CUSTOM_BLOCKS)
109+
target_compile_definitions(scratchcpp PRIVATE ENABLE_CUSTOM_BLOCKS)
110+
target_sources(scratchcpp
111+
PRIVATE
112+
customblocks.cpp
113+
customblocks.h
114+
)
115+
endif()

src/dev/blocks/blocks.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include <scratchcpp/scratchconfiguration.h>
4+
5+
#include "blocks.h"
6+
7+
#ifdef ENABLE_MOTION_BLOCKS
8+
#include "motionblocks.h"
9+
#endif
10+
#ifdef ENABLE_LOOKS_BLOCKS
11+
#include "looksblocks.h"
12+
#endif
13+
#ifdef ENABLE_SOUND_BLOCKS
14+
#include "soundblocks.h"
15+
#endif
16+
#ifdef ENABLE_EVENT_BLOCKS
17+
#include "eventblocks.h"
18+
#endif
19+
#ifdef ENABLE_CONTROL_BLOCKS
20+
#include "controlblocks.h"
21+
#endif
22+
#ifdef ENABLE_SENSING_BLOCKS
23+
#include "sensingblocks.h"
24+
#endif
25+
#ifdef ENABLE_OPERATOR_BLOCKS
26+
#include "operatorblocks.h"
27+
#endif
28+
#ifdef ENABLE_VARIABLE_BLOCKS
29+
#include "variableblocks.h"
30+
#endif
31+
#ifdef ENABLE_LIST_BLOCKS
32+
#include "listblocks.h"
33+
#endif
34+
#ifdef ENABLE_CUSTOM_BLOCKS
35+
#include "customblocks.h"
36+
#endif
37+
38+
using namespace libscratchcpp;
39+
40+
Blocks Blocks::m_instance;
41+
42+
const std::vector<std::shared_ptr<IExtension>> &Blocks::extensions()
43+
{
44+
return m_instance.m_extensions;
45+
}
46+
47+
Blocks::Blocks()
48+
{
49+
#ifdef ENABLE_MOTION_BLOCKS
50+
m_extensions.push_back(std::make_shared<MotionBlocks>());
51+
#endif
52+
#ifdef ENABLE_LOOKS_BLOCKS
53+
m_extensions.push_back(std::make_shared<LooksBlocks>());
54+
#endif
55+
#ifdef ENABLE_SOUND_BLOCKS
56+
m_extensions.push_back(std::make_shared<SoundBlocks>());
57+
#endif
58+
#ifdef ENABLE_EVENT_BLOCKS
59+
m_extensions.push_back(std::make_shared<EventBlocks>());
60+
#endif
61+
#ifdef ENABLE_CONTROL_BLOCKS
62+
m_extensions.push_back(std::make_shared<ControlBlocks>());
63+
#endif
64+
#ifdef ENABLE_SENSING_BLOCKS
65+
m_extensions.push_back(std::make_shared<SensingBlocks>());
66+
#endif
67+
#ifdef ENABLE_OPERATOR_BLOCKS
68+
m_extensions.push_back(std::make_shared<OperatorBlocks>());
69+
#endif
70+
#ifdef ENABLE_VARIABLE_BLOCKS
71+
m_extensions.push_back(std::make_shared<VariableBlocks>());
72+
#endif
73+
#ifdef ENABLE_LIST_BLOCKS
74+
m_extensions.push_back(std::make_shared<ListBlocks>());
75+
#endif
76+
#ifdef ENABLE_CUSTOM_BLOCKS
77+
m_extensions.push_back(std::make_shared<CustomBlocks>());
78+
#endif
79+
}
80+
81+
void Blocks::registerExtensions()
82+
{
83+
for (auto ext : m_extensions)
84+
ScratchConfiguration::registerExtension(ext);
85+
}

src/dev/blocks/blocks.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include <vector>
6+
#include <memory>
7+
8+
namespace libscratchcpp
9+
{
10+
11+
class IExtension;
12+
13+
class Blocks
14+
{
15+
public:
16+
static const std::vector<std::shared_ptr<IExtension>> &extensions();
17+
18+
private:
19+
Blocks();
20+
void registerExtensions();
21+
22+
static Blocks m_instance; // use static initialization
23+
std::vector<std::shared_ptr<IExtension>> m_extensions;
24+
};
25+
26+
} // namespace libscratchcpp

src/dev/blocks/controlblocks.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include "controlblocks.h"
4+
5+
using namespace libscratchcpp;
6+
7+
std::string ControlBlocks::name() const
8+
{
9+
return "Control";
10+
}
11+
12+
std::string ControlBlocks::description() const
13+
{
14+
return name() + " blocks";
15+
}
16+
17+
void ControlBlocks::registerBlocks(IEngine *engine)
18+
{
19+
}

src/dev/blocks/controlblocks.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include <scratchcpp/iextension.h>
6+
7+
namespace libscratchcpp
8+
{
9+
10+
class ControlBlocks : public IExtension
11+
{
12+
public:
13+
std::string name() const override;
14+
std::string description() const override;
15+
16+
void registerBlocks(IEngine *engine) override;
17+
};
18+
19+
} // namespace libscratchcpp

src/dev/blocks/customblocks.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include "customblocks.h"
4+
5+
using namespace libscratchcpp;
6+
7+
std::string CustomBlocks::name() const
8+
{
9+
return "Custom blocks";
10+
}
11+
12+
std::string CustomBlocks::description() const
13+
{
14+
return name();
15+
}
16+
17+
void CustomBlocks::registerBlocks(IEngine *engine)
18+
{
19+
}

src/dev/blocks/customblocks.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include <scratchcpp/iextension.h>
6+
7+
namespace libscratchcpp
8+
{
9+
10+
class CustomBlocks : public IExtension
11+
{
12+
public:
13+
std::string name() const override;
14+
std::string description() const override;
15+
16+
void registerBlocks(IEngine *engine) override;
17+
};
18+
19+
} // namespace libscratchcpp

0 commit comments

Comments
 (0)