Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ __pycache__/
.DS_Store

# Test artifacts (generated in build directory, but ignore strays)
tests/baselines/**/*.bytecode
tests/reports/*.json
tests/outputs/
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ if(PROJECT_IS_TOP_LEVEL)
)

# Custom target: Generate/update baselines
add_custom_target(test-baselines
add_custom_target(update-test-baselines
COMMAND ${TEST_RUNNER_CMD} --update-baselines
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating test baselines"
COMMENT "Updating test baselines"
DEPENDS gs2test
)

Expand Down Expand Up @@ -243,7 +243,7 @@ if(PROJECT_IS_TOP_LEVEL)
message(STATUS " Reports in: ${CMAKE_BINARY_DIR}/tests/reports")
message(STATUS " Available targets:")
message(STATUS " run-tests - Run test suite with verbose output")
message(STATUS " test-baselines - Generate/update baseline bytecode")
message(STATUS " update-test-baselines - Generate/update baseline bytecode")
message(STATUS " test-clean - Clean test artifacts")
message(STATUS " test or ctest - Run tests (quiet, for CI/CD)")

Expand Down
22 changes: 5 additions & 17 deletions src/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ class ExpressionArrayIndexNode : public ExpressionNode
if (list)
{
exprList = std::move(*list);
delete list;
}

for (const auto& expr : exprList)
Expand Down Expand Up @@ -499,17 +498,17 @@ class ExpressionUnaryOpNode : public ExpressionNode
return expr->toString() + std::string(ExpressionOpToString(op));
}

virtual ExpressionType expressionType() const
ExpressionType expressionType() const override
{
switch (op)
{
case ExpressionOp::UnaryMinus:
case ExpressionOp::UnaryNot:
return ExpressionType::EXPR_NUMBER;
default:
return expr->expressionType();
}

return expr->expressionType();
}
}
};

class ExpressionFnCallNode : public ExpressionNode
Expand All @@ -523,7 +522,6 @@ class ExpressionFnCallNode : public ExpressionNode
if (argList)
{
args = std::move(*argList);
delete argList;
}

takeOwnership(funcExpr, objExpr);
Expand Down Expand Up @@ -566,7 +564,6 @@ class ExpressionNewArrayNode : public ExpressionNode
if (dim)
{
dimensions = std::move(*dim);
delete dim;
}
}

Expand Down Expand Up @@ -596,7 +593,6 @@ class ExpressionNewObjectNode : public ExpressionNode
if (argList)
{
args = std::move(*argList);
delete argList;
}

takeOwnership(newExpr);
Expand Down Expand Up @@ -628,7 +624,6 @@ class ExpressionListNode : public ExpressionNode
if (argList)
{
args = std::move(*argList);
delete argList;
}

for (const auto& node : args)
Expand Down Expand Up @@ -701,7 +696,6 @@ class StatementFnDeclNode : public StatementNode
if (argList)
{
args = std::move(*argList);
delete argList;
}

takeOwnership(stmtBlock);
Expand Down Expand Up @@ -731,7 +725,6 @@ class StatementNewNode : public StatementNode
if (argList)
{
args = std::move(*argList);
delete argList;
}

takeOwnership(stmtBlock);
Expand Down Expand Up @@ -899,7 +892,6 @@ class StatementSwitchNode : public StatementNode
if (caseNodes)
{
cases = std::move(*caseNodes);
delete caseNodes;
}

takeOwnership(expr);
Expand Down Expand Up @@ -943,11 +935,7 @@ class EnumList
addMember(member);
}

~EnumList()
{
for (const auto& n : members)
delete n;
}
~EnumList() = default;

void addMember(EnumMember *member);

Expand Down
20 changes: 2 additions & 18 deletions src/codegen/GS2Bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ int32_t GS2Bytecode::getStringConst(const std::string& str)

Buffer GS2Bytecode::getByteCode()
{
// This fixes a weird bug in which the last function was uncallable,
// i am unsure if this is a bug with our specific client or something
// weird is happening during compilation that is causing the issue.
// I've used identical bytecode as per the decompiler, and still
// ran into this issue so I believe its a client issue.
// Either way, emitting this op seems to fix it. *shrugs*
// - joey
emit(opcode::OP_RET);

Buffer byteCode;

// GS1EventFlags
Expand Down Expand Up @@ -93,12 +84,6 @@ Buffer GS2Bytecode::getByteCode()
functionTableBuffer.Write<encoding::Int32>(func.opIndex);
functionTableBuffer.write(func.functionName.c_str(), func.functionName.length());
functionTableBuffer.write('\0');

// emit a jump before the function declaration to the last op index
if (func.jmpLoc != 0)
{
emit(short(opIndex), func.jmpLoc - 2);
}
}
}

Expand Down Expand Up @@ -130,16 +115,15 @@ Buffer GS2Bytecode::getByteCode()
return byteCode;
}

void GS2Bytecode::addFunction(std::string functionName, uint32_t opIdx, size_t jmpLoc)
void GS2Bytecode::addFunction(std::string functionName, uint32_t opIdx)
{
auto ret = functionSet.insert(functionName);

if (ret.second)
{
functionTable.push_back(FunctionEntry{
std::move(functionName),
opIdx,
jmpLoc
opIdx
});
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/GS2Bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ struct FunctionEntry
{
std::string functionName;
uint32_t opIndex;
size_t jmpLoc;
};

class GS2Bytecode
{
friend class GS2CompilerVisitor;
friend class JumpTarget;

private:
GS2Bytecode() : opIndex(0), lastOp(opcode::Opcode::OP_NONE) {}

Buffer getByteCode();
int32_t getStringConst(const std::string& str);

void addFunction(std::string functionName, uint32_t opIdx, size_t jmpLoc);
void addFunction(std::string functionName, uint32_t opIdx);

/*
* Functions to emit bytecode into the underlying buffer
Expand Down
Loading
Loading