Setup the serene-repl target with a basic REPL loop
This commit is contained in:
parent
f473d1122b
commit
c05d42107f
10
README.org
10
README.org
|
@ -56,6 +56,16 @@ Setup the githook and install dependencies using the following commands:
|
||||||
*** Emacs
|
*** Emacs
|
||||||
If you're using Emacs as your development environment just install =clangd= and =lsp=.
|
If you're using Emacs as your development environment just install =clangd= and =lsp=.
|
||||||
|
|
||||||
|
** Heads up for devs
|
||||||
|
While you're working on *Serene* be mindful of:
|
||||||
|
- In =DEBUG= mode we dynamically link against =libsan= due to the fact that we build the =libserene=
|
||||||
|
as a shared lib by default. This means we need to =LD_PRELOAD= the =libclang_rt= before we run
|
||||||
|
any executable. If you're using the =builder= script you're all set otherwise you can run an
|
||||||
|
executable like:
|
||||||
|
|
||||||
|
#+BEGIN_SRC bash
|
||||||
|
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) /path/to/executable
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
* How to build
|
* How to build
|
||||||
In order to build for development (Debug mode) just use =./builder build= to setup the build and build
|
In order to build for development (Debug mode) just use =./builder build= to setup the build and build
|
||||||
|
|
12
builder
12
builder
|
@ -101,6 +101,12 @@ function run() {
|
||||||
popd_build
|
popd_build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function repl() {
|
||||||
|
pushed_build
|
||||||
|
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) "$BUILD_DIR"/src/serene-repl/serene-repl "$@"
|
||||||
|
popd_build
|
||||||
|
}
|
||||||
|
|
||||||
function memcheck() {
|
function memcheck() {
|
||||||
export ASAN_FLAG=""
|
export ASAN_FLAG=""
|
||||||
build
|
build
|
||||||
|
@ -155,9 +161,15 @@ case "$command" in
|
||||||
compile
|
compile
|
||||||
run-tests
|
run-tests
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"run")
|
"run")
|
||||||
run "${@:2}"
|
run "${@:2}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"repl")
|
||||||
|
repl "${@:2}"
|
||||||
|
;;
|
||||||
|
|
||||||
"run-tests")
|
"run-tests")
|
||||||
run-tests "${@:2}"
|
run-tests "${@:2}"
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
add_subdirectory(libserene)
|
add_subdirectory(libserene)
|
||||||
add_subdirectory(serenec)
|
add_subdirectory(serenec)
|
||||||
|
add_subdirectory(serene-repl)
|
||||||
|
|
||||||
# Testing only available if this is the main app
|
# Testing only available if this is the main app
|
||||||
# Emergency override SERENE_CMAKE_BUILD_TESTING provided as well
|
# Emergency override SERENE_CMAKE_BUILD_TESTING provided as well
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
# Serene Programming Language
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 2.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
add_executable(serene-repl serene-repl.cpp)
|
||||||
|
add_executable(Serene::Repl ALIAS serene-repl)
|
||||||
|
|
||||||
|
set_target_properties(serene-repl PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||||
|
# Warn on unused libs
|
||||||
|
LINK_WHAT_YOU_USE TRUE
|
||||||
|
|
||||||
|
# LTO support
|
||||||
|
INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
|
||||||
|
|
||||||
|
if (CPP_20_SUPPORT)
|
||||||
|
target_compile_features(serene-repl PRIVATE cxx_std_20)
|
||||||
|
else()
|
||||||
|
target_compile_features(serene-repl PRIVATE cxx_std_17)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
target_link_libraries(serene-repl
|
||||||
|
PRIVATE
|
||||||
|
Serene::lib
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(serene-repl PRIVATE ${PROJECT_BINARY_DIR})
|
||||||
|
target_include_directories(serene-repl PRIVATE ${INCLUDE_DIR})
|
||||||
|
|
||||||
|
install(TARGETS serene-repl DESTINATION bin)
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,84 @@
|
||||||
|
/* -*- C++ -*-
|
||||||
|
* Serene Programming Language
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 2.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "serene/serene.h"
|
||||||
|
|
||||||
|
#include <linenoise.h>
|
||||||
|
#include <llvm/Support/CommandLine.h>
|
||||||
|
#include <llvm/Support/raw_ostream.h>
|
||||||
|
|
||||||
|
using namespace serene;
|
||||||
|
namespace cl = llvm::cl;
|
||||||
|
|
||||||
|
static std::string banner =
|
||||||
|
llvm::formatv("\nSerene Compiler Version {0}"
|
||||||
|
"\nCopyright (C) 2019-2021 "
|
||||||
|
"Sameer Rahmani <lxsameer@gnu.org>\n"
|
||||||
|
"Serene comes with ABSOLUTELY NO WARRANTY;\n"
|
||||||
|
"This is free software, and you are welcome\n"
|
||||||
|
"to redistribute it under certain conditions; \n"
|
||||||
|
"for details take a look at the LICENSE file.\n",
|
||||||
|
SERENE_VERSION);
|
||||||
|
|
||||||
|
static std::string art = "\n";
|
||||||
|
|
||||||
|
static cl::opt<std::string>
|
||||||
|
historyFile("h", cl::desc("The absolute path to the history file to use."),
|
||||||
|
cl::value_desc("filename"), cl::init("~/.serene-repl.history"));
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
initCompiler();
|
||||||
|
registerSereneCLOptions();
|
||||||
|
|
||||||
|
cl::ParseCommandLineOptions(argc, argv, banner);
|
||||||
|
|
||||||
|
llvm::outs() << banner << art;
|
||||||
|
|
||||||
|
auto ctx = makeSereneContext();
|
||||||
|
auto userNS = makeNamespace(*ctx, "user", llvm::None);
|
||||||
|
|
||||||
|
applySereneCLOptions(*ctx);
|
||||||
|
|
||||||
|
// Enable the multi-line mode
|
||||||
|
linenoise::SetMultiLine(true);
|
||||||
|
|
||||||
|
// Set max length of the history
|
||||||
|
linenoise::SetHistoryMaxLen(4);
|
||||||
|
|
||||||
|
// Load history
|
||||||
|
linenoise::LoadHistory(historyFile.c_str());
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
// Read line
|
||||||
|
std::string line;
|
||||||
|
auto quit = linenoise::Readline("user> ", line);
|
||||||
|
|
||||||
|
if (quit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm::outs() << "echo: '" << line << "'"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
// Add text to history
|
||||||
|
linenoise::AddHistory(line.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save history
|
||||||
|
linenoise::SaveHistory(historyFile.c_str());
|
||||||
|
}
|
Loading…
Reference in New Issue