Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
amanuel2 committed Jun 25, 2024
1 parent 769f260 commit ab125b3
Show file tree
Hide file tree
Showing 8 changed files with 1,064 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
[submodule "external/googletest"]
path = external/googletest
url = https://github.com/google/googletest.git
[submodule "external/abseil"]
path = external/abseil
url = git@github.com:abseil/abseil-cpp.git
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
"exception": "cpp",
"system_error": "cpp",
"thread": "cpp",
"type_traits": "cpp"
"type_traits": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"csignal": "cpp",
"future": "cpp",
"regex": "cpp",
"scoped_allocator": "cpp",
"typeindex": "cpp"
}
}
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ endif()

project(RiftLang)

# C++17 for now might switch to 20
set(CMAKE_CXX_STANDARD 17)
# C++20 required
set(CMAKE_CXX_STANDARD 20)

# Set Debug Mode
set(CMAKE_BUILD_TYPE Debug)
Expand All @@ -42,4 +42,9 @@ add_subdirectory(tests)
# Google {Test&Mock}
add_subdirectory(external/googletest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
include_directories(${gmock_SOURCE_DIR}/include ${gmock_SOURCE_DIR})
include_directories(${gmock_SOURCE_DIR}/include ${gmock_SOURCE_DIR})

# Google {Abseil}
add_subdirectory(external/abseil)
include_directories(${CMAKE_SOURCE_DIR}/external/abseil/absl)
# target_link_libraries(riftlang absl::base absl::synchronization absl::strings)
996 changes: 966 additions & 30 deletions compile_commands.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions external/abseil
Submodule abseil added at e486af
39 changes: 39 additions & 0 deletions include/ast/env.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/////////////////////////////////////////////////////////////
/// ///
/// ██████╗ ██╗███████╗████████╗ ///
/// ██╔══██╗██║██╔════╝╚══██╔══╝ ///
/// ██████╔╝██║█████╗ ██║ ///
/// ██╔══██╗██║██╔══╝ ██║ ///
/// ██║ ██║██║██║ ██║ ///
/// ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ///
/// * RIFT CORE - The official compiler for Rift. ///
/// * Copyright (c) 2024, Rift-Org ///
/// * License terms may be found in the LICENSE file. ///
/// ///
/////////////////////////////////////////////////////////////

#pragma once
#include <absl/container/flat_hash_map.h>
#include <scanner/tokens.hh>

using Token = rift::scanner::Token;
using str_t = std::string;
using strv_t = std::string_view;

namespace rift
{
namespace ast
{
class Environment
{
public:
Environment() = default;
~Environment() = default;

Token getEnv(const strv_t& name) const;
void setEnv(const strv_t& name, const Token& value);
protected:
absl::flat_hash_map<str_t, rift::scanner::Token> values;
};
}
}
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set( SOURCES
utils/literals.cc

# AST
ast/env.cc
ast/parser.cc
ast/printer.cc
ast/eval.cc
Expand All @@ -37,7 +38,6 @@ set( SOURCES
main.cc
)


add_executable(
riftlang
${SOURCES}
Expand Down
38 changes: 38 additions & 0 deletions lib/ast/env.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////
/// ///
/// ██████╗ ██╗███████╗████████╗ ///
/// ██╔══██╗██║██╔════╝╚══██╔══╝ ///
/// ██████╔╝██║█████╗ ██║ ///
/// ██╔══██╗██║██╔══╝ ██║ ///
/// ██║ ██║██║██║ ██║ ///
/// ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ///
/// * RIFT CORE - The official compiler for Rift. ///
/// * Copyright (c) 2024, Rift-Org ///
/// * License terms may be found in the LICENSE file. ///
/// ///
/////////////////////////////////////////////////////////////

#include <ast/env.hh>
#include <error/error.hh>

namespace rift
{
namespace ast
{
Token Environment::getEnv(const strv_t& name) const
{
if (!values.contains(name)) {
rift::error::runTimeError("🛑 Undefined variable '" + std::string(name) + "'");
}
return values.at("env");
}

void Environment::setEnv(const strv_t& name, const Token& value)
{
if (values.contains(name)) {
std::cout << "🟡 [line " << value.line << "] Warn: Variable '" << name << "' already defined." << std::endl;
}
values[name] = value;
}
}
}

0 comments on commit ab125b3

Please sign in to comment.