Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F2730025
effects-versions.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Mar 13, 7:32 PM
Size
6 KB
Mime Type
text/x-c
Expires
Sun, Mar 15, 7:32 PM (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
243297
Attached To
rXR Xreate
effects-versions.cpp
View Options
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*
* Created on: Dec 16, 2016
* Author: pgess <v.melnychenko@xreate.org>
*/
#include "pass/versionspass.h"
#include "xreatemanager.h"
#include "gtest/gtest.h"
using namespace xreate;
using namespace xreate::versions;
TEST(Effects, syntax_versions_1){
XreateManager* man = XreateManager::prepare(R"Code(
test= function(a:: num):: num; entry {
x= b[8].
b = 5:: num.
x{1} = a:: num.
x{1} + a
}
)Code");
}
TEST(Effects, analysis_versions_1){
XreateManager* man = XreateManager::prepare(
R"Code(
test= function:: num; entry {
x{0}= 3:: int.
x{1} = x{0} + 1.
x{1}
}
)Code");
VersionsPass* pass = new VersionsPass(man);
pass->run();
VersionsGraph graph = pass->getResultGraph();
ASSERT_TRUE(graph.validate());
}
TEST(Effects, analysis_versions_2){
XreateManager* man = XreateManager::prepare(
R"Code(
test= function(a:: num):: num; entry {
x{0}= 3:: int.
b = {1, 2, x{0}}.
x{1} = b[2].
x{1} + a
}
)Code");
VersionsPass* pass = new VersionsPass(man);
pass->run();
VersionsGraph graph = pass->getResultGraph();
ASSERT_TRUE(graph.validate());
}
TEST(Effects, analysis_versions_2_1_fail){
XreateManager* man = XreateManager::prepare(
R"Code(
test= function(a:: num):: num; entry {
x{0}= 5:: int.
b = x{0}.
x{1} = 2.
b + x{1}
}
)Code");
VersionsPass* pass = new VersionsPass(man);
pass->run();
VersionsGraph graph = pass->getResultGraph();
graph.__debug_print(std::cout);
ASSERT_FALSE(graph.validate());
}
TEST(Effects, analysis_versions_2_2){
XreateManager* man = XreateManager::prepare(
R"Code(
test= function(a:: num):: num; entry {
x{0}= 5:: int.
b = intrinsic copy(x{0}).
x{1} = 2.
b + x{1}
}
)Code");
VersionsPass* pass = new VersionsPass(man);
pass->run();
VersionsGraph graph = pass->getResultGraph();
graph.__debug_print(std::cout);
ASSERT_TRUE(graph.validate());
}
TEST(Effects, analysis_versions_3){
XreateManager* man = XreateManager::prepare(
R"Code(
test= function:: num; entry {
x{0}= 3:: int.
a = x{0}:: int.
b = a :: int.
x{1} = b.
x{1}
}
)Code");
VersionsPass* pass = new VersionsPass(man);
pass->run();
VersionsGraph graph = pass->getResultGraph();
graph.__debug_print(std::cout);
ASSERT_TRUE(graph.validate());
std::cout << "========================\n";
graph.__debug_print(std::cout);
AttachmentsContainerDefault<std::list<Symbol>>* attachmentsDependency = graph.representAsAttachments();
CodeScope* scope = man->root->findFunction("test")->getEntryScope();
const std::list<Symbol>& dependenciesX1 = attachmentsDependency->get(Symbol{ScopedSymbol{1, 1}, scope});
ASSERT_EQ(3, dependenciesX1.size());
}
TEST(Effects, compilation_versions_1){
details::tier1::XreateManager* man = details::tier1::XreateManager::prepare(
R"Code(
test= function:: num; entry {
x{1} = b.
b = a :: int.
a = x{0}:: int.
x{0}= 3:: int.
x{1}
}
)Code");
man->analyse();
if (!man->isPassRegistered(PassId::VersionsPass)){
VersionsPass* pass = new VersionsPass(man);
pass->run();
pass->finish();
}
int (*body)() = (int (*)())man->run();
int answer = body();
ASSERT_EQ(3, answer);
}
TEST(Effects, compilation_versions_versionInit1){
details::tier1::XreateManager* man = details::tier1::XreateManager::prepare(
R"Code(
test= function:: num; entry {
x{0} = 3.
x{0}
}
)Code");
man->analyse();
if (!man->isPassRegistered(PassId::VersionsPass)){
VersionsPass* pass = new VersionsPass(man);
pass->run();
pass->finish();
}
int (*body)() = (int (*)())man->run();
int answer = body();
ASSERT_EQ(3, answer);
}
TEST(Effects, compilation_versions_versionNext1){
details::tier1::XreateManager* man = details::tier1::XreateManager::prepare(
R"Code(
test= function:: num; entry {
x{0} = 5.
x{1} = x{0} - 2.
x{1}
}
)Code");
man->analyse();
if (!man->isPassRegistered(PassId::VersionsPass)){
VersionsPass* pass = new VersionsPass(man);
pass->run();
pass->finish();
}
int (*body)() = (int (*)())man->run();
int answer = body();
ASSERT_EQ(3, answer);
}
TEST(Effects, compilation_versions_IntrinsicCopy1){
details::tier1::XreateManager* man = details::tier1::XreateManager::prepare(
R"Code(
test= function:: num; entry {
x{0} = 5.
b = intrinsic copy (x{0}).
x{1} = 2.
b - x{1}
}
)Code");
man->analyse();
if (!man->isPassRegistered(PassId::VersionsPass)){
VersionsPass* pass = new VersionsPass(man);
pass->run();
pass->finish();
}
int (*body)() = (int (*)())man->run();
int answer = body();
ASSERT_EQ(3, answer);
}
TEST(Effects, compilation_versions_varexchange){
details::tier1::XreateManager* man = details::tier1::XreateManager::prepare(
R"Code(
test= function:: num; entry {
a{0} = 3.
b{0} = 5.
tmp = intrinsic copy (a{0}).
a{1} = b{0}.
b{1} = tmp.
b{1}
}
)Code");
man->analyse();
if (!man->isPassRegistered(PassId::VersionsPass)){
VersionsPass* pass = new VersionsPass(man);
pass->run();
pass->finish();
}
int (*body)() = (int (*)())man->run();
int answer = body();
ASSERT_EQ(3, answer);
}
/*
TEST(Effects, analysis_versions_copy){
}
TEST(Effects, syntax_references1){
}
TEST(Effects, syntax_scope_versions1){
}
TEST(Effects, DynamicVersions_analysis){
}
*/
Event Timeline
Log In to Comment