From 5a163a6af9b169bc95da36d0c2210771e15a526b Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 24 Aug 2022 07:43:42 +0800 Subject: [PATCH] fix exit --- .gitignore | 5 +++++ Makefile | 4 +++- prompt.py | 5 ++++- reconstruct/ast.py | 10 +++++----- server/monetdb_conn.cpp | 10 +++++++++- server/monetdb_conn.h | 5 +++++ server/server.cpp | 8 ++++---- server/types.h | 2 +- 8 files changed, 36 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index f606d26..fa039f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +*.json +!sample_ast.json +*.o +*.pch +*.gch a.out.* *.log *.pyc diff --git a/Makefile b/Makefile index 4eda0dc..fcea7cc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ OS_SUPPORT = MonetDB_LIB = Threading = + ifeq ($(OS),Windows_NT) OS_SUPPORT += server/winhelper.cpp MonetDB_LIB += -Imonetdb/msvc msc-plugin/monetdbe.dll @@ -11,6 +12,7 @@ endif ifeq ($(THREADING),1) Threading += server/threading.cpp -DTHREADING endif + info: $(info $(OS_SUPPORT)) $(info $(OS)) @@ -22,6 +24,6 @@ server.so: # $(CXX) server/server.cpp server/monetdb_conn.cpp -fPIC -shared $(OS_SUPPORT) monetdb/msvc/monetdbe.dll --std=c++1z -O3 -march=native -o server.so -I./monetdb/msvc $(CXX) -shared -fPIC -flto server/server.cpp server/io.cpp server/table.cpp $(OS_SUPPORT) server/monetdb_conn.cpp $(Threading) $(MonetDB_LIB) --std=c++1z -o server.so -O3 snippet: - $(CXX) -shared -fPIC -flto --std=c++1z out.cpp server/monetdb_conn.cpp server/table.cpp server/io.cpp $(MonetDB_LIB) -O3 -march=native -o dll.so + $(CXX) -shared -fPIC -flto --std=c++1z -include server/aggregations.h out.cpp server/monetdb_conn.cpp server/table.cpp server/io.cpp $(MonetDB_LIB) -O3 -march=native -o dll.so clean: rm *.shm -rf diff --git a/prompt.py b/prompt.py index 348b8bb..bf47811 100644 --- a/prompt.py +++ b/prompt.py @@ -104,7 +104,7 @@ class PromptState(): th = None send = None test_parser = True - server_mode : RunType = RunType.Threaded + server_mode: RunType = RunType.Threaded server_bin = 'server.bin' if server_mode == RunType.IPC else 'server.so' set_ready = lambda: None get_ready = lambda: None @@ -381,6 +381,9 @@ def main(running = lambda:True, next = input, state = None): print(e) except (KeyboardInterrupt): break + except SystemExit: + print("\nBye.") + raise except: import code, traceback sh = code.InteractiveConsole({**globals(), **locals()}) diff --git a/reconstruct/ast.py b/reconstruct/ast.py index 5b248e6..0061ec7 100644 --- a/reconstruct/ast.py +++ b/reconstruct/ast.py @@ -30,10 +30,10 @@ class ast_node: def add(self, code): self.sql += code + ' ' def addc(self, code): - self.ccode += code + '\n' - + self.ccode += code + '\n' + name = 'null' - + def init(self, _): if self.parent is None: self.context.sql_begin() @@ -43,7 +43,7 @@ class ast_node: pass def spawn(self, _): pass - + def consume(self, _): if self.parent is None: self.emit(self.sql+';\n') @@ -245,7 +245,7 @@ class projection(ast_node): if type(val[1]) is int: self.context.emitc(f'{self.outtable_name}->get_col<{key}>().initfrom({vid2cname[val[1]]});') else: - # for funcs evaluate f_i(x, ...) + # for funcs evaluate f_i(x, ...) self.context.emitc(f'{self.outtable_name}->get_col<{key}>() = {val[1]};') # print out col_is self.context.emitc(f'print(*{self.outtable_name});') diff --git a/server/monetdb_conn.cpp b/server/monetdb_conn.cpp index 0cfc911..61428d8 100644 --- a/server/monetdb_conn.cpp +++ b/server/monetdb_conn.cpp @@ -139,4 +139,12 @@ void* Server::getCol(int col_idx){ Server::~Server(){ close(); -} \ No newline at end of file +} + +bool Server::havehge() { +#if defined(_MONETDBE_LIB_) and defined(HAVE_HGE) + return HAVE_HGE; +#else + return false; +#endif +} diff --git a/server/monetdb_conn.h b/server/monetdb_conn.h index b550476..5afae0e 100644 --- a/server/monetdb_conn.h +++ b/server/monetdb_conn.h @@ -1,3 +1,5 @@ +#ifndef __MONETDB_CONN_H__ +#define __MONETDB_CONN_H__ struct Context; @@ -19,5 +21,8 @@ struct Server{ void *getCol(int col_idx); void close(); bool haserror(); + static bool havehge(); ~Server(); }; + +#endif diff --git a/server/server.cpp b/server/server.cpp index 522df1f..3c4003f 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -65,8 +65,8 @@ extern "C" int __DLLEXPORT__ binary_info() { } __AQEXPORT__(bool) have_hge(){ -#if defined(_MONETDBE_LIB_) and defined(HAVE_HGE) - return HAVE_HGE; +#if defined(__MONETDB_CONN_H__) + return Server::havehge(); #else return false; #endif @@ -105,10 +105,10 @@ int dll_main(int argc, char** argv, Context* cxt){ } for(int i = 0; i < n_recv; ++i) { - printf("%s, %d\n", n_recvd[i], n_recvd[i][0] == 'Q'); + //printf("%s, %d\n", n_recvd[i], n_recvd[i][0] == 'Q'); if (n_recvd[i][0] == 'Q'){ server->exec(n_recvd[i] + 1); - printf("Exec Q%d: %s\n", i, n_recvd[i]); + printf("Exec Q%d: %s", i, n_recvd[i]); } else if (n_recvd[i][0] == 'P' && handle && !server->haserror()) { code_snippet c = reinterpret_cast(dlsym(handle, n_recvd[i]+1)); diff --git a/server/types.h b/server/types.h index 1df357f..562a0c4 100644 --- a/server/types.h +++ b/server/types.h @@ -1,10 +1,10 @@ #ifndef _TYPES_H #define _TYPES_H #include -#include #include #include #include +#include #ifdef _MSC_VER #define __restrict__ __restrict