Skip to content

Commit

Permalink
#637 - [FIXED]unit tests for byRefOp optimization - variant 1
Browse files Browse the repository at this point in the history
  • Loading branch information
arakov committed Apr 2, 2024
1 parent e381728 commit 8c987fd
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 140 deletions.
2 changes: 1 addition & 1 deletion elenasrc3/elc/cliconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace elena_lang
{
#define ELC_REVISION_NUMBER 0x0248
#define ELC_REVISION_NUMBER 0x0249

#if defined _M_IX86 || _M_X64

Expand Down
98 changes: 49 additions & 49 deletions elenasrc3/elc/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8598,62 +8598,62 @@ void Compiler :: compileVMT(BuildTreeWriter& writer, ClassScope& scope, SyntaxNo
SyntaxNode current = node.firstChild();
while (current != SyntaxKey::None) {
switch (current.key) {
case SyntaxKey::Method:
{
if (exclusiveMode
&& (ignoreAutoMultimethod == SyntaxTree::ifChildExists(current, SyntaxKey::Autogenerated, -1)))
case SyntaxKey::Method:
{
current = current.nextNode();
continue;
}
if (exclusiveMode
&& (ignoreAutoMultimethod == SyntaxTree::ifChildExists(current, SyntaxKey::Autogenerated, -1)))
{
current = current.nextNode();
continue;
}

MethodScope methodScope(&scope);
initializeMethod(scope, methodScope, current);
MethodScope methodScope(&scope);
initializeMethod(scope, methodScope, current);

#ifdef FULL_OUTOUT_INFO
IdentifierString messageName;
ByteCodeUtil::resolveMessageName(messageName, scope.module, methodScope.message);
#ifdef FULL_OUTOUT_INFO
IdentifierString messageName;
ByteCodeUtil::resolveMessageName(messageName, scope.module, methodScope.message);

// !! temporal
if (messageName.compare("static:getItem<'IntNumber,'Object>[3]"))
methodScope.message |= 0;
// !! temporal
if (messageName.compare("static:getItem<'IntNumber,'Object>[3]"))
methodScope.message |= 0;

_errorProcessor->info(infoCurrentMethod, *messageName);
#endif // FULL_OUTOUT_INFO
_errorProcessor->info(infoCurrentMethod, *messageName);
#endif // FULL_OUTOUT_INFO

// if it is a dispatch handler
if (methodScope.message == scope.moduleScope->buildins.dispatch_message) {
compileDispatcherMethod(writer, methodScope, current,
test(scope.info.header.flags, elWithGenerics),
test(scope.info.header.flags, elWithVariadics));
}
// if it is an abstract one
else if (methodScope.checkHint(MethodHint::Abstract)) {
compileAbstractMethod(writer, methodScope, current, scope.abstractMode);
}
// if it is an initializer
else if (methodScope.checkHint(MethodHint::Initializer)) {
compileInitializerMethod(writer, methodScope, node);
}
// if it is a normal method
else compileMethod(writer, methodScope, current);
break;
}
case SyntaxKey::Constructor:
if (_logic->isRole(scope.info)) {
scope.raiseError(errIllegalConstructor, node);
}
break;
case SyntaxKey::StaticMethod:
if (_logic->isRole(scope.info)) {
scope.raiseError(errIllegalStaticMethod, node);
// if it is a dispatch handler
if (methodScope.message == scope.moduleScope->buildins.dispatch_message) {
compileDispatcherMethod(writer, methodScope, current,
test(scope.info.header.flags, elWithGenerics),
test(scope.info.header.flags, elWithVariadics));
}
// if it is an abstract one
else if (methodScope.checkHint(MethodHint::Abstract)) {
compileAbstractMethod(writer, methodScope, current, scope.abstractMode);
}
// if it is an initializer
else if (methodScope.checkHint(MethodHint::Initializer)) {
compileInitializerMethod(writer, methodScope, node);
}
// if it is a normal method
else compileMethod(writer, methodScope, current);
break;
}
break;
case SyntaxKey::StaticInitializerMethod:
compileStaticInitializerMethod(writer, scope, current);
break;
default:
break;
case SyntaxKey::Constructor:
if (_logic->isRole(scope.info)) {
scope.raiseError(errIllegalConstructor, node);
}
break;
case SyntaxKey::StaticMethod:
if (_logic->isRole(scope.info)) {
scope.raiseError(errIllegalStaticMethod, node);
}
break;
case SyntaxKey::StaticInitializerMethod:
compileStaticInitializerMethod(writer, scope, current);
break;
default:
break;
}

current = current.nextNode();
Expand Down
30 changes: 28 additions & 2 deletions elenasrc3/elena-tests/bt_optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,40 @@
#include "bt_optimization.h"
#include "serializer.h"

#include <windows.h>

using namespace elena_lang;

constexpr auto BT_RULES_FILE = "bt_rules60.dat";

inline void getAppPath(PathString& appPath)
{
wchar_t path[MAX_PATH + 1];

::GetModuleFileName(nullptr, path, MAX_PATH);

appPath.copySubPath(path, false);
appPath.lower();
}

// --- BTOptimization1 ---

constexpr auto Declaration1_1 = "namespace (class ( nameattr (identifier \"Object\" ())) class (attribute -2147467263 () attribute -2147475455 () attribute -2147479550 () nameattr (identifier \"Struct\" ()) field (attribute -2147475454 () attribute -2147481597 () nameattr (identifier \"_value\" ())dimension (integer \"4\" ()))) class ( attribute -2147471359 () nameattr (identifier \"TestReference\" ()) field (attribute -2147475454 () type (identifier \"Struct\" ()) nameattr (identifier \"_value\" ())) ) class (attribute -2147467263 ()attribute -2147479546 () nameattr (identifier \"Tester\" ()) method (type (identifier \"Struct\" ()) nameattr (identifier \"getValue\" ())code ())))";
constexpr auto SyntaxTree1_1 = "expression(assign_operation(object(type(identifier \"Struct\"())identifier \"r\"())expression(message_operation(object(identifier \"Tester\"())message(identifier \"getValue\" ())))))";
constexpr auto BuildTree1_1 = "byrefmark -8 () local_address -8 () saving_stack 1 () class_reference 4 () saving_stack () argument () direct_call_op 2050 (type 4 ()) local_address -8 () copying -4 (size 4 ())";
constexpr auto OptimizedBuildTree1_1 = "local_address -4 () saving_stack 1 () class_reference 4 () saving_stack () argument () direct_call_op 2050 (type 4 ()) local_address -4 ()";

void BTOptimization1_1 :: SetUp()
{
PathString appPath;
getAppPath(appPath);

PathString btRulesPath(*appPath, BT_RULES_FILE);
FileReader btRuleReader(*btRulesPath, FileRBMode, FileEncoding::Raw, false);
if (btRuleReader.isOpen()) {
btRules.load(btRuleReader, btRuleReader.length());
}

SyntaxTreeWriter writer(syntaxTree);
writer.appendNode(SyntaxKey::Root);

Expand All @@ -30,6 +54,8 @@ void BTOptimization1_1 :: SetUp()
SyntaxTreeSerializer::load(Declaration1_1, declarationNode);
SyntaxTreeSerializer::load(SyntaxTree1_1, exprNode);

auto outputNode = buildTree.readRoot();
BuildTreeSerializer::load(BuildTree1_1, outputNode);
beforeOptimization = buildTree.readRoot().appendChild(BuildKey::Tape);
afterOptimization = buildTree.readRoot().appendChild(BuildKey::Tape);
BuildTreeSerializer::load(BuildTree1_1, beforeOptimization);
BuildTreeSerializer::load(OptimizedBuildTree1_1, afterOptimization);
}
5 changes: 5 additions & 0 deletions elenasrc3/elena-tests/bt_optimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ namespace elena_lang
class BTOptimization1_1 : public testing::Test
{
protected:
MemoryDump btRules;

SyntaxTree syntaxTree;
BuildTree buildTree;

SyntaxNode declarationNode;
SyntaxNode exprNode;

BuildNode beforeOptimization;
BuildNode afterOptimization;

CompilerEnvironment env;

void SetUp() override;
Expand Down
22 changes: 19 additions & 3 deletions elenasrc3/elena-tests/bt_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
#include "pch.h"
#include "bt_optimization.h"

#include "bcwriter.h"

using namespace elena_lang;
TEST_F(BTOptimization1_1, BuildTapeTest) {
EXPECT_EQ(1, 1);
EXPECT_TRUE(true);
TEST_F(BTOptimization1_1, BuildTapeTest)
{
// Arrange
ByteCodeWriter::BuildTreeOptimizer buildTreeOptimizer;
MemoryReader reader(&btRules);
buildTreeOptimizer.load(reader);

BuildTree output;
BuildTreeWriter writer(output);
BuildTree::copyNode(writer, beforeOptimization, true);

// Act
buildTreeOptimizer.proceed(output.readRoot());

// Assess
bool matched = BuildTree::compare(output.readRoot(), afterOptimization, true);
EXPECT_TRUE(matched);
}
2 changes: 1 addition & 1 deletion elenasrc3/elena-tests/compiler_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST_F(BTOptimization1_1, CompilerTest)
writer.closeNode();

// Assess
bool matched = BuildTree::compare(buildTree.readRoot(), output.readRoot(), true);
bool matched = BuildTree::compare(beforeOptimization, output.readRoot(), true);
EXPECT_TRUE(matched);

freeobj(compiler);
Expand Down
5 changes: 5 additions & 0 deletions elenasrc3/elena-tests/elena-tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,21 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\common\files.h" />
<ClInclude Include="..\common\paths.h" />
<ClInclude Include="..\engine\serializer.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="tests_common.h" />
<ClInclude Include="bt_optimization.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\common\dump.cpp" />
<ClCompile Include="..\common\files.cpp" />
<ClCompile Include="..\common\paths.cpp" />
<ClCompile Include="..\common\ustring.cpp" />
<ClCompile Include="..\elc\compiler.cpp" />
<ClCompile Include="..\elc\compilerlogic.cpp" />
<ClCompile Include="..\engine\bcwriter.cpp" />
<ClCompile Include="..\engine\bytecode.cpp" />
<ClCompile Include="..\engine\module.cpp" />
<ClCompile Include="..\engine\scriptreader.cpp" />
Expand Down
Loading

0 comments on commit 8c987fd

Please sign in to comment.