diff --git a/engine/ast.py b/engine/ast.py
index 651fa26..ddcfe29 100644
--- a/engine/ast.py
+++ b/engine/ast.py
@@ -1,4 +1,3 @@
-from operator import index
from engine.utils import base62uuid
from copy import copy
# replace column info with this later.
@@ -203,8 +202,11 @@ class Context:
using namespace types;
'''
+ LOG_INFO = 'INFO'
+ LOG_ERROR = 'ERROR'
+ LOG_SILENT = 'SILENT'
def __init__(self):
- self.tables:List[TableInfo] = []
+ self.tables:list[TableInfo] = []
self.tables_byname = dict()
self.ccols_byname = dict()
self.gc_name = 'gc_' + base62uuid(4)
@@ -212,6 +214,8 @@ class Context:
self.udf_map = dict()
self.headers = set(['\"./server/libaquery.h\"'])
self.finalized = False
+ self.log_level = Context.LOG_SILENT
+ self.print = print
# read header
self.ccode = ''
self.ccodelet = ''
@@ -277,6 +281,16 @@ class Context:
self.emit(str_scan)
self.scans.remove(scan)
+ def Info(self, msg):
+ if self.log_level.upper() == Context.LOG_INFO:
+ self.print(msg)
+ def Error(self, msg):
+ if self.log_level.upper() == Context.LOG_ERROR:
+ self.print(msg)
+ else:
+ self.Info(self, msg)
+
+
def finalize(self):
if not self.finalized:
headers = ''
diff --git a/engine/ddl.py b/engine/ddl.py
index f1511db..1d5a6da 100644
--- a/engine/ddl.py
+++ b/engine/ddl.py
@@ -28,7 +28,7 @@ class create_table(ast_node):
# create an empty new table
if self.cexprs is None:
for c in tbl.columns:
- self.emit(f"{c.cxt_name}.init({c.name});")
+ self.emit(f'{c.cxt_name}.init("{c.name}");')
# create an output table
else:
# 1 to 1 lineage.
@@ -40,7 +40,7 @@ class create_table(ast_node):
else:
self.lineage = None
for i, c in enumerate(tbl.columns):
- self.emit(f"{c.cxt_name}.init({c.name});")
+ self.emit(f'{c.cxt_name}.init("{c.name}");')
self.emit(f"{c.cxt_name} = {self.cexprs[i](self.lineage)};")
self.lineage = None
self.parent.assumptions = None
@@ -54,7 +54,7 @@ class create_table(ast_node):
scanner.add(f"{lineage_var}.emplace_back({counter_var}++);", "front")
self.lineage = f"{lineage_var}.rid"
for i, c in enumerate(tbl.columns):
- scanner.add(f"{c.cxt_name}.init({c.name});", "init")
+ scanner.add(f'{c.cxt_name}.init("{c.name}");', "init")
scanner.add(f"{c.cxt_name} = {self.cexprs[i](scanner.it_ver)};")
class insert(ast_node):
diff --git a/engine/expr.py b/engine/expr.py
index 71d14f4..7a8572f 100644
--- a/engine/expr.py
+++ b/engine/expr.py
@@ -100,7 +100,7 @@ class expr(ast_node):
elif key in self.unary_ops:
self._expr += f'{self.unary_ops[key]}({expr(self, val)._expr})'
else:
- print(f'Undefined expr: {key}{val}')
+ self.context.Error(f'Undefined expr: {key}{val}')
if key in self.coumpound_generating_ops and not self.is_compound:
self.is_compound = True
diff --git a/engine/projection.py b/engine/projection.py
index 11c613a..4bf2a20 100644
--- a/engine/projection.py
+++ b/engine/projection.py
@@ -24,7 +24,7 @@ class projection(ast_node):
def produce(self, node):
p = node['select']
self.projections = p if type(p) is list else [p]
- print(node)
+ self.context.Info(node)
def spawn(self, node):
self.datasource = None
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..a6260f2
--- /dev/null
+++ b/index.html
@@ -0,0 +1,19 @@
+
Google
\ No newline at end of file
diff --git a/msc-plugin/msc-plugin.vcxproj b/msc-plugin/msc-plugin.vcxproj
index 7194878..fd13c4f 100644
--- a/msc-plugin/msc-plugin.vcxproj
+++ b/msc-plugin/msc-plugin.vcxproj
@@ -47,7 +47,7 @@
true
v143
Unicode
- true
+ false
false
diff --git a/msvs-py/msvs-py.pyproj b/msvs-py/msvs-py.pyproj
index b2fdde2..4230f8c 100644
--- a/msvs-py/msvs-py.pyproj
+++ b/msvs-py/msvs-py.pyproj
@@ -4,13 +4,13 @@
2.0
ccc243f5-663e-45b7-a6de-b2468c58b3a7
.
-
-
+ ..\prompt.py
..\msvs-py
- .
+ ..
.
msvs-py
msvs-py
+ False
true
diff --git a/out.cpp b/out.cpp
index f282ad1..dc3842e 100644
--- a/out.cpp
+++ b/out.cpp
@@ -1,79 +1,65 @@
-#include "./server/libaquery.h"
+#include
#include "./server/aggregations.h"
+#include "csv.h"
+#include "./server/libaquery.h"
+#include "./server/hasher.h"
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std;
using namespace types;
- auto stocks = new TableInfo("stocks", 2);
-cxt->tables.insert({"stocks", stocks});
-auto& stocks_timestamp = *(ColRef *)(&stocks->colrefs[0]);
-auto& stocks_price = *(ColRef *)(&stocks->colrefs[1]);
-stocks_timestamp.init();
-stocks_price.init();
-stocks_timestamp.emplace_back(1);
-stocks_price.emplace_back(15);
-stocks_timestamp.emplace_back(2);
-stocks_price.emplace_back(19);
-stocks_timestamp.emplace_back(3);
-stocks_price.emplace_back(16);
-stocks_timestamp.emplace_back(4);
-stocks_price.emplace_back(17);
-stocks_timestamp.emplace_back(5);
-stocks_price.emplace_back(15);
-stocks_timestamp.emplace_back(6);
-stocks_price.emplace_back(13);
-stocks_timestamp.emplace_back(7);
-stocks_price.emplace_back(5);
-stocks_timestamp.emplace_back(8);
-stocks_price.emplace_back(8);
-stocks_timestamp.emplace_back(9);
-stocks_price.emplace_back(7);
-stocks_timestamp.emplace_back(10);
-stocks_price.emplace_back(13);
-stocks_timestamp.emplace_back(11);
-stocks_price.emplace_back(11);
-stocks_timestamp.emplace_back(12);
-stocks_price.emplace_back(14);
-stocks_timestamp.emplace_back(13);
-stocks_price.emplace_back(10);
-stocks_timestamp.emplace_back(14);
-stocks_price.emplace_back(5);
-stocks_timestamp.emplace_back(15);
-stocks_price.emplace_back(2);
-stocks_timestamp.emplace_back(16);
-stocks_price.emplace_back(5);
-auto out_oMxe = new TableInfo>>("out_oMxe", 1);
-cxt->tables.insert({"out_oMxe", out_oMxe});
-auto& out_oMxe_maxstockspriceminstockstimestamp = *(ColRef>> *)(&out_oMxe->colrefs[0]);
-out_oMxe_maxstockspriceminstockstimestamp.init();
-out_oMxe_maxstockspriceminstockstimestamp = max((stocks_price-min(stocks_timestamp)));
-print(*out_oMxe);
-auto out_2ZWg = new TableInfo>>("out_2ZWg", 1);
-cxt->tables.insert({"out_2ZWg", out_2ZWg});
-auto& out_2ZWg_maxstockspriceminsstocksprice = *(ColRef>> *)(&out_2ZWg->colrefs[0]);
-out_2ZWg_maxstockspriceminsstocksprice.init();
-out_2ZWg_maxstockspriceminsstocksprice = max((stocks_price-mins(stocks_price)));
-print(*out_2ZWg);
-const auto& tmp_sz_B19sAY = stocks_timestamp.size;
-auto out_JZsz = new TableInfo>,value_type>>("out_JZsz", 2);
-cxt->tables.insert({"out_JZsz", out_JZsz});
-auto& out_JZsz_price = *(ColRef>> *)(&out_JZsz->colrefs[0]);
-auto& out_JZsz_timestamp = *(ColRef>> *)(&out_JZsz->colrefs[1]);
-out_JZsz_price.init();
-out_JZsz_timestamp.init();
-for (uint32_t i3D = 0; i3D < tmp_sz_B19sAY; ++i3D){
-if ((((stocks_price[i3D]-stocks_timestamp[i3D])>=1)&&!(((stocks_price[i3D]*stocks_timestamp[i3D])<100)))) {
-out_JZsz_price = stocks_price[i3D];
-out_JZsz_timestamp = stocks_timestamp[i3D];
-}}
-print(*out_JZsz);
-auto out_2Fm0 = new TableInfo>>("out_2Fm0", 1);
-cxt->tables.insert({"out_2Fm0", out_2Fm0});
-auto& out_2Fm0_maxstockspriceminsstocksprice = *(ColRef>> *)(&out_2Fm0->colrefs[0]);
-auto order_5qqTLa = stocks->order_by<-1>();
-out_2Fm0_maxstockspriceminsstocksprice.init();
-out_2Fm0_maxstockspriceminsstocksprice = max((stocks_price[*order_5qqTLa]-mins(stocks_price[*order_5qqTLa])));
-print(*out_2Fm0);
+ auto sale = new TableInfo("sale", 2);
+cxt->tables.insert({"sale", sale});
+auto& sale_Month = *(ColRef *)(&sale->colrefs[0]);
+auto& sale_sales = *(ColRef *)(&sale->colrefs[1]);
+sale_Month.init("Month");
+sale_sales.init("sales");
+io::CSVReader<2> csv_reader_6ojNrU("moving_avg.csv");
+csv_reader_6ojNrU.read_header(io::ignore_extra_column, "Month","sales");
+int tmp_30abZdE5;
+int tmp_zx6KcpzH;
+while(csv_reader_6ojNrU.read_row(tmp_30abZdE5,tmp_zx6KcpzH)) {
+
+sale_Month.emplace_back(tmp_30abZdE5);
+sale_sales.emplace_back(tmp_zx6KcpzH);
+}
+auto out_4oKV = new TableInfo>,value_type>>("out_4oKV", 2);
+cxt->tables.insert({"out_4oKV", out_4oKV});
+auto& out_4oKV_Month = *(ColRef>> *)(&out_4oKV->colrefs[0]);
+auto& out_4oKV_avgw3salesales = *(ColRef>> *)(&out_4oKV->colrefs[1]);
+auto order_3t9jQY = sale->order_by<0>();
+out_4oKV_Month.init("Month");
+out_4oKV_Month = sale_Month[*order_3t9jQY];
+out_4oKV_avgw3salesales.init("avgw3salesales");
+out_4oKV_avgw3salesales = avgw(3,sale_sales[*order_3t9jQY]);
+print(*out_4oKV);
+FILE* fp_d7p2ph = fopen("moving_avg_output.csv", "w");
+out_4oKV->printall(";", "\n", nullptr, fp_d7p2ph);
+fclose(fp_d7p2ph);
+typedef record record_typexsfbsFs;
+unordered_map, transTypes> g5N8IBNq;
+for (uint32_t i4w = 0; i4w < sale_sales.size; ++i4w){
+g5N8IBNq[forward_as_tuple(sale_sales[i4w])].emplace_back(i4w);
+}
+auto out_7JGJ = new TableInfo,value_type>>("out_7JGJ", 2);
+cxt->tables.insert({"out_7JGJ", out_7JGJ});
+auto& out_7JGJ_Month = *(ColRef> *)(&out_7JGJ->colrefs[0]);
+auto& out_7JGJ_minw2salesales = *(ColRef>> *)(&out_7JGJ->colrefs[1]);
+out_7JGJ_Month.init("Month");
+out_7JGJ_minw2salesales.init("minw2salesales");
+for(auto& iVb : g5N8IBNq) {
+auto &val_6xjJXey = iVb.second;
+sale->order_by<-1>(&val_6xjJXey);
+}
+for(auto& i5G : g5N8IBNq) {
+auto &key_1e9JJOf = i5G.first;
+auto &val_6g6wlkk = i5G.second;
+out_7JGJ_Month.emplace_back(sale_Month[val_6g6wlkk]);
+out_7JGJ_minw2salesales.emplace_back(minw(2,get<0>(key_1e9JJOf)));
+}
+print(*out_7JGJ);
+FILE* fp_1yhzJM = fopen("flatten.csv", "w");
+out_7JGJ->printall(",", "\n", nullptr, fp_1yhzJM);
+fclose(fp_1yhzJM);
return 0;
}
\ No newline at end of file
diff --git a/prompt.py b/prompt.py
index 67741d1..057e60c 100644
--- a/prompt.py
+++ b/prompt.py
@@ -92,7 +92,7 @@ print(res)
# os.remove(shm)
# exit()
keep = False
-cxt = None
+cxt = engine.initialize()
while test_parser:
try:
if server.poll() is not None:
@@ -107,23 +107,30 @@ while test_parser:
engine.generate(s, cxt)
else:
engine.generate(stmts_stmts, cxt)
- print(cxt.ccode)
+ cxt.Info(cxt.ccode)
with open('out.cpp', 'wb') as outfile:
outfile.write((cxt.finalize()).encode('utf-8'))
if subprocess.call(['make', 'snippet']) == 0:
mm.seek(0,os.SEEK_SET)
mm.write(b'\x01\x01')
continue
+ elif q.startswith('log'):
+ qs = re.split(' |\t', q)
+ if len(qs) > 1:
+ cxt.log_level = qs[1]
+ else:
+ cxt.print(cxt.log_level)
+ continue
elif q == 'k':
subprocess.call(basecmd)
continue
elif q == 'print':
- print(stmts)
+ cxt.print(stmts)
continue
elif q == 'keep':
keep = not keep
continue
- elif q=='format' or q == 'fmt':
+ elif q == 'format' or q == 'fmt':
subprocess.call(['clang-format', 'out.cpp'])
elif q == 'exit':
break
@@ -151,9 +158,9 @@ while test_parser:
stmts = parser.parse(contents)
continue
stmts = parser.parse(q)
- print(stmts)
+ cxt.Info(stmts)
except (ValueError, FileNotFoundError, ParseException) as e:
rm()
- print(type(e), e)
+ cxt.Error(type(e), e)
rm()
\ No newline at end of file
diff --git a/server/aggregations.h b/server/aggregations.h
index 7a5accc..a85adbd 100644
--- a/server/aggregations.h
+++ b/server/aggregations.h
@@ -133,7 +133,7 @@ decayed_t> avgw(uint32_t w, const VT& arr) {
const uint32_t& len = arr.size;
decayed_t ret(len);
uint32_t i = 0;
- types::GetLongType s;
+ types::GetLongType s{};
w = w > len ? len : w;
if(len) s = ret[i++] = arr[0];
for (; i < w; ++i)
diff --git a/server/enc_temp_folder/3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H b/server/enc_temp_folder/3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H
deleted file mode 100644
index 757cb76..0000000
--- a/server/enc_temp_folder/3ad6cbe3a5dd4f9a9284fdca02eb4ea/IO.H
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-#include "types.h"
-#include
-#include
-template
-std::string generate_printf_string(const char* sep = " ", const char* end = "\n") {
- std::string str;
- ((str += types::printf_str[types::Types>::getType()], str += sep), ...);
- const auto trim = str.size() - strlen(sep);
- if (trim > 0)
- str.resize(trim);
- str += end;
- return str;
-}
-
diff --git a/server/enc_temp_folder/d544cc15c643dbd4f18da52d811c040/table.h b/server/enc_temp_folder/d544cc15c643dbd4f18da52d811c040/table.h
deleted file mode 100644
index 059c3e6..0000000
--- a/server/enc_temp_folder/d544cc15c643dbd4f18da52d811c040/table.h
+++ /dev/null
@@ -1,443 +0,0 @@
-// TODO: Replace `cout, printf` with sprintf&fputs and custom buffers
-
-#ifndef _TABLE_H
-#define _TABLE_H
-
-#include "types.h"
-#include "vector_type.hpp"
-#include
-#include
-#include "io.h"
-template
-class vector_type;
-template <>
-class vector_type;
-
-#ifdef _MSC_VER
-namespace types {
- enum Type_t;
- template
- struct Types;
- template
- struct Coercion;
-}
-#endif
-template
-class ColView;
-template
-class ColRef : public vector_type<_Ty>
-{
-public:
- typedef ColRef<_Ty> Decayed_t;
- const char* name;
- types::Type_t ty = types::ERROR;
- ColRef() : vector_type<_Ty>(0), name("") {}
- ColRef(const uint32_t& size, const char* name = "") : vector_type<_Ty>(size), name(name) {}
- ColRef(const char* name) : name(name) {}
- void init(const char* name = "") { ty = types::Types<_Ty>::getType(); this->size = this->capacity = 0; this->container = 0; this->name = name; }
- ColRef(const char* name, types::Type_t ty) : name(name), ty(ty) {}
- using vector_type<_Ty>::operator[];
- using vector_type<_Ty>::operator=;
- ColView<_Ty> operator [](const vector_type&idxs) const {
- return ColView<_Ty>(*this, idxs);
- }
-
- void out(uint32_t n = 4, const char* sep = " ") const {
- n = n > this->size ? this->size : n;
- std::cout << '(';
- for (uint32_t i = 0; i < n; ++i)
- std::cout << this->operator[](i) << sep;
- std::cout << ')';
- }
- template
- ColRef scast();
-};
-
-template
-class ColView {
-public:
- typedef ColRef<_Ty> Decayed_t;
- const vector_type& idxs;
- const ColRef<_Ty>& orig;
- const uint32_t& size;
- ColView(const ColRef<_Ty>& orig, const vector_type& idxs) : orig(orig), idxs(idxs), size(idxs.size) {}
- ColView(const ColView<_Ty>& orig, const vector_type& idxs) : orig(orig.orig), idxs(idxs), size(idxs.size) {
- for (uint32_t i = 0; i < size; ++i)
- idxs[i] = orig.idxs[idxs[i]];
- }
- _Ty& operator [](const uint32_t& i) const {
- return orig[idxs[i]];
- }
- struct Iterator_t {
- const uint32_t* val;
- const ColRef<_Ty>& orig;
- constexpr Iterator_t(const uint32_t* val, const ColRef<_Ty>& orig) noexcept : val(val), orig(orig) {}
- _Ty& operator*() { return orig[*val]; }
- bool operator != (const Iterator_t& rhs) { return rhs.val != val; }
- Iterator_t& operator++ () {
- ++val;
- return *this;
- }
- Iterator_t operator++ (int) {
- Iterator_t tmp = *this;
- ++val;
- return tmp;
- }
- };
- Iterator_t begin() const {
- return Iterator_t(idxs.begin(), orig);
- }
- Iterator_t end() const {
- return Iterator_t(idxs.end(), orig);
- }
- void out(uint32_t n = 4, const char* sep = " ") const {
- n = n > size ? size : n;
- std::cout<<'(';
- for (uint32_t i = 0; i < n; ++i)
- std::cout << this->operator[](i)<< sep;
- std::cout << ')';
- }
- operator ColRef<_Ty>() {
- auto ret = ColRef<_Ty>(size);
- for (uint32_t i = 0; i < size; ++i)
- ret[i] = orig[idxs[i]];
- return ret;
- }
-};
-template class VT, class T>
-std::ostream& operator<<(std::ostream& os, const VT& v)
-{
- v.out();
- return os;
-}
-template
-struct decayed_impl { typedef ColRef type; };
-template
-template
-inline ColRef ColRef<_Ty>::scast()
-{
- this->ty = types::Types::getType();
- return *(ColRef *)this;
-}
-using uColRef = ColRef;
-
-template struct TableInfo;
-template struct TableView;
-
-template
-constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept {
- if constexpr (order)
- return *(ColRef>> *) & (table.colrefs[_Index]);
- else
- return *(ColRef>> *) & (table.colrefs[-1-_Index]);
-}
-
-template
-constexpr inline ColRef>>& get(const TableView<_Types...>& table) noexcept {
- return *(ColRef>> *) & (table.info.colrefs[_Index]);
-}
-
-template
-struct is_vector_impl> : std::true_type {};
-template
-struct is_vector_impl> : std::true_type {};
-template
-struct is_vector_impl> : std::true_type {};
-
-template
-struct TableView;
-template
-struct TableInfo {
- const char* name;
- ColRef* colrefs;
- uint32_t n_cols;
- typedef std::tuple tuple_type;
- void print(const char* __restrict sep, const char* __restrict end) const;
-
- template
- struct lineage_t {
- TableInfo* this_table;
- TableInfo* table;
- vector_type rid;
- constexpr lineage_t(TableInfo*this_table, TableInfo *table)
- : this_table(this_table), table(table), rid(0) {}
- constexpr lineage_t() : this_table(0), table(0), rid(0) {}
-
- template
- inline auto& get(uint32_t idx) {
- return get(*table)[rid[idx]];
- }
- void emplace_back(const uint32_t& v) {
- rid.emplace_back(v);
- }
- };
- template
- auto bind(TableInfo* table2) {
- return lineage_t(this, table2);
- }
-
- template
- typename std::enable_if::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
- template
- typename std::enable_if::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
- template
- struct GetTypes {
- typedef typename std::tuple::type ...> type;
- };
- template
- using getRecordType = typename GetTypes::type;
- TableInfo(const char* name, uint32_t n_cols);
- template
- inline void materialize(const vector_type& idxs, TableInfo* tbl = nullptr) { // inplace materialize
- if constexpr(prog == 0) tbl = (tbl == 0 ? this : tbl);
- if constexpr (prog == sizeof...(Types)) return;
- else {
- auto& col = get(*this);
- auto new_col = decays{idxs.size};
- for(uint32_t i = 0; i < idxs.size; ++i)
- new_col[i] = col[idxs[i]];
- get(*tbl) = new_col;
- materialize(idxs, tbl);
- }
- }
- inline TableInfo* materialize_copy(const vector_type& idxs) {
- auto tbl = new TableInfo(this->name, sizeof...(Types));
- materialize<0>(idxs, tbl);
- return tbl;
- }
- template
- inline vector_type* order_by(vector_type* ord = nullptr) {
- if (!ord) {
- ord = new vector_type(colrefs[0].size);
- for (uint32_t i = 0; i < colrefs[0].size; ++i)
- (*ord)[i] = i;
- }
- std::sort(ord->begin(), ord->end(), [this](const uint32_t& lhs, const uint32_t& rhs) {
- return
- std::forward_as_tuple((cols >= 0 ? get= 0)>(*this)[lhs] : -get= 0)>(*this)[lhs]) ...)
- <
- std::forward_as_tuple((cols >= 0 ? get= 0)>(*this)[rhs] : -get= 0)>(*this)[rhs]) ...);
- });
- return ord;
- }
- template
- auto order_by_view () {
- return TableView(order_by(), *this);
- }
-
- // Print 2 -- generate printf string first, supports flattening, supports sprintf/printf/fprintf
- template
- inline void print2_impl(Fn func, const uint32_t& i, const __Types& ... args) const {
- using this_type = typename std::tuple_element::type;
- const auto& this_value = get(*this)[i];
- const auto& next = [&](auto &v) {
- if constexpr (sizeof...(rem_cols) == 0)
- func(args..., v);
- else
- print2_impl(func, i, args ..., v);
- };
- if constexpr (is_vector_type)
- for (int j = 0; j < this_value.size; ++j)
- next(this_value[j]);
- else
- next(this_value);
- }
- template
- void print2(const char* __restrict sep = ",", const char* __restrict end = "\n",
- const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr) const {
- std::string printf_string =
- generate_printf_string::type ...>(sep, end);
- const auto& prt_loop = [&fp, &view, &printf_string, *this](const auto& f) {
- if(view)
- for (int i = 0; i < view->size; ++i)
- print2_impl(f, (*view)[i], printf_string.c_str());
- else
- for (int i = 0; i < colrefs[0].size; ++i)
- print2_impl(f, i, printf_string.c_str());
- };
- if (fp)
- prt_loop([&fp](auto... args) { fprintf(fp, args...); });
- else
- prt_loop(printf);
- }
- template struct applier {
- inline constexpr static void apply(const TableInfo& t, const char* __restrict sep = ",", const char* __restrict end = "\n",
- const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr)
- { t.template print2(sep, end, view, fp); }};
-
- inline void printall(const char* __restrict sep = ",", const char* __restrict end = "\n",
- const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr) {
- applyIntegerSequence::apply(*this, sep, end, view, fp);
- }
-};
-
-
-template
-struct TableView {
- const vector_type* idxs;
- const TableInfo& info;
- constexpr TableView(const vector_type* idxs, const TableInfo& info) noexcept : idxs(idxs), info(info) {}
- void print(const char* __restrict sep, const char* __restrict end) const;
- template
- typename std::enable_if::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
- template
- typename std::enable_if < j < sizeof...(Types) - 1, void>::type print_impl(const uint32_t& i, const char* __restrict sep = " ") const;
-
- ~TableView() {
- delete idxs;
- }
-};
-
-template
-constexpr static inline bool is_vector(const ColRef&) {
- return true;
-}
-template
-constexpr static inline bool is_vector(const vector_type&) {
- return true;
-}
-
-template
-TableInfo::TableInfo(const char* name, uint32_t n_cols) : name(name), n_cols(n_cols) {
- this->colrefs = (ColRef*)malloc(sizeof(ColRef) * n_cols);
-}
-template
-template
-inline typename std::enable_if::type
-TableView::print_impl(const uint32_t& i, const char* __restrict sep) const {
- std::cout << (get(*this))[(*idxs)[i]];
-}
-
-template
-template
-inline typename std::enable_if < j < sizeof...(Types) - 1, void>::type
- TableView::print_impl(const uint32_t& i, const char* __restrict sep) const
-{
- std::cout << (get(*this))[(*idxs)[i]] << sep;
- print_impl(i, sep);
-}
-
-template
-inline void TableView::print(const char* __restrict sep, const char* __restrict end) const {
- int n_rows = 0;
- if (info.colrefs[0].size > 0)
- n_rows = info.colrefs[0].size;
- for (int i = 0; i < n_rows; ++i) {
- print_impl(i);
- std::cout << end;
- }
-}
-template
-template
-inline typename std::enable_if::type
- TableInfo::print_impl(const uint32_t& i, const char* __restrict sep) const {
- std::cout << (get(*this))[i];
-}
-
-template
-template
-inline typename std::enable_if::type
- TableInfo::print_impl(const uint32_t& i, const char* __restrict sep) const
-{
- std::cout << (get(*this))[i] << sep;
- print_impl(i, sep);
-}
-
-template
-inline void TableInfo::print(const char* __restrict sep, const char* __restrict end) const {
- int n_rows = 0;
- if (n_cols > 0 && colrefs[0].size > 0)
- n_rows = colrefs[0].size;
- for (int i = 0; i < n_rows; ++i) {
- print_impl(i);
- std::cout << end;
- }
-}
-template class VT, template class VT2>
-decayed_t::type> operator -(const VT& lhs, const VT2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] - rhs[i];
- return ret;
-}
-template class VT>
-decayed_t::type> operator -(const VT& lhs, const T2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] - rhs;
- return ret;
-}
-template class VT, template class VT2>
-decayed_t::type> operator +(const VT& lhs, const VT2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] + rhs[i];
- return ret;
-}
-template class VT>
-decayed_t::type> operator +(const VT& lhs, const T2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] + rhs;
- return ret;
-}
-template class VT, template class VT2>
-decayed_t::type> operator *(const VT& lhs, const VT2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] * rhs[i];
- return ret;
-}
-template class VT>
-decayed_t::type> operator *(const VT& lhs, const T2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] * rhs;
- return ret;
-}
-template class VT, template class VT2>
-decayed_t::type> operator /(const VT& lhs, const VT2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] / rhs[i];
- return ret;
-}
-template class VT>
-decayed_t::type> operator /(const VT& lhs, const T2& rhs) {
- auto ret = decayed_t::type>(lhs.size, "");
- for (int i = 0; i < lhs.size; ++i)
- ret[i] = lhs[i] / rhs;
- return ret;
-}
-
-template
-void print(const TableInfo& v, const char* delimiter = " ", const char* endline = "\n") {
- v.print(delimiter, endline);
-}
-template
-void print(const TableView& v, const char* delimiter = " ", const char* endline = "\n") {
- v.print(delimiter, endline);
-}
-template
-void print(const T& v, const char* delimiter = " ") {
- std::cout<< v;
- // printf(types::printf_str[types::Types::getType()], v);
-}
-template
-void inline print_impl(const T& v, const char* delimiter, const char* endline) {
- for (const auto& vi : v) {
- print(vi);
- std::cout << delimiter;
- // printf("%s", delimiter);
- }
- std::cout << endline;
- //printf("%s", endline);
-}
-
-template class VT>
-typename std::enable_if, TableInfo>::value>::type
-print(const VT& v, const char* delimiter = " ", const char* endline = "\n") {
- print_impl(v, delimiter, endline);
-}
-
-#endif
\ No newline at end of file
diff --git a/server/libaquery.h b/server/libaquery.h
index 3288a03..57ac4e1 100644
--- a/server/libaquery.h
+++ b/server/libaquery.h
@@ -4,9 +4,28 @@
#include "table.h"
#include
+enum Log_level {
+ LOG_INFO,
+ LOG_ERROR,
+ LOG_SILENT
+};
+
struct Context{
- std::unordered_map tables;
+ typedef int (*printf_type) (const char *format, ...);
+ std::unordered_map tables;
std::unordered_map cols;
+ Log_level log_level = LOG_SILENT;
+ printf_type print = printf;
+ template
+ void log(Types... args) {
+ if (log_level == LOG_INFO)
+ print(args...);
+ }
+ template
+ void err(Types... args) {
+ if (log_level <= LOG_ERROR)
+ print(args...);
+ }
};
#ifdef _MSC_VER
diff --git a/server/server.cpp b/server/server.cpp
index 8a32f10..d294392 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -37,7 +37,9 @@ void daemon(thread_context* c) {
typedef int (*code_snippet)(void*);
int _main();
int main(int argc, char** argv) {
- printf("%d %s\n", argc, argv[1]);
+ Context* cxt = new Context();
+ cxt->log("%d %s\n", argc, argv[1]);
+
const char* shmname;
if (argc <= 1)
return _main();
@@ -48,24 +50,23 @@ int main(int argc, char** argv) {
return 1;
bool &running = static_cast(shm.pData)[0],
&ready = static_cast(shm.pData)[1];
- Context *cxt = new Context();
using namespace std::chrono_literals;
- printf("running: %s\n", running? "true":"false");
- printf("ready: %s\n", ready? "true":"false");
+ cxt->log("running: %s\n", running? "true":"false");
+ cxt->log("ready: %s\n", ready? "true":"false");
while (running) {
std::this_thread::sleep_for(1ms);
if(ready){
- printf("running: %s\n", running? "true":"false");
- printf("ready: %s\n", ready? "true":"false");
+ cxt->log("running: %s\n", running? "true":"false");
+ cxt->log("ready: %s\n", ready? "true":"false");
void* handle = dlopen("./dll.so", RTLD_LAZY);
- printf("handle: %x\n", handle);
+ cxt->log("handle: %x\n", handle);
if (handle) {
- printf("inner\n");
+ cxt->log("inner\n");
code_snippet c = reinterpret_cast(dlsym(handle, "dllmain"));
- printf("routine: %x\n", c);
+ cxt->log("routine: %x\n", c);
if (c) {
- printf("inner\n");
- printf("return: %d\n", c(cxt));
+ cxt->log("inner\n");
+ cxt->err("return: %d\n", c(cxt));
}
dlclose(handle);
}
@@ -84,17 +85,18 @@ int _main()
//t.emplace_back(2);
//print(t);
//return 0;
+ Context* cxt = new Context();
+ cxt->log_level = LOG_INFO;
puts(cpp_17 ?"true":"false");
void* handle = dlopen("dll.so", RTLD_LAZY);
printf("handle: %x\n", handle);
- Context* cxt = new Context();
if (handle) {
- printf("inner\n");
+ cxt->log("inner\n");
code_snippet c = reinterpret_cast(dlsym(handle, "dllmain"));
printf("routine: %x\n", c);
if (c) {
- printf("inner\n");
- printf("return: %d\n", c(cxt));
+ cxt->log("inner\n");
+ cxt->log("return: %d\n", c(cxt));
}
dlclose(handle);
}
diff --git a/server/server.vcxproj b/server/server.vcxproj
index 8421b08..fac9b38 100644
--- a/server/server.vcxproj
+++ b/server/server.vcxproj
@@ -46,7 +46,7 @@
true
v143
Unicode
- true
+ false
Application
diff --git a/server/table.h b/server/table.h
index 9b3ce8f..bea1954 100644
--- a/server/table.h
+++ b/server/table.h
@@ -45,8 +45,13 @@ public:
void out(uint32_t n = 4, const char* sep = " ") const {
n = n > this->size ? this->size : n;
std::cout << '(';
- for (uint32_t i = 0; i < n; ++i)
+ if (n > 0)
+ {
+ uint32_t i = 0;
+ for (; i < n - 1; ++i)
std::cout << this->operator[](i) << sep;
+ std::cout << this->operator[](i);
+ }
std::cout << ')';
}
template
@@ -242,23 +247,49 @@ struct TableInfo {
else
next(this_value);
}
+ std::string get_header_string(const char* __restrict sep, const char* __restrict end) const{
+ std::string header_string = std::string();
+ for (int i = 0; i < sizeof...(Types); ++i)
+ header_string += std::string(this->colrefs[i].name) + sep;
+ const size_t l_sep = strlen(sep);
+ if (header_string.size() - l_sep >= 0)
+ header_string.resize(header_string.size() - l_sep);
+ header_string += end + std::string(header_string.size(), '=') + end;
+ return header_string;
+ }
template
void print2(const char* __restrict sep = ",", const char* __restrict end = "\n",
const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr) const {
+
std::string printf_string =
generate_printf_string::type ...>(sep, end);
+
+ std::string header_string = std::string();
+ constexpr static int a_cols[] = { cols... };
+ for(int i = 0; i < sizeof...(cols); ++i)
+ header_string += std::string(this->colrefs[a_cols[i]].name) + sep;
+ const size_t l_sep = strlen(sep);
+ if(header_string.size() - l_sep >= 0)
+ header_string.resize(header_string.size() - l_sep);
+
const auto& prt_loop = [&fp, &view, &printf_string, *this](const auto& f) {
if(view)
for (int i = 0; i < view->size; ++i)
print2_impl(f, (*view)[i], printf_string.c_str());
else
for (int i = 0; i < colrefs[0].size; ++i)
- print2_impl(f, i, printf_string.c_str());
+ print2_impl(f, i, printf_string.c_str());
};
+
if (fp)
+ {
+ fprintf(fp, "%s%s", header_string.c_str(), end);
prt_loop([&fp](auto... args) { fprintf(fp, args...); });
- else
+ }
+ else {
+ printf("%s%s", header_string.c_str(), end);
prt_loop(printf);
+ }
}
template struct applier {
inline constexpr static void apply(const TableInfo& t, const char* __restrict sep = ",", const char* __restrict end = "\n",
@@ -319,6 +350,9 @@ inline typename std::enable_if < j < sizeof...(Types) - 1, void>::type
template
inline void TableView::print(const char* __restrict sep, const char* __restrict end) const {
+ std::string header_string = info.get_header_string(sep, end);
+ std::cout << header_string.c_str();
+
int n_rows = 0;
if (info.colrefs[0].size > 0)
n_rows = info.colrefs[0].size;
@@ -345,6 +379,10 @@ inline typename std::enable_if::type
template
inline void TableInfo::print(const char* __restrict sep, const char* __restrict end) const {
+
+ std::string header_string = get_header_string(sep, end);
+ std::cout << header_string.c_str();
+
int n_rows = 0;
if (n_cols > 0 && colrefs[0].size > 0)
n_rows = colrefs[0].size;
diff --git a/server/vector_type.cpp b/server/vector_type.cpp
index ebb4460..3cb23c1 100644
--- a/server/vector_type.cpp
+++ b/server/vector_type.cpp
@@ -5,7 +5,11 @@ inline void vector_type<_Ty>::out(uint32_t n, const char* sep) const
{
n = n > size ? size : n;
std::cout << '(';
- for (uint32_t i = 0; i < n; ++i)
+ {
+ uint32_t i = 0;
+ for (; i < n - 1; ++i)
std::cout << this->operator[](i) << sep;
+ std::cout << this->operator[](i);
+ }
std::cout << ')';
}
\ No newline at end of file