Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 81 additions & 5 deletions compiler+runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ endfunction()
# remains a static lib, since these symbols need to be accessible in the
# compiler's runtime by the JIT compiler.

add_library(
jank_lib STATIC
set(JANK_LIBRARY_COMMON_SOURCES
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to uppercase all of this. All of our CMake variables are lowercase.

src/cpp/jtl/panic.cpp
src/cpp/jtl/assert.cpp
src/cpp/jank/c_api.cpp
Expand Down Expand Up @@ -273,16 +272,24 @@ add_library(
src/cpp/jank/analyze/expr/case.cpp
src/cpp/jank/analyze/local_frame.cpp
src/cpp/jank/analyze/step/force_boxed.cpp

# Native module sources.
src/cpp/clojure/core_native.cpp
src/cpp/clojure/string_native.cpp
src/cpp/jank/perf_native.cpp
)

add_library(
jank_lib STATIC
${JANK_LIBRARY_COMMON_SOURCES}

src/cpp/jank/evaluate.cpp
src/cpp/jank/codegen/llvm_processor.cpp
src/cpp/jank/jit/processor.cpp
src/cpp/jank/aot/processor.cpp

# Native module sources.
src/cpp/clojure/core_native.cpp
src/cpp/clojure/string_native.cpp
src/cpp/jank/compiler_native.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep this one in the static sources? It requires codegen for the only function in there.

src/cpp/jank/perf_native.cpp
)

set_property(TARGET jank_lib PROPERTY OUTPUT_NAME jank)
Expand Down Expand Up @@ -363,6 +370,75 @@ target_link_options(jank_lib PRIVATE ${jank_linker_flags})
set_target_properties(jank_lib PROPERTIES ENABLE_EXPORTS 1)
# ---- libjank.a ----

# ---- libjank_static_rt.a ----
add_library(
jank_lib_static_rt STATIC
${JANK_LIBRARY_COMMON_SOURCES}

src/cpp/jank/evaluate_static_rt.cpp
)

set_property(TARGET jank_lib_static_rt PROPERTY OUTPUT_NAME jank_static_rt)

target_compile_features(jank_lib_static_rt PUBLIC ${jank_cxx_standard})
target_compile_options(jank_lib_static_rt PUBLIC ${jank_common_compiler_flags} ${jank_aot_compiler_flags})

target_include_directories(
jank_lib_static_rt
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/cpp>"
)
target_include_directories(
jank_lib_static_rt
SYSTEM
PUBLIC
${BDWGC_INCLUDE_DIR}
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/nanobench/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/folly>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/bpptree/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/immer>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/magic_enum/include/magic_enum>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/cli11/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/ftxui/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/libzippp/src>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/cpptrace/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/boost-preprocessor/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third-party/boost-multiprecision/include>"
Comment on lines +396 to +406
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to not duplicate all of this between the two libs. Same goes for the linked libs and the common compile options.

)

target_link_libraries(
jank_lib_static_rt PRIVATE
${BDWGC_LIBRARIES}
libzippp::libzippp
cpptrace::cpptrace
# clang
# clang-cpp
# LLVM
ftxui::screen ftxui::dom
OpenSSL::Crypto
Boost::multiprecision
)

# Build a string of all of our JIT compilation flags so we can load them up in the runtime.
set(jank_jit_compile_flags_list ${jank_common_compiler_flags} ${jank_jit_compiler_flags})
list(JOIN jank_jit_compile_flags_list " " jank_jit_compile_flags_str)

set(jank_deps_library_dirs ${LLVM_LIBRARY_DIRS})

target_compile_options(
jank_lib_static_rt
PUBLIC
-DJANK_VERSION="${jank_version}"
-DJANK_JIT_FLAGS="${jank_jit_compile_flags_str}"
-DJANK_CLANG_PREFIX="${CLANG_INSTALL_PREFIX}"
-DJANK_STATIC_RUNTIME
)
target_link_options(jank_lib_static_rt PRIVATE ${jank_linker_flags})

# Symbol exporting for JIT.
set_target_properties(jank_lib_static_rt PROPERTIES ENABLE_EXPORTS 1)
# ---- libjank_static_rt.a ----

# ---- libnanobench.a ----
# nanobench uses a single header for both .hpp and .cpp inclusion, based on
# whether a define has been set. This doesn't work with jank's pre-compiled
Expand Down
1 change: 1 addition & 0 deletions compiler+runtime/include/cpp/jank/aot/processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace jank::aot
native_vector<jtl::immutable_string> define_macros;
native_vector<jtl::immutable_string> libs;

jtl::immutable_string runtime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want an enum for this, not a string. It only has two possible values, whereas the domain of a string is infinite.

jtl::immutable_string output_filename;
};

Expand Down
2 changes: 2 additions & 0 deletions compiler+runtime/include/cpp/jank/runtime/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ namespace jank::runtime
* of previous code. This is essential for REPL use. */
/* TODO: This needs to be synchronized. */
analyze::processor an_prc{ *this };
#ifndef JANK_STATIC_RUNTIME
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's def JANK_DYNAMIC_RUNTIME for dynamic builds and JANK_STATIC_RUNTIME for static builds. Checking for "not static" is both indirect and potentially too broad. For example, if we add a third runtime, this check would also match that.

jit::processor jit_prc;
#endif
/* TODO: This needs to be a dynamic var. */
native_unordered_map<jtl::immutable_string, native_vector<jtl::immutable_string>>
module_dependencies;
Expand Down
6 changes: 2 additions & 4 deletions compiler+runtime/src/cpp/jank/aot/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace jank::aot
, library_dirs{ opts.library_dirs }
, define_macros{ opts.define_macros }
, libs{ opts.libs }
, runtime{ opts.target_runtime }
, output_filename(opts.output_filename)
{
}
Expand Down Expand Up @@ -70,8 +71,6 @@ extern "C" jank_object_ref jank_call0(jank_object_ref f);
sb(R"(
extern "C" jank_object_ref jank_load_clojure_core_native();
extern "C" jank_object_ref jank_load_clojure_string_native();
extern "C" jank_object_ref jank_load_jank_compiler_native();
extern "C" jank_object_ref jank_load_clojure_core();
extern "C" jank_object_ref jank_var_intern_c(char const *, char const *);
extern "C" jank_object_ref jank_deref(jank_object_ref);
extern "C" jank_object_ref jank_call2(jank_object_ref, jank_object_ref, jank_object_ref);
Expand All @@ -94,7 +93,6 @@ int main(int argc, const char** argv)
auto const fn{ [](int const argc, char const **argv) {
jank_load_clojure_core_native();
jank_load_clojure_string_native();
jank_load_jank_compiler_native();

)");

Expand Down Expand Up @@ -203,7 +201,7 @@ int main(int argc, const char** argv)
compiler_args.push_back(strdup(util::format("-L{}", library_dir).c_str()));
}

for(auto const &lib : { "-ljank",
for(auto const &lib : { runtime == "static" ? "-ljank_static_rt" : "-ljank",
/* Default libraries that jank depends on. */
"-lfolly",
"-lgc",
Expand Down
135 changes: 135 additions & 0 deletions compiler+runtime/src/cpp/jank/evaluate_static_rt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include <jank/evaluate.hpp>

namespace jank::evaluate
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed if you just remove the param names.


analyze::expr::function_ref wrap_expression(
analyze::expression_ref const expr,
jtl::immutable_string const &name,
native_vector<runtime::obj::symbol_ref>
params) // NOLINT(performance-unnecessary-value-param): This is a dummy implementation for static runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the comment before the arg, use NOLINTNEXTLINE, use /* */ style comments, and end the comment in a . since comments are documentation.

{
throw std::runtime_error{ "Eval disabled in static runtime." };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define a constexpr C string at the top of the file with this message, instead of duplicating it 24 times.

}

analyze::expr::function_ref wrap_expressions(native_vector<analyze::expression_ref> const &exprs,
analyze::processor const &an_prc,
jtl::immutable_string const &name)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expression_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::def_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::var_deref_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::var_ref_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::call_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::primitive_literal_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::list_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::vector_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::map_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::set_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::local_reference_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::function_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::recur_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::recursion_reference_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::named_recursion_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::let_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::letfn_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::do_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::if_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::throw_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::try_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

runtime::object_ref eval(analyze::expr::case_ref)
{
throw std::runtime_error{ "Eval disabled in static runtime." };
}

#pragma clang diagnostic pop
}
26 changes: 22 additions & 4 deletions compiler+runtime/src/cpp/jank/runtime/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ namespace jank::runtime
}

context::context(util::cli::options const &opts)
: jit_prc{ opts }
, binary_cache_dir{ util::binary_cache_dir(opts.optimization_level,
opts.include_dirs,
opts.define_macros) }
:
#ifndef JANK_STATIC_RUNTIME
jit_prc{ opts }
,
#endif
binary_cache_dir{
util::binary_cache_dir(opts.optimization_level, opts.include_dirs, opts.define_macros)
}
, module_loader{ *this, opts.module_path }
{
auto const core(intern_ns(make_box<obj::symbol>("clojure.core")));
Expand Down Expand Up @@ -160,8 +164,12 @@ namespace jank::runtime
return eval_string(file.expect_ok().view());
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
object_ref context::eval_string(native_persistent_string_view const &code)
#pragma clang diagnostic pop
{
#ifndef JANK_STATIC_RUNTIME
profile::timer const timer{ "rt eval_string" };
read::lex::processor l_prc{ code };
read::parse::processor p_prc{ l_prc.begin(), l_prc.end() };
Expand Down Expand Up @@ -196,10 +204,17 @@ namespace jank::runtime
}

return ret;
#else
throw std::runtime_error{ "Eval disabled in static runtime." };
#endif
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
void context::eval_cpp_string(native_persistent_string_view const &code) const
#pragma clang diagnostic pop
{
#ifndef JANK_STATIC_RUNTIME
profile::timer const timer{ "rt eval_cpp_string" };

/* TODO: Handle all the errors here to avoid exceptions. Also, return a message that
Expand All @@ -215,6 +230,9 @@ namespace jank::runtime
}

auto err(jit_prc.interpreter->Execute(partial_tu));
#else
throw std::runtime_error{ "Eval disabled in static runtime." };
#endif
}

object_ref context::read_string(native_persistent_string_view const &code)
Expand Down
Loading
Loading