Skip to content

Commit f3546e6

Browse files
committed
Implement block function static types
1 parent cb3570c commit f3546e6

File tree

10 files changed

+446
-191
lines changed

10 files changed

+446
-191
lines changed

include/scratchcpp/dev/compiler.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include <unordered_set>
6+
#include <vector>
67

78
#include "../global.h"
89
#include "../spimpl.h"
@@ -23,6 +24,14 @@ class CompilerPrivate;
2324
class LIBSCRATCHCPP_EXPORT Compiler
2425
{
2526
public:
27+
enum class StaticType
28+
{
29+
Void,
30+
Number,
31+
Bool,
32+
String
33+
};
34+
2635
Compiler(IEngine *engine, Target *target);
2736
Compiler(const Compiler &) = delete;
2837

@@ -32,7 +41,7 @@ class LIBSCRATCHCPP_EXPORT Compiler
3241

3342
std::shared_ptr<ExecutableCode> compile(std::shared_ptr<Block> startBlock);
3443

35-
void addFunctionCall(const std::string &functionName, int argCount, bool returns);
44+
void addFunctionCall(const std::string &functionName, StaticType returnType = StaticType::Void, const std::vector<StaticType> &argTypes = {});
3645
void addConstValue(const Value &value);
3746
void addVariableValue(Variable *variable);
3847
void addListContents(List *list);

src/dev/engine/compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBl
7373
* Adds a call to the given function.\n
7474
* For example: extern "C" some_block(ValueData *ret, ValueData *arg1, ValueData *arg2) has 2 arguments
7575
*/
76-
void Compiler::addFunctionCall(const std::string &functionName, int argCount, bool returns)
76+
void Compiler::addFunctionCall(const std::string &functionName, StaticType returnType, const std::vector<StaticType> &argTypes)
7777
{
78-
impl->builder->addFunctionCall(functionName, argCount, returns);
78+
impl->builder->addFunctionCall(functionName, returnType, argTypes);
7979
}
8080

8181
/*! Adds a constant value to the compiled code. */

src/dev/engine/internal/icodebuilder.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
#pragma once
44

5-
#include <string>
6-
#include <memory>
5+
#include <scratchcpp/dev/compiler.h>
76

87
namespace libscratchcpp
98
{
@@ -20,7 +19,7 @@ class ICodeBuilder
2019

2120
virtual std::shared_ptr<ExecutableCode> finalize() = 0;
2221

23-
virtual void addFunctionCall(const std::string &functionName, int argCount, bool returns) = 0;
22+
virtual void addFunctionCall(const std::string &functionName, Compiler::StaticType returnType, const std::vector<Compiler::StaticType> &argTypes) = 0;
2423
virtual void addConstValue(const Value &value) = 0;
2524
virtual void addVariableValue(Variable *variable) = 0;
2625
virtual void addListContents(List *list) = 0;

0 commit comments

Comments
 (0)