Skip to content

Commit

Permalink
Add backward
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjoseph1995 committed Apr 27, 2023
1 parent d1cc690 commit 778a9c3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ add_library(lox_compiler STATIC
error.cpp
parser_state.cpp
native_function.cpp)
target_include_directories(lox_compiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(lox_compiler fmt)

target_include_directories(lox_compiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(lox_compiler fmt Backward::Backward)
target_compile_definitions(lox_compiler PRIVATE
$<$<STREQUAL:${DEBUG_GC_LOGGING},ON>:DEBUG_GC_LOGGING=1>
$<$<STREQUAL:${STRESS_TEST_GC},ON>:STRESS_TEST_GC=1>
Expand Down
11 changes: 7 additions & 4 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef LOX_CPP_ERROR_H
#define LOX_CPP_ERROR_H

#include "fmt/core.h"
#include <backward.hpp>
#include <fmt/core.h>

#include <expected>
#include <stdio.h>
Expand All @@ -14,13 +15,15 @@

auto PrintAssertionMessage(char const* file, int line, char const* function_name, char const* message = nullptr) -> void;

// TODO: Print stack-trace here, research available solutions
// Look into: https://github.com/bombela/backward-cpp/blob/master/backward.hpp
#define unlikely(x) __builtin_expect(!!(x), 0)
#define LOX_ASSERT(expr, ...) \
do { \
if ((!(expr))) [[unlikely]] { \
PrintAssertionMessage(__FILE__, __LINE__, __func__ __VA_OPT__(, ) __VA_ARGS__); \
using namespace backward; \
StackTrace st; \
st.load_here(32); \
Printer p; \
p.print(st); \
__builtin_trap(); \
} \
} while (0)
Expand Down
1 change: 1 addition & 0 deletions tests/test_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by kevin on 8/11/22.
//

#include "error.h"
#include "fmt/core.h"
#include "gtest/gtest.h"
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-restrict")
endif ()


add_subdirectory(backward-cpp)
add_subdirectory(googletest)

0 comments on commit 778a9c3

Please sign in to comment.