Skip to content

Commit

Permalink
resolved build errors, resolver here we come...
Browse files Browse the repository at this point in the history
  • Loading branch information
amanuel2 committed Aug 25, 2024
1 parent b6cab5f commit 1d29d00
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 105 deletions.
37 changes: 20 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0079 NEW)

# Built using Clang 🐐
set(CMAKE_CXX_COMPILER_ID "Clang")
Expand All @@ -12,7 +13,6 @@ find_program(CMAKE_C_COMPILER NAMES clang clang-14 clang-13 clang-12 clang-11 cl
if(NOT CMAKE_CXX_COMPILER)
message(FATAL_ERROR "Clang++ not found")
endif()

if(NOT CMAKE_C_COMPILER)
message(FATAL_ERROR "Clang not found")
endif()
Expand All @@ -21,22 +21,35 @@ project(RiftLang)

# C++20 required
set(CMAKE_CXX_STANDARD 20)

# Set Debug Mode
set(CMAKE_BUILD_TYPE Debug)

# add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# sets targets
include(Options.mk)
include(FindReadline.mk)

# Add the directory containing FindReadline.cmake to the module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")

# Find the Readline package
find_package(Readline REQUIRED)

# "#includes"
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/external)

# Add subdirectories and define targets
add_subdirectory(lib)

# Now that the target is defined, we can link Readline
if(READLINE_FOUND)
target_include_directories(riftlang PRIVATE ${Readline_INCLUDE_DIR})
target_link_libraries(riftlang PRIVATE ${Readline_LIBRARY})
else()
message(FATAL_ERROR "Readline not found")
endif()

enable_testing()
add_subdirectory(tests)

Expand All @@ -45,16 +58,6 @@ add_subdirectory(external/googletest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
include_directories(${gmock_SOURCE_DIR}/include ${gmock_SOURCE_DIR})

# Google {Abseil}
# add_compile_definitions(ABSL_USE_GOOGLE_DEFAULT_NAMESPACE)
# add_subdirectory(external/abseil)
# find_package(absl REQUIRED)
# include_directories(${abseil_SOURCE_DIR})
# target_link_libraries(riftlang absl::base absl::synchronization absl::strings)

#readline library for interpreter
# find_package(Readline REQUIRED)
# if READLINE_FOUND is false then fail
if(NOT READLINE_FOUND)
message(FATAL_ERROR "Readline not found")
endif()
# Debug output
message(STATUS "Readline include dir: ${Readline_INCLUDE_DIR}")
message(STATUS "Readline library: ${Readline_LIBRARY}")
39 changes: 39 additions & 0 deletions FindReadline.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Try to find readline include dirs and libraries

# Variables used by this module:
# Readline_ROOT_DIR - Set this to the root installation of readline

# Variables defined by this module:
# READLINE_FOUND - System has readline, include and lib dirs found
# Readline_INCLUDE_DIR - The readline include directories
# Readline_LIBRARY - The readline library

find_path(Readline_ROOT_DIR
NAMES include/readline/readline.h
)

find_path(Readline_INCLUDE_DIR
NAMES readline/readline.h
HINTS ${Readline_ROOT_DIR}/include
)

find_library(Readline_LIBRARY
NAMES readline
HINTS ${Readline_ROOT_DIR}/lib
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Readline
DEFAULT_MSG
Readline_INCLUDE_DIR
Readline_LIBRARY
)

mark_as_advanced(
Readline_ROOT_DIR
Readline_INCLUDE_DIR
Readline_LIBRARY
)

# Set READLINE_FOUND for backwards compatibility
set(READLINE_FOUND ${Readline_FOUND})
49 changes: 0 additions & 49 deletions FindReadline.mk

This file was deleted.

1 change: 1 addition & 0 deletions include/ast/grmr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <scanner/tokens.hh>
#include <utils/macros.hh>
#include <ast/env.hh>
#include <vector>

using Token = rift::scanner::Token;
using Tokens = std::vector<Token>;
Expand Down
21 changes: 18 additions & 3 deletions include/ast/stmt.hh
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,28 @@ namespace rift
{
public:
using vec_prog = std::vector<std::unique_ptr<Decl<Token>>>;
Block(vec_prog&& decls) : decls(std::move(decls)) {};
vec_prog decls = {};

Block() = default;
Block(const Block<T>& other) { decls = other.decls; }
~Block() = default;
vec_prog decls = {};
Block(vec_prog&& decls) : decls(std::move(decls)) {};
Block(const Block<T>& other) { decls = other.decls; }

T accept(const StmtVisitor<T> &visitor) const override { return visitor.visit_block_stmt(*this); };

Block &operator=(const Block<T> &other)
{
if (this != &other)
{
decls.clear();
decls.reserve(other.decls.size());
for (const auto &decl : other.decls)
{
decls.push_back(decl ? decl->clone() : nullptr);
}
}
return *this;
}
};

template <typename T>
Expand Down
1 change: 1 addition & 0 deletions include/driver/driver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once

// #include <cli/cli.hh>
#include <cstdio>
#include <getopt.h>
#include <readline/readline.h>
#include <readline/history.h>
Expand Down
3 changes: 2 additions & 1 deletion include/reader/reader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include <error/error.hh>
#include <exception>
#include <string>

#include <memory>
#include <vector>
namespace rift
{
namespace reader
Expand Down
2 changes: 1 addition & 1 deletion include/scanner/tokens.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace rift
ELIF,
NIL,
PRINT,
RETURN,
RETURN_TOK, // conflicts with <chardefs.h>
SUPER,
THIS,
TRUE,
Expand Down
1 change: 1 addition & 0 deletions include/utils/macros.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <error/error.hh>
#include <cstring>

#pragma mark - Forward Declarations

Expand Down
3 changes: 2 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set( SOURCES
ast/parser.cc
ast/printer.cc
ast/eval.cc
ast/resolver.cc

# Driver
driver/driver.cc
Expand All @@ -46,7 +47,7 @@ add_executable(
target_compile_options(riftlang PRIVATE -Wno-gcc-compat)
target_compile_definitions(riftlang PRIVATE ABSL_USES_STD_ANY=1)

target_link_libraries(riftlang PRIVATE Readline)
target_link_libraries(riftlang PRIVATE readline)
# target_link_libraries(riftlang absl::base absl::strings absl::hash absl::algorithm absl::memory absl::flat_hash_map absl::container_common absl::container_memory)

add_library(riftlib STATIC ${SOURCES})
Expand Down
1 change: 1 addition & 0 deletions lib/ast/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <error/error.hh>
#include <utils/macros.hh>
#include <ast/env.hh>
#include <vector>

namespace rift
{
Expand Down
4 changes: 2 additions & 2 deletions lib/ast/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace rift
stmt = statement_print();
} else if (consume(Token(TokenType::IF, "if", "if", line))) {
stmt = statement_if();
} else if (consume(Token(TokenType::RETURN))) {
} else if (consume(Token(TokenType::RETURN_TOK))) {
stmt = statement_return();
} else if (consume (Token(TokenType::FOR, "", "", line))) {
stmt = statement_for();
Expand Down Expand Up @@ -568,7 +568,7 @@ namespace rift
case TokenType::IF:
case TokenType::WHILE:
case TokenType::PRINT:
case TokenType::RETURN:
case TokenType::RETURN_TOK:
return;
default:
break;
Expand Down
Loading

0 comments on commit 1d29d00

Please sign in to comment.