Skip to content

Commit 3f60ab5

Browse files
committed
Merge main branch
1 parent 2d45d67 commit 3f60ab5

File tree

92 files changed

+905
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+905
-159
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ If you'd like your name, company, or logo here, you can
7373
</a>
7474
</p>
7575

76-
<p align="center">
77-
<a href="https://devcarbon.com/">
78-
devcarbon.com
79-
</a>
80-
</p>
81-
8276
<p align="center">
8377
<a href="https://pitch.com/">
8478
Misha Karpenko

compiler+runtime/CMakeLists.txt

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ set(
9595
set(
9696
jank_linker_flags
9797
#-stdlib=libc++ -lc++abi
98+
$<$<PLATFORM_ID:Darwin>:-L/opt/homebrew/lib>
99+
$<$<PLATFORM_ID:Darwin>:${CMAKE_BINARY_DIR}/llvm-install/usr/local/lib/libunwind.a>
100+
$<$<PLATFORM_ID:Darwin>:${CMAKE_BINARY_DIR}/llvm-install/usr/local/lib/libc++abi.a>
98101
)
99102
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
100103
list(APPEND jank_common_compiler_flags #-Werror
@@ -244,7 +247,7 @@ target_link_libraries(
244247
readline
245248
clangInterpreter
246249
Boost::boost
247-
OpenSSL::SSL
250+
$<$<PLATFORM_ID:Darwin>:crypto>
248251
)
249252

250253
jank_hook_llvm(jank_lib)
@@ -255,20 +258,27 @@ list(JOIN jank_jit_compile_flags_list " " jank_jit_compile_flags_str)
255258

256259
# Build a string of all include flags for jank. This will be used for building the PCH at build
257260
# time as well as building the PCH on first run, after installation.
258-
get_target_property(jank_lib_includes jank_lib INCLUDE_DIRECTORIES)
259-
set(jank_lib_includes_str "")
260-
foreach(dir ${jank_lib_includes})
261+
get_target_property(jank_lib_includes_prop jank_lib INCLUDE_DIRECTORIES)
262+
set(jank_lib_includes "")
263+
foreach(dir ${jank_lib_includes_prop})
261264
# System includes are just the path, but normal includes have this format:
262265
# $<BUILD_INTERFACE:/home/jeaye/projects/jank/compiler+runtime/include/cpp>
263266
# We need to strip all of that out.
264267
if(${dir} MATCHES "BUILD_INTERFACE:")
265268
string(REGEX REPLACE "\\$<BUILD_INTERFACE:(.*)>" "\\1" dir_path ${dir})
266-
string(APPEND jank_lib_includes_str "-I${dir_path} ")
269+
list(APPEND jank_lib_includes -I${dir_path})
267270
else()
268-
string(APPEND jank_lib_includes_str "-isystem ${dir} ")
271+
list(APPEND jank_lib_includes -isystem ${dir})
269272
endif()
270273
endforeach()
271274

275+
target_include_directories(
276+
jank_lib
277+
SYSTEM
278+
PUBLIC
279+
"$<$<PLATFORM_ID:Darwin>:/opt/homebrew/include>"
280+
)
281+
272282
target_compile_options(
273283
jank_lib
274284
PUBLIC
@@ -340,6 +350,7 @@ set(
340350
third-party/folly/folly/synchronization/SanitizeThread.cpp
341351
third-party/folly/folly/lang/SafeAssert.cpp
342352
third-party/folly/folly/lang/ToAscii.cpp
353+
third-party/folly/folly/lang/Exception.cpp
343354
third-party/folly/folly/system/ThreadId.cpp
344355
third-party/folly/folly/system/AtFork.cpp
345356
third-party/folly/folly/detail/Futex.cpp
@@ -465,10 +476,24 @@ set(jank_pch_compile_flags_list ${jank_common_compiler_flags} -w)
465476
list(JOIN jank_pch_compile_flags_list " " jank_pch_compile_flags_str)
466477

467478
set(jank_incremental_pch_flag ${CMAKE_BINARY_DIR}/incremental.pch)
479+
480+
separate_arguments(jank_incremental_pch_cxx_flags UNIX_COMMAND ${CMAKE_CXX_FLAGS})
481+
list(REMOVE_ITEM jank_incremental_pch_cxx_flags -fPIC)
468482
add_custom_command(
469-
DEPENDS ${CMAKE_BINARY_DIR}/jank ${CMAKE_SOURCE_DIR}/bin/build-pch
483+
DEPENDS ${CMAKE_BINARY_DIR}/jank
470484
OUTPUT ${jank_incremental_pch_flag}
471-
COMMAND "${CMAKE_SOURCE_DIR}/bin/build-pch" "${CLANG_INSTALL_PREFIX}" "${CMAKE_SOURCE_DIR}/include" "${jank_incremental_pch_flag}" "${jank_pch_compile_flags_str}" "${jank_lib_includes_str}"
485+
COMMAND_EXPAND_LISTS
486+
VERBATIM
487+
COMMAND ${CMAKE_CXX_COMPILER}
488+
${jank_incremental_pch_cxx_flags}
489+
${jank_common_compiler_flags} ${jank_aot_compiler_flags}
490+
${jank_lib_includes}
491+
-Xclang -fincremental-extensions
492+
-Xclang -emit-pch
493+
-x c++-header
494+
-w
495+
-c ${PROJECT_SOURCE_DIR}/include/cpp/jank/prelude.hpp
496+
-o ${jank_incremental_pch_flag}
472497
)
473498
add_custom_target(
474499
jank_incremental_pch

compiler+runtime/bin/build-clang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function build()
5454
cd "${srcdir}/llvm-build"
5555

5656
cmake -DCMAKE_BUILD_TYPE=Release \
57+
-DLLVM_ENABLE_RUNTIMES=all \
5758
-DCMAKE_CXX_STANDARD=20 \
5859
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
5960
-DLLVM_TARGETS_TO_BUILD="host" \

compiler+runtime/bin/build-pch

Lines changed: 0 additions & 21 deletions
This file was deleted.

compiler+runtime/default.nix

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ pkgs.llvmPackages_19.stdenv.mkDerivation {
2626
ninja
2727
];
2828

29-
patchPhase = ''
30-
patchShebangs --host "${pkgs.bash}" bin/build-pch
31-
'';
32-
3329
buildInputs = [
3430
boost
3531
boehmgc

compiler+runtime/doc/build.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ cd -
4141
export CC=$PWD/build/llvm-install/usr/local/bin/clang; export CXX=$PWD/build/llvm-install/usr/local/bin/clang++
4242
```
4343

44+
On macOS also do this:
45+
```
46+
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
47+
```
48+
4449
At this point, you're ready to build jank.
4550

4651

@@ -65,6 +70,12 @@ To make a debug build, specify the build type when configuring.
6570
./bin/watch ./bin/test
6671
```
6772

73+
# Run jank
74+
To run jank's repl, inside of /compiler+runtime, do
75+
```bash
76+
./build/jank repl
77+
```
78+
6879
## Packaging
6980
There's also a script for installing jank and all its necessary dependencies.
7081
Note that this includes a lot of header files, which are necessary for jank's

compiler+runtime/include/cpp/jank/read/lex.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,23 @@ namespace jank::read::lex
4242
integer,
4343
/* Has double data. */
4444
real,
45+
/* Has two integer data. */
46+
ratio,
4547
/* Has string data. */
4648
string,
4749
/* Has string data. */
4850
escaped_string,
4951
eof,
5052
};
5153

54+
struct ratio
55+
{
56+
native_integer numerator{};
57+
native_integer denominator{};
58+
native_bool operator==(ratio const &rhs) const;
59+
native_bool operator!=(ratio const &rhs) const;
60+
};
61+
5262
struct token
5363
{
5464
token() = default;
@@ -65,6 +75,7 @@ namespace jank::read::lex
6575
token(size_t const p, size_t const s, token_kind const k, native_persistent_string_view const);
6676
token(size_t const p, size_t const s, token_kind const k, char const * const);
6777
token(size_t const p, size_t const s, token_kind const k, native_bool const);
78+
token(size_t const p, size_t const s, token_kind const k, ratio const);
6879

6980
native_bool operator==(token const &rhs) const;
7081
native_bool operator!=(token const &rhs) const;
@@ -81,12 +92,18 @@ namespace jank::read::lex
8192
size_t pos{ ignore_pos };
8293
size_t size{ 1 };
8394
token_kind kind{ token_kind::eof };
84-
boost::variant<no_data, native_integer, native_real, native_persistent_string_view, native_bool>
95+
boost::variant<no_data,
96+
native_integer,
97+
native_real,
98+
native_persistent_string_view,
99+
native_bool,
100+
ratio>
85101
data;
86102
};
87103

88104
std::ostream &operator<<(std::ostream &os, token const &t);
89105
std::ostream &operator<<(std::ostream &os, token::no_data const &t);
106+
std::ostream &operator<<(std::ostream &os, ratio const &t);
90107
}
91108

92109
namespace jank::read
@@ -142,6 +159,8 @@ namespace jank::read::lex
142159
size_t pos{};
143160
/* Whether or not the previous token requires a space after it. */
144161
native_bool require_space{};
162+
/* True when seeing a '/' following a number. */
163+
native_bool found_slash_after_number{};
145164
native_persistent_string_view file;
146165
};
147166
}

compiler+runtime/include/cpp/jank/read/parse.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@ namespace jank::runtime
1212
/* TODO: Rename file to processor. */
1313
namespace jank::read::parse
1414
{
15+
static option<char> get_char_from_literal(native_persistent_string const &sv)
16+
{
17+
if(sv.size() == 2)
18+
{
19+
return sv[1];
20+
}
21+
else if(sv == R"(\newline)")
22+
{
23+
return '\n';
24+
}
25+
else if(sv == R"(\space)")
26+
{
27+
return ' ';
28+
}
29+
else if(sv == R"(\tab)")
30+
{
31+
return '\t';
32+
}
33+
else if(sv == R"(\backspace)")
34+
{
35+
return '\b';
36+
}
37+
else if(sv == R"(\formfeed)")
38+
{
39+
return '\f';
40+
}
41+
else if(sv == R"(\return)")
42+
{
43+
return '\r';
44+
}
45+
46+
return none;
47+
}
48+
1549
struct processor
1650
{
1751
struct object_source_info
@@ -73,6 +107,7 @@ namespace jank::read::parse
73107
object_result parse_boolean();
74108
object_result parse_keyword();
75109
object_result parse_integer();
110+
object_result parse_ratio();
76111
object_result parse_real();
77112
object_result parse_string();
78113
object_result parse_escaped_string();

compiler+runtime/include/cpp/jank/runtime/behavior/comparable.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace jank::runtime::behavior
44
{
55
template <typename T>
66
concept comparable = requires(T * const t) {
7-
/* Returns how this object compares to the specified object. Comparison, unlike equality,
7+
/* Returns how this object compares to the specified object. Comparison, unlike equality,
88
* can only be done for objects of the same type. If there's a type mismatch, this function
99
* is expected to throw. There are three cases to handle:
1010
*
@@ -14,6 +14,6 @@ namespace jank::runtime::behavior
1414
*
1515
* For sequences, all values need to be considered for comparison.
1616
*/
17-
{ t->compare(std::declval<object const &>()) } -> std::convertible_to<native_integer>;
17+
{ t->compare(std::declval<object const &>()) } -> std::convertible_to<native_integer>;
1818
};
1919
}

compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace jank::runtime
66
void to_string(char ch, fmt::memory_buffer &buff);
77
void to_string(object_ptr o, fmt::memory_buffer &buff);
88

9+
native_persistent_string to_code_string(object const *o);
10+
void to_code_string(char ch, fmt::memory_buffer &buff);
11+
void to_code_string(object_ptr o, fmt::memory_buffer &buff);
12+
913
template <typename It>
1014
void to_string(It const &begin,
1115
It const &end,
@@ -63,4 +67,62 @@ namespace jank::runtime
6367
runtime::to_string(s, buff);
6468
return native_persistent_string{ buff.data(), buff.size() };
6569
}
70+
71+
template <typename It>
72+
void to_code_string(It const &begin,
73+
It const &end,
74+
native_persistent_string_view const open,
75+
char const close,
76+
fmt::memory_buffer &buff)
77+
{
78+
auto inserter(std::back_inserter(buff));
79+
for(auto const c : open)
80+
{
81+
inserter = c;
82+
}
83+
for(auto i(begin); i != end; ++i)
84+
{
85+
runtime::to_code_string(*i, buff);
86+
auto n(i);
87+
if(++n != end)
88+
{
89+
inserter = ' ';
90+
}
91+
}
92+
inserter = close;
93+
}
94+
95+
template <typename T>
96+
requires behavior::sequenceable<T>
97+
void to_code_string(native_box<T> const s, fmt::memory_buffer &buff)
98+
{
99+
auto inserter(std::back_inserter(buff));
100+
if(!s)
101+
{
102+
fmt::format_to(inserter, "()");
103+
return;
104+
}
105+
106+
fmt::format_to(inserter, "(");
107+
native_bool needs_space{};
108+
for(auto i(s->fresh_seq()); i != nullptr; i = i->next_in_place())
109+
{
110+
if(needs_space)
111+
{
112+
fmt::format_to(inserter, " ");
113+
}
114+
runtime::to_code_string(i->first(), buff);
115+
needs_space = true;
116+
}
117+
fmt::format_to(inserter, ")");
118+
}
119+
120+
template <typename T>
121+
requires behavior::sequenceable<T>
122+
native_persistent_string to_code_string(native_box<T> const s)
123+
{
124+
fmt::memory_buffer buff;
125+
runtime::to_code_string(s, buff);
126+
return native_persistent_string{ buff.data(), buff.size() };
127+
}
66128
}

0 commit comments

Comments
 (0)