Add Lisp C++ Preprocessing (LCP)
Summary:
In order to enhance C++ metaprogramming capabilities, a custom
preprocessing step is added before compilation. C++ code may be mixed
with Lisp code in order to generate a complete C++ source code. The
mechanism is hooked into cmake. To notify cmake of .lcp files, `add_lcp`
function in src/CMakeLists.txt needs to be invoked.
The main executable entry point is in tools/lcp, while the source code
is in src/lisp/lcp.lisp
The main goal of LCP is to auto generate class serialization code and
member variable getter functions. This should now be significantly less
error prone, since you cannot forget to serialize a member variable
through this mechanism. Future uses should be generating other repeating
code, such as `Clone` methods or perhaps some debug information.
.lcp files may contain mixed C++ code (enclosed in #>cpp ... cpp<#
blocks) with Common Lisp code.
NOTE: With great power comes great responsibility. Lisp metaprogramming
capabilities are incredibly powerful. To keep the sanity of the team
intact, use Lisp preprocessing only when *really* necessary.
Reviewers: buda, mferencevic, msantl, dgleich, ipaljak, mculinovic, mtomic
Reviewed By: mtomic
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D1361
2018-04-27 21:48:30 +08:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
2019-05-10 19:54:23 +08:00
|
|
|
if [[ ! ($# -ge 1 && $# -le 3) ]]; then
|
|
|
|
echo "Usage: $0 [--debug] LCP_FILE [SLK_SERIALIZE]"
|
2018-05-16 19:48:56 +08:00
|
|
|
echo "Convert a LCP_FILE to C++ header file and output to stdout."
|
2019-05-03 02:53:54 +08:00
|
|
|
echo "If SLK_SERIALIZE is provided, then SLK serialization is generated."
|
Add Lisp C++ Preprocessing (LCP)
Summary:
In order to enhance C++ metaprogramming capabilities, a custom
preprocessing step is added before compilation. C++ code may be mixed
with Lisp code in order to generate a complete C++ source code. The
mechanism is hooked into cmake. To notify cmake of .lcp files, `add_lcp`
function in src/CMakeLists.txt needs to be invoked.
The main executable entry point is in tools/lcp, while the source code
is in src/lisp/lcp.lisp
The main goal of LCP is to auto generate class serialization code and
member variable getter functions. This should now be significantly less
error prone, since you cannot forget to serialize a member variable
through this mechanism. Future uses should be generating other repeating
code, such as `Clone` methods or perhaps some debug information.
.lcp files may contain mixed C++ code (enclosed in #>cpp ... cpp<#
blocks) with Common Lisp code.
NOTE: With great power comes great responsibility. Lisp metaprogramming
capabilities are incredibly powerful. To keep the sanity of the team
intact, use Lisp preprocessing only when *really* necessary.
Reviewers: buda, mferencevic, msantl, dgleich, ipaljak, mculinovic, mtomic
Reviewed By: mtomic
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D1361
2018-04-27 21:48:30 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-05-10 19:54:23 +08:00
|
|
|
debug=false
|
|
|
|
if [[ "$1" == "--debug" ]]; then
|
|
|
|
debug=true
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
Add Lisp C++ Preprocessing (LCP)
Summary:
In order to enhance C++ metaprogramming capabilities, a custom
preprocessing step is added before compilation. C++ code may be mixed
with Lisp code in order to generate a complete C++ source code. The
mechanism is hooked into cmake. To notify cmake of .lcp files, `add_lcp`
function in src/CMakeLists.txt needs to be invoked.
The main executable entry point is in tools/lcp, while the source code
is in src/lisp/lcp.lisp
The main goal of LCP is to auto generate class serialization code and
member variable getter functions. This should now be significantly less
error prone, since you cannot forget to serialize a member variable
through this mechanism. Future uses should be generating other repeating
code, such as `Clone` methods or perhaps some debug information.
.lcp files may contain mixed C++ code (enclosed in #>cpp ... cpp<#
blocks) with Common Lisp code.
NOTE: With great power comes great responsibility. Lisp metaprogramming
capabilities are incredibly powerful. To keep the sanity of the team
intact, use Lisp preprocessing only when *really* necessary.
Reviewers: buda, mferencevic, msantl, dgleich, ipaljak, mculinovic, mtomic
Reviewed By: mtomic
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D1361
2018-04-27 21:48:30 +08:00
|
|
|
if [[ ! -r "$1" ]]; then
|
|
|
|
echo "File '$1' doesn't exist or isn't readable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
lcp_file=`realpath $1`
|
|
|
|
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
quicklisp_install_dir="$HOME/quicklisp"
|
|
|
|
if [[ -v QUICKLISP_HOME ]]; then
|
|
|
|
quicklisp_install_dir="${QUICKLISP_HOME}"
|
|
|
|
fi
|
|
|
|
|
2019-05-03 02:53:54 +08:00
|
|
|
slk_serialize=""
|
|
|
|
if [[ "$2" == "SLK_SERIALIZE" ]]; then
|
2019-05-28 22:30:23 +08:00
|
|
|
slk_serialize=":slk-serialize-p t"
|
2018-05-16 19:48:56 +08:00
|
|
|
fi
|
|
|
|
|
2019-05-10 19:54:23 +08:00
|
|
|
if [[ $debug == "true" ]]; then
|
|
|
|
echo \
|
|
|
|
"
|
|
|
|
(load \"${quicklisp_install_dir}/setup.lisp\")
|
|
|
|
(ql:quickload :lcp :silent t)
|
|
|
|
(let ((*debugger-hook* #'lcp.debug:lcp-debugger-hook))
|
2019-05-28 22:30:23 +08:00
|
|
|
(lcp:process-lcp-file \"$lcp_file\" $slk_serialize))
|
2019-05-10 19:54:23 +08:00
|
|
|
" | sbcl --noinform --noprint
|
|
|
|
else
|
|
|
|
echo \
|
|
|
|
"
|
|
|
|
(load \"${quicklisp_install_dir}/setup.lisp\")
|
|
|
|
(ql:quickload :lcp :silent t)
|
2019-05-28 22:30:23 +08:00
|
|
|
(lcp:process-lcp-file \"$lcp_file\" $slk_serialize)
|
2019-05-10 19:54:23 +08:00
|
|
|
" | sbcl --script
|
|
|
|
fi
|
2018-05-16 19:48:56 +08:00
|
|
|
|
|
|
|
filename=`basename $lcp_file .lcp`
|
|
|
|
hpp_file="$(dirname $lcp_file)/$filename.hpp"
|
|
|
|
clang-format -style=file -i $hpp_file
|
|
|
|
|
2018-11-16 17:55:37 +08:00
|
|
|
if [[ -w "$lcp_file.cpp" ]]; then
|
2018-05-16 19:48:56 +08:00
|
|
|
clang-format -style=file -i "$lcp_file.cpp"
|
|
|
|
fi
|