Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F2718353
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 16, 1:16 AM
Size
28 KB
Mime Type
text/x-diff
Expires
Wed, Feb 18, 1:16 AM (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
237294
Attached To
rXR Xreate
View Options
diff --git a/config/default.json b/config/default.json
index f72b68e..28e521b 100644
--- a/config/default.json
+++ b/config/default.json
@@ -1,73 +1,73 @@
{
"containers": {
"id": {
"implementations": "impl_fulfill_cluster",
"clusters": "var_cluster",
"prototypes": "proto_cluster",
"linkedlist": "linkedlist"
},
"impl": {
"solid": "solid",
"onthefly": "on_the_fly"
}
},
"logging": {
"id": "logging"
},
"function-entry": "entry",
"clasp": {
"bindings" : {
"variable": "bind",
"function": "bind_func",
"scope": "bind_scope",
"function_demand" : "bind_function_demand",
"scope_decision": "bind_scope_decision"
},
"context" : {
"decisions":{
"dependent": "resolution_dependency"
},
},
"nonevalue": "nonevalue",
"ret": {
"symbol": "retv",
"tag": "ret"
}
},
"tests": {
"template": "containers",
"templates": {
"default": "*-",
"basic": "Basic.*",
"ast": "AST.*",
"cfa": "CFA.*",
"dfa": "DFA.*",
"compilation": "Compilation.*",
- "containers": "Containers.ListAsArray2-",
+ "containers": "Containers.Inference*-",
"diagnostic": "Diagnostic.*",
"serializer": "ExpressionSerializer.*",
"externc": "InterfaceExternC.*",
"context": "ExpressionSerializer.*:Context.*",
"types": "Types.*-",
"log": "Logging*",
"clang": "ClangAPI.*",
"skip": "SkipDetection*:Adhoc_Loop_SkipDetection.*",
"raw-xml": "libxml2*",
"xml": "Xml.*",
"installation": "Compilation.*:Sprint1.*",
"exploitation": "Exploitation.*",
"loops": "Loop.*",
"dsl": "Interpretation.*",
"adhocs": "Adhoc.*",
}
}
}
diff --git a/core/containers.lp b/core/containers.lp
index aa8e996..a8c53b8 100644
--- a/core/containers.lp
+++ b/core/containers.lp
@@ -1,40 +1,42 @@
-%1. Domain definitions:
- impl(solid; on_the_fly; linked_list).
+%3. Domain definitions:
+ implementation(solid; on_the_fly; linked_list).
op(seqaccess; randaccess).
relation(recommends; satisfied; unsupported).
relation_score(satisfied, 0).
relation_score(recommends, 1).
score(0..1).
-%2. Domain facts:
+%4. Domain facts:
relation_op(seqaccess, on_the_fly, recommends).
relation_op(randaccess, solid, recommends).
relation_op(randaccess, on_the_fly, unsupported).
- bind(X, impl(solid)):- bind(X, dfa_operator(list)).
- bind(X, impl(on_the_fly)):- bind(X, dfa_operator(list)).
+ bind(X, variant(l0_implementation(solid; on_the_fly))):- bind(X, dfa_operator(list)).
+ bind(X, variant(implementation(IMPL))):- bind(X, variant(l0_implementation(IMPL))); not bind(X, -variant(implementation(IMPL))).
bind(X, l0_op(seqaccess)) :- bind(X, dfa_operator(loop_fold)).
- bind(X, l0_op0(randaccess)) :- bind(X, dfa_operator(index)).
-
-%5. Manual input
-
-%2. Supplies
-
-%4. Best implemetation search:
- score(op(OP), IMPL, SCORE):- SCORE = #sum{SCORE1, SCORE1: relation_score(RL, SCORE1), relation_op(OP, IMPL, RL)}; op(OP); impl(IMPL); not relation_op(OP, IMPL, unsupported).
- {score(v(VAR), IMPL, SCORE)}:- score(op(OP), IMPL, SCORE); bind(VAR, op(OP)); bind(VAR, impl(IMPL)).
- :- 2{score(v(VAR), IMPL, SCORE): v(VAR)}.
-
- #maximize { SCORE, (VAR, SCORE): score(v(VAR), _, SCORE) }.
+ bind(X, l0_op(randaccess)) :- bind(X, dfa_operator(index)).
+ bind(X, op(OP)):- bind(X, l0_op(OP)); #count{OP1: bind(X, op(OP1)), OP1 <> OP}=0.
+
+% Transfunction inference
+ bind(Vactual, op(Op)) :-
+ bind(Vres, variant(implementation(..))) :-
+
+%5. Best implemetation search:
+ score(op(OP), IMPL, SCORE):- SCORE = #sum{SCORE1, SCORE1: relation_score(RL, SCORE1), relation_op(OP, IMPL, RL)}; op(OP); implementation(IMPL); not relation_op(OP, IMPL, unsupported).
+ score(v(VAR), IMPL, SCORE):- bind(VAR, implementation(IMPL)); score(op(OP), IMPL, SCORE); bind(VAR, op(OP)).
+ #maximize { SCORE, (VAR, SCORE): score(v(VAR), _, SCORE) }.
-%5. Output
- bind_decision(VAR, SUBJECT, RESOLUTION) :- SUBJECT=implementation; RESOLUTION=IMPL; score(v(VAR), IMPL, _).
+%6. Output
+ bind(VAR, implementation(IMPL)): bind(VAR, variant(implementation(IMPL))):- bind(VAR, op(OP)).
%1. DFA input
- v(a).
- bind(a, dfa_operator(list)).
- bind(a, dfa_operator(loop_fold)).
-
-
+ % bind(X, dfa_operator(...)
+
+%2. Manual input
+ % bind(V, variant(implementation(...))). -- add variant
+ % bind(V, -variant(implementation(...))). -- remove variant
+
+ % bind(V, op(..)). --set op demand
+ % bind(V, implementation(..)). --set decision
diff --git a/core/precompilation.lp b/core/precompilation.lp
deleted file mode 120000
index b21ab11..0000000
--- a/core/precompilation.lp
+++ /dev/null
@@ -1 +0,0 @@
-/private/prg/code/xreate/scripts/precompilation-1.lp
\ No newline at end of file
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 764079d..beae275 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -1,34 +1,34 @@
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -fprofile-arcs -ftest-coverage -O0")
set(CMAKE_BUILD_TYPE Debug)
# BUILD OPTIONS
#======================
set(XREATE_DEFINITIONS
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DWITH_THREADS=1
)
add_definitions(${XREATE_DEFINITIONS})
-add_compile_options(-Winvalid-pch -fPIC -std=c++11)
+add_compile_options(-Winvalid-pch -fPIC -std=c++14)
# XREATE
#======================
add_subdirectory(src)
# XREATE-TESTS
#======================
if (BUILD_XREATE_TESTS)
message ("Building xreate tests")
add_subdirectory(tests)
endif ()
# XREATE-SERVER
#======================
if (BUILD_XREATE_SERVER)
message ("Building xreate server")
add_subdirectory(../tools/execution-server execution-server)
endif ()
diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt
index fb7d51b..2200b02 100644
--- a/cpp/src/CMakeLists.txt
+++ b/cpp/src/CMakeLists.txt
@@ -1,216 +1,217 @@
cmake_minimum_required(VERSION 2.8.11)
project(xreate)
cmake_policy(SET CMP0022 NEW)
# LLVM
#======================
#FIND_PACKAGE (LLVM REQUIRED CONFIG PATHS PATH-TO-CMAKE-DIR NO_DEFAULT_PATH)
FIND_PACKAGE (LLVM REQUIRED)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-tools")
#include(PCH_GCC4_v2)
set(LLVM_VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR})
message ("LLVM LIB PATH:" ${LLVM_LIBRARY_DIRS})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
message ("MPATH:" ${CMAKE_MODULE_PATH})
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "INCLUDE DIR: ${LLVM_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(${LLVM_INCLUDE_DIRS})
message("LLVM defs: " ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(LLVM_LIBS core nativecodegen native executionengine mcjit support)
message("LLVM libs: " ${LLVM_LIBS})
# CLANG
#======================
set(CLANG_LIBS
${LLVM_LIBRARY_DIRS}/libclangCodeGen.so
${LLVM_LIBRARY_DIRS}/libclangASTMatchers.so
${LLVM_LIBRARY_DIRS}/libclangQuery.so
${LLVM_LIBRARY_DIRS}/libclangTooling.so
${LLVM_LIBRARY_DIRS}/libclangFrontend.so
${LLVM_LIBRARY_DIRS}/libclangSerialization.so
${LLVM_LIBRARY_DIRS}/libclangDriver.so
${LLVM_LIBRARY_DIRS}/libclangParse.so
${LLVM_LIBRARY_DIRS}/libclangSema.so
${LLVM_LIBRARY_DIRS}/libclangAnalysis.so
${LLVM_LIBRARY_DIRS}/libclangAST.so
${LLVM_LIBRARY_DIRS}/libclangEdit.so
${LLVM_LIBRARY_DIRS}/libclangLex.so
${LLVM_LIBRARY_DIRS}/libclangBasic.so
)
#find_package(Clang REQUIRED clangTooling libClang)
message(STATUS "CLANG LIBS: " ${CLANG_LIBS})
# POTASSCO
#======================
set(POTASSCO_PATH "/opt/potassco/clingo" CACHE PATH "Path to potassco sources")
set(POTASSCO_INCLUDE_PATH
${POTASSCO_PATH}/libgringo
${POTASSCO_PATH}/libclasp
${POTASSCO_PATH}/libclingo
${POTASSCO_PATH}/libprogram_opts
${POTASSCO_PATH}/liblp
)
INCLUDE_DIRECTORIES(${POTASSCO_INCLUDE_PATH})
set (LIBCLASP_PATH ${POTASSCO_PATH}/build/debug)
set(LIBCLASP_LIBS
clingo
clasp
gringo
program_opts
reify
lp
)
message(STATUS "CLASP LIBS: " ${LIBCLASP_LIBS})
link_directories(${LIBCLASP_PATH})
# OTHER DEPENDENCIES
#===========================
set(JEAYESON_INCLUDE_PATH
${CMAKE_HOME_DIRECTORY}/../vendors/jeayeson/include/
)
INCLUDE_DIRECTORIES(${JEAYESON_INCLUDE_PATH})
# COCO
#===========================
set(COCO_PATH ${CMAKE_HOME_DIRECTORY}/../coco/)
set(COCO_SOURCE_FILES
${COCO_PATH}/Parser.cpp
${COCO_PATH}/Scanner.cpp)
INCLUDE_DIRECTORIES(${COCO_PATH})
add_custom_command(OUTPUT ${COCO_SOURCE_FILES}
COMMAND ${COCO_PATH}/gen-grammar
WORKING_DIRECTORY ${COCO_PATH}
MAIN_DEPENDENCY ${COCO_PATH}/xreate.ATG
)
message(STATUS "COCO GRAMMAR BUILD STATUS:" ${COCO_OUTPUT})
# XREATE
#======================
set(SOURCE_FILES
+ clasplayer.cpp
pass/compilepass.cpp
pass/interpretationpass.cpp
compilation/targetinterpretation.cpp
ast.cpp
ExternLayer.cpp
attachments.cpp
analysis/cfagraph.cpp
analysis/dfagraph.cpp
analysis/aux.cpp
compilation/containers.cpp
compilation/advanced.cpp
compilation/transformations.cpp
analysis/DominatorsTreeAnalysisProvider.cpp
- clasplayer.cpp
+
compilation/latecontextcompiler2.cpp
query/context.cpp
#compilation/latecontextcompiler.cpp
serialization/expressionserializer.cpp
serialization/expressionserializer2.cpp
llvmlayer.cpp
utils.cpp
passmanager.cpp
pass/abstractpass.cpp pass/dfapass.cpp
pass/cfapass.cpp
pass/loggerpass.cpp
pass/adhocpass.cpp
query/containers.cpp
contextrule.cpp
#query/ptrvalid.cpp
#pass/rulespass.cpp #
)
set(XREATE_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/
)
INCLUDE_DIRECTORIES(${XREATE_INCLUDE_DIRS})
set(XREATE_PRIVATE_INCLUDE_DIRS
${XREATE_INCLUDE_DIRS}
${COCO_PATH}
${JEAYESON_INCLUDE_PATH}
${LLVM_INCLUDE_DIRS}
${POTASSCO_INCLUDE_PATH}
)
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${COCO_SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${LIBCLASP_LIBS})
target_include_directories(${PROJECT_NAME} INTERFACE
${XREATE_INCLUDE_DIRS}
${COCO_PATH}
${JEAYESON_INCLUDE_PATH}
${LLVM_INCLUDE_DIRS}
${POTASSCO_INCLUDE_PATH}
)
get_directory_property(DEFINITIONS_ALL DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS)
message("definitions all: " ${DEFINITIONS_ALL})
target_compile_definitions(${PROJECT_NAME} INTERFACE ${DEFINITIONS_ALL})
get_directory_property(COMPILATION_OPTIONS_ALL DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS)
message("compilations all: " ${COMPILATION_OPTIONS_ALL})
target_compile_options(${PROJECT_NAME} INTERFACE ${COMPILATION_OPTIONS_ALL})
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY
INTERFACE_LINK_LIBRARIES ${LLVM_LIBS} ${CLANG_LIBS} tbb
)
#set (LINK_INTERFACE_LIBRARIES "")
# FUNCTION(PREPEND var prefix)
# SET(listVar "")
# FOREACH(f ${ARGN})
# LIST(APPEND listVar "${prefix}/${f}")
# ENDFOREACH(f)
# SET(${var} "${listVar}" PARENT_SCOPE)
# ENDFUNCTION(PREPEND)
#set(COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "-j4")
#cotire(xreate)
# MACRO (ADD_PCH_RULE _header_filename _src_list)
# SET(_gch_filename "${_header_filename}.gch")
# LIST(APPEND ${_src_list} ${_gch_filename})
# SET (_args ${CMAKE_CXX_FLAGS})
# LIST(APPEND _args -c ${_header_filename} -o ${_gch_filename})
# GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES)
# foreach (_inc ${DIRINC})
# LIST(APPEND _args "-I" ${_inc})
# endforeach(_inc ${DIRINC})
# SEPARATE_ARGUMENTS(_args)
# add_custom_command(OUTPUT ${_gch_filename}
# COMMAND rm -f ${_gch_filename}
# COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${_args}
# DEPENDS ${_header_filename})
# ENDMACRO(ADD_PCH_RULE _header_filename _src_list)
# ADD_PCH_RULE (${CMAKE_HOME_DIRECTORY}/src/ast.h SOURCE_FILES)
# ADD_PCH_RULE (${CMAKE_HOME_DIRECTORY}/src/llvmlayer.h SOURCE_FILES)
# ADD_PCH_RULE (${CMAKE_HOME_DIRECTORY}/src/clasplayer.h SOURCE_FILES)
# ADD_PCH_RULE (${CMAKE_HOME_DIRECTORY}/src/pass/abstractpass.h SOURCE_FILES)
diff --git a/cpp/src/clasplayer.cpp b/cpp/src/clasplayer.cpp
index 59eb970..09b2026 100644
--- a/cpp/src/clasplayer.cpp
+++ b/cpp/src/clasplayer.cpp
@@ -1,311 +1,313 @@
#include "clasplayer.h"
#include <iostream>
#include "utils.h"
#include <boost/format.hpp>
#include <boost/algorithm/string/join.hpp>
#include <gringo/scripts.hh>
#include "analysis/aux.h"
#include "analysis/DominatorsTreeAnalysisProvider.h"
#include "analysis/cfagraph.h"
#include "analysis/dfagraph.h"
using namespace std;
//TODO escape identifiers started from upper case symbol
namespace xreate {
void
ClaspLayer::printWarnings(std::ostream& out)
{
const std::string warningTag = "warning";
auto warningsRange = __model.equal_range(warningTag);
for (auto warning=warningsRange.first; warning!= warningsRange.second; ++warning) {
unsigned int warningId;
Gringo::Symbol params;
std::tie(warningId, params) = parse<unsigned int, Gringo::Symbol>(warning->second);
cout << "Warning: " << __warnings.at(warningId) << " ";
params.print(out);
out<<params;
}
}
bool
ClaspLayer::handleSolution(Gringo::Model const &model) {
std::list<std::string> warnings;
cout << "Model: " << endl;
const string& atomBindVar = Config::get("clasp.bindings.variable");
const string& atomBindFunc = Config::get("clasp.bindings.function");
const string& atomBindScope = Config::get("clasp.bindings.scope");
for (Gringo::Symbol atom : model.atoms(clingo_show_type_atoms)) {
atom.print(cout);
cout <<" | "<< endl;
string atomName(atom.name().c_str());
if (atomName == atomBindVar || atomName == atomBindFunc || atomName == atomBindScope){
string name = std::get<1>(parse<Gringo::Symbol, Gringo::Symbol>(atom)).name().c_str();
__model.emplace(move(name), move(atom));
}
__model.emplace(atomName, move(atom));
}
return true;
}
void
ClaspLayer::setCFAData(xreate::analysis::CFAGraph* graph) {
dataCFA.reset(graph);
}
void
ClaspLayer::setDFAData(xreate::analysis::DFAGraph* graph){
dataDFA.reset(graph);
}
void
ClaspLayer::addRuleWarning(const RuleWarning &rule) {
//__partGeneral << rule << endl;
list<string> domains;
boost::format formatDef("%1%(%2%)");
std::transform(rule.__args.begin(), rule.__args.end(), std::inserter(domains, domains.begin()),
[&formatDef](const std::pair<std::string, DomainAnnotation> &argument) {
string domain;
switch (argument.second) {
case DomainAnnotation::FUNCTION:
domain = "function";
break;
case DomainAnnotation::VARIABLE:
domain = "variable";
break;
}
return boost::str(formatDef % domain % argument.first);
});
list<string> vars;
std::transform(rule.__args.begin(), rule.__args.end(), std::inserter(vars, vars.begin()),
[](const std::pair<std::string, DomainAnnotation> &argument) {
return argument.first.c_str();
});
list<list<string>> guardsRaw;
std::transform(rule.__guards.begin(), rule.__guards.end(), std::inserter(guardsRaw, guardsRaw.begin()),
[this](const Expression &guard) {
return xreate::analysis::compile(guard);
});
const list<string>& guards = xreate::analysis::multiplyLists(std::move(guardsRaw));
list<string> &&branches = xreate::analysis::compileNeg(rule.__condition);
boost::format formatWarning("warning(%1%, (%2%)):- %3%, %4%, %5%.");
for (const string &guardsJoined: guards)
for (const string &branch: branches) {
unsigned int hook = registerWarning(string(rule.__message));
__partGeneral << formatWarning
%(hook)
%(boost::algorithm::join(vars, ", "))
%(branch)
%(guardsJoined)
%(boost::algorithm::join(domains, ", "))
<<endl;
}
}
unsigned int
ClaspLayer::registerWarning(std::string &&message) {
static int warningId = 0;
__warnings.emplace(warningId, message);
return warningId++;;
}
void
ClaspLayer::involveImports() {
ostream &out = __partGeneral;
for (string fn: ast->__rawImports)
{
std::ifstream file(fn);
if (!file) continue;
while(!file.eof()){
string line;
std::getline(file, line);
out << line << endl;
}
}
}
void
ClaspLayer::addRawScript(std::string&& script){
__partGeneral << script;
}
void
ClaspLayer::run() {
involveImports();
if (this->dataDFA){
this->dataDFA->print(__partGeneral);
}
if (this->dataCFA){
this->dataCFA->print(__partGeneral);
}
DominatorsTreeAnalysisProvider providerDominators;
providerDominators.run(this);
providerDominators.print(__partGeneral);
ostringstream program;
program << __partTags.str() << __partGeneral.str();
cout << FYEL(program.str()) << endl;
std::vector<char const *> args{"clingo", nullptr};
DefaultGringoModule moduleDefault;
Gringo::Scripts scriptsDefault(moduleDefault);
ClingoLib ctl(scriptsDefault, 0, args.data(), {}, 0);
ctl.add("base", {}, program.str());
ctl.ground({{"base", {}}}, nullptr);
// solve
Gringo::SolveResult result = ctl.solve([this](Gringo::Model const &model) {
this->handleSolution(model);
return true;
}, {});
if (result.satisfiable() == Gringo::SolveResult::Satisfiable) {
cout << FGRN("SUCCESSFULLY") << endl;
} else {
cout << FRED("UNSUCCESSFULLY") << endl;
}
// invoke all query plugins to process clasp data
for (auto q: __queries)
{
q.second->init(this);
}
}
bool
ClaspLayer::checkScript(std::string&& script, std::string&& atomCheckSuccess){
//init
std::vector<char const *> args{"clingo", nullptr};
DefaultGringoModule moduleDefault;
Gringo::Scripts scriptsDefault(moduleDefault);
ClingoLib ctl(scriptsDefault, 0, args.data(), {}, 0);
- ctl.add("base", {}, program.str());
+ ctl.add("base", {}, script);
ctl.ground({{"base", {}}}, nullptr);
bool flagCheck = false;
- Gringo::SolveResult result = ctl.solve([this, &flagCheck, const &atomCheckSuccess](Gringo::Model const &model) {
+ Gringo::SolveResult result = ctl.solve([this, &flagCheck, &atomCheckSuccess](Gringo::Model const &model) {
for (Gringo::Symbol atom : model.atoms(clingo_show_type_atoms)) {
-
- string atomName(atom.name().c_str());
- if (atomName == atomCheckSuccess){
- flagCheck = true;
- break;
- }
+ atom.print(cout);
+ cout << endl;
+
+ string atomName(atom.name().c_str());
+ if (atomName == atomCheckSuccess){
+ flagCheck = true;
+ break;
+ }}
return true;
- }}, {});
+ }, {});
if (!result.satisfiable()){
return false;
}
- return flagCheck
+ return flagCheck;
}
ClaspLayer::ClaspLayer() {
}
ClaspLayer::ModelFragment
ClaspLayer::query(const std::string& atom)
{
if (! __model.count(atom)){
return boost::none;
}
return ModelFragment(__model.equal_range(atom));
}
ScopePacked
ClaspLayer::pack(CodeScope* const scope) {
auto pos = __indexScopes.emplace(scope, __indexScopes.size());
if (pos.second)
__registryScopes.push_back(scope);
return pos.first->second;
}
size_t
ClaspLayer::getScopesCount() const{
return __registryScopes.size();
}
SymbolPacked
ClaspLayer::pack(const Symbol& symbol, std::string hintSymbolName)
{
SymbolPacked result;
result.scope = pack(symbol.scope);
result.identifier = symbol.identifier;
__indexSymbolNameHints.emplace(result, hintSymbolName);
return result;
}
Symbol
ClaspLayer::unpack(const SymbolPacked& symbol)
{
return Symbol{symbol.identifier, __registryScopes[symbol.scope]};
};
std::string
ClaspLayer::getHintForPackedSymbol(const SymbolPacked& symbol){
if (!symbol.categoryTransient) {
auto result = __indexSymbolNameHints.find(symbol);
return (result == __indexSymbolNameHints.end())? "" : result->second;
} else {
return "anonym(" + to_string(symbol.identifier) + ")";
}
}
bool operator==(const SymbolPacked& s1, const SymbolPacked& s2)
{
return s1.identifier == s2.identifier && s1.scope == s2.scope;
}
bool operator<(const SymbolPacked& s1, const SymbolPacked& s2)
{
return s1.scope < s2.scope || (s1.scope == s2.scope && s1.identifier < s2.identifier);
}
IQuery*
ClaspLayer::registerQuery(IQuery *query, const QueryId& id) {
return __queries.emplace(id, query).first->second;
}
IQuery*
ClaspLayer::getQuery(const QueryId& id){
assert(__queries.count(id) && "Undefined query");
return __queries.at(id);
}
}
diff --git a/cpp/tests/containers.cpp b/cpp/tests/containers.cpp
index d5cdf0e..ab41c1c 100644
--- a/cpp/tests/containers.cpp
+++ b/cpp/tests/containers.cpp
@@ -1,124 +1,219 @@
/*
* containers.cpp
*
* Created on: Jun 9, 2015
* Author: pgess
*/
#include "passmanager.h"
#include "query/containers.h"
+#include "analysis/dfagraph.h"
+#include "analysis/cfagraph.h"
#include "Parser.h"
#include "gtest/gtest.h"
using namespace std;
using namespace xreate;
using namespace containers;
TEST(Containers, ListAsArray){
PassManager* man = PassManager::prepareForCode(
R"Code(
main = function(x:: int):: int;entry {
a = [1, 2, 3]:: [int].
a[x]
}
)Code" );
void* mainPtr = man->run();
int (*main)(int) = (int (*)(int))mainPtr;
ASSERT_EQ(2, main(1));
delete man;
}
TEST(Containers, ListAsArray2){
PassManager* man = PassManager::prepareForCode(
R"Code(
main = function:: int;entry {
a= [1, 2, 3]:: [int].
b= loop map(a->el:: int):: [int]{
2 * el
}.
sum = loop fold(b->el:: int, 0->acc):: int {
acc + el
}.
sum
}
)Code" );
void* mainPtr = man->run();
int (*main)() = (int (*)())mainPtr;
ASSERT_EQ(0, main());
delete man;
}
+TEST(Containers, InferenceManualControlSupply_add){
+ string program =
+R"SCRIPT(
+ #include "core/containers.lp".
+
+ %1. DFA input
+ v(a).
+ bind(a, dfa_operator(loop_fold)).
+
+ %2. Manual input
+ bind(a, variant(implementation(on_the_fly))).
+
+ success :- bind(a, implementation(on_the_fly)).
+
+)SCRIPT";
+
+ ClaspLayer* solver = new ClaspLayer();
+ ASSERT_TRUE(solver->checkScript(move(program), "success"));
+
+ delete solver;
+}
+
+TEST(Containers, InferenceManualControlSupply_delete){
+ string program =
+R"SCRIPT(
+
+ #include "core/containers.lp".
+
+ %1. DFA input
+ v(a).
+ bind(a, dfa_operator(loop_fold)).
+ bind(a, dfa_operator(list)).
+
+ %2. Manual input
+ bind(a, -variant(implementation(on_the_fly))).
+
+ success :- bind(a, implementation(solid)).
+
+)SCRIPT";
+
+ ClaspLayer* solver = new ClaspLayer();
+ ASSERT_TRUE(solver->checkScript(move(program), "success"));
+
+ delete solver;
+}
+
+TEST(Containers, InferenceManualControlDemand_set){
+ string program =
+R"SCRIPT(
+
+ #include "core/containers.lp".
+
+ %1. DFA input
+ v(a).
+ bind(a, dfa_operator(loop_fold)).
+ bind(a, dfa_operator(list)).
+
+ %2. Manual input
+ bind(a, op(randaccess)).
+
+ success :- bind(a, implementation(solid)).
+
+)SCRIPT";
+
+ ClaspLayer* solver = new ClaspLayer();
+ ASSERT_TRUE(solver->checkScript(move(program), "success"));
+
+ delete solver;
+}
+
+TEST(Containers, InferenceManualControlImpl_set){
+ string program =
+R"SCRIPT(
+
+ #include "core/containers.lp".
+
+ %1. DFA input
+ v(a).
+ bind(a, dfa_operator(loop_fold)).
+ bind(a, dfa_operator(list)).
+
+ %2. Manual input
+ bind(a, implementation(solid)).
+
+ success :- bind(a, implementation(solid)).
+
+)SCRIPT";
+
+ ClaspLayer* solver = new ClaspLayer();
+ ASSERT_TRUE(solver->checkScript(move(program), "success"));
+
+ delete solver;
+}
//TEST(){
// function test1(i:: num):: num{
// a = [1..10]:: [num].
//
// b = loop map(a->el:: num):: [num]{
// a * a
// }
//
// b[i]
// }
//
// function test2(){
// a= [1..10]:: [num].
//
// b = loop map(a->el:: num):: [num]{
// a * a
// }
//
// c = loop fold(b->el, 0->sum>)::num {
// sum + el
// }
//
// c
// }
//}
TEST(Containers, ContanierLinkedList1){
FILE* input = fopen("scripts/testspass/Containers_Implementation_LinkedList1.xreate","r");
assert(input != nullptr);
Scanner scanner(input);
Parser parser(&scanner);
parser.Parse();
AST& ast = parser.root;
CodeScope* body = ast.findFunction("test")->getEntryScope();
Symbol symb_chilrenRaw = body->findSymbol("childrenRaw");
containers::ImplementationLinkedList iLL(symb_chilrenRaw);
ASSERT_EQ(true, static_cast<bool>(iLL));
ASSERT_EQ("next", iLL.fieldPointer);
Implementation impl = Implementation::create(symb_chilrenRaw);
ASSERT_NO_FATAL_FAILURE(impl.extract<ON_THE_FLY>());
ImplementationRec<ON_THE_FLY> recOnthefly = impl.extract<ON_THE_FLY>();
ASSERT_EQ(symb_chilrenRaw, recOnthefly.source);
}
TEST(Containers, Implementation_LinkedListFull){
FILE* input = fopen("scripts/testspass/Containers_Implementation_LinkedList1.xreate","r");
assert(input != nullptr);
std::unique_ptr<PassManager> program(PassManager::prepareForCode(input));
void* mainPtr = program->run();
int (*main)() = (int (*)())(intptr_t)mainPtr;
int answer = main();
ASSERT_EQ(17, answer);
fclose(input);
}
diff --git a/scripts/containers-set-intersection.xreate b/scripts/containers-set-intersection.xreate
deleted file mode 100644
index 22b378d..0000000
--- a/scripts/containers-set-intersection.xreate
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * intersection of two sets
- */
-
-intersection = function(X: [a], sorted; Y: [b], sorted)
-{
- loop map (X -> x: a | exists(Y, x))
- {x;};
-}
-
-
\ No newline at end of file
diff --git a/scripts/precompilation-1.lp b/scripts/precompilation-1.lp
deleted file mode 100644
index 1c14007..0000000
--- a/scripts/precompilation-1.lp
+++ /dev/null
@@ -1,11 +0,0 @@
-%%DATA EMBEDDING:
- %bind(S, static(Data)):- Data= ref(_); bind(SymbolFrom, static(Data)); dfa_connection(S, SymbolFrom, _).
- %bind(S, static(ref(Root))):- Data= data(_); bind(Root, static(Data)); dfa_connection(S, Root, _).
-
-%% SCHEME:
- % bind(S, static).
- % dfa_static(S, data(Data))
- % dfa_static(S, ref(RootSymbol))
-
-bind(S2, static) :- bind(S1, static): dfa_connection(S2, S1, _).
-
Event Timeline
Log In to Comment