-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,064 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |