Skip to content

Commit 6954532

Browse files
committed
Add initial C++ function call implementation
1 parent 68bc1aa commit 6954532

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎src/engine/internal/codegen/cpp/instructions/functions.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "functions.h"
44
#include "../cppinstruction.h"
5+
#include "../cppcodegenerator.h"
56

67
using namespace libscratchcpp;
78
using namespace libscratchcpp::cppins;
@@ -25,5 +26,21 @@ ProcessResult Functions::process(CppInstruction *ins)
2526

2627
CppInstruction *Functions::buildFunctionCall(CppInstruction *ins)
2728
{
29+
// TODO: Synchronize variables
30+
std::vector<const CppIdentifier *> args;
31+
32+
const auto &insArgs = ins->getArgs();
33+
34+
for (auto &arg : insArgs) {
35+
args.push_back(m_codeGen.castValue(arg.second, arg.first));
36+
}
37+
38+
if (ins->getFunctionReturnReg()) {
39+
CppIdentifier::Type retType = m_codeGen.getType(ins->getFunctionReturnReg()->type());
40+
m_codeGen.createCall(ins->functionName, retType, ins->getFunctionReturnReg(), ins->functionCtxArg, ins->functionTargetArg, args);
41+
} else {
42+
m_codeGen.createCall(ins->functionName, ins->functionCtxArg, ins->functionTargetArg, args);
43+
}
44+
2845
return ins->getNext();
2946
}

0 commit comments

Comments
 (0)