![]() |
ArkScript
A small, lisp-inspired, functional scripting language
|
#include <LocalsLocator.hpp>
Classes | |
| struct | Scope |
Public Types | |
| enum class | ScopeType { Default , Function , Closure } |
Public Member Functions | |
| LocalsLocator () | |
| Create a new LocalsLocator to track the position of variables in the scope stack. | |
| void | addLocal (const std::string &name) |
| Register a local in the current scope, triggered by a STORE instruction. If the local already exists, it won't be added. | |
| std::optional< std::size_t > | lookupLastScopeByName (const std::string &name) |
| Search for a local in the current scope. Returns std::nullopt in case of closure scopes or if the variable is in a parent scope. | |
| void | createScope (ScopeType type=ScopeType::Default) |
| Create a new scope. | |
| void | deleteScope () |
| Delete the last scope. | |
| void | saveScopeLengthForBranch () |
| Save the current scope length before entering a branch, so that we can ignore variable definitions inside the branch and generate valid indices. | |
| void | dropVarsForBranch () |
| Drop potentially defined variables in the last saved branch. | |
Private Attributes | |
| std::vector< Scope > | m_scopes |
| std::vector< std::size_t > | m_drop_for_conds |
| Needed to drop variables inside if/else branches since they don't have their own scope. | |
Definition at line 20 of file LocalsLocator.hpp.
|
strong |
| Enumerator | |
|---|---|
| Default | |
| Function | |
| Closure | |
Definition at line 23 of file LocalsLocator.hpp.
| Ark::internal::LocalsLocator::LocalsLocator | ( | ) |
Create a new LocalsLocator to track the position of variables in the scope stack.
Definition at line 7 of file LocalsLocator.cpp.
References m_scopes.
| void Ark::internal::LocalsLocator::addLocal | ( | const std::string & | name | ) |
Register a local in the current scope, triggered by a STORE instruction. If the local already exists, it won't be added.
| name | local's name |
Definition at line 13 of file LocalsLocator.cpp.
References m_scopes.
Referenced by Ark::internal::ASTLowerer::compileFunction(), and Ark::internal::ASTLowerer::compileLetMutSet().
| void Ark::internal::LocalsLocator::createScope | ( | ScopeType | type = ScopeType::Default | ) |
Create a new scope.
| type | scope type, default ScopeType::Default |
Definition at line 34 of file LocalsLocator.cpp.
References m_scopes.
Referenced by Ark::internal::ASTLowerer::compileFunction(), and Ark::internal::ASTLowerer::compileWhile().
| void Ark::internal::LocalsLocator::deleteScope | ( | ) |
Delete the last scope.
Definition at line 41 of file LocalsLocator.cpp.
References m_scopes.
Referenced by Ark::internal::ASTLowerer::compileFunction(), and Ark::internal::ASTLowerer::compileWhile().
| void Ark::internal::LocalsLocator::dropVarsForBranch | ( | ) |
Drop potentially defined variables in the last saved branch.
Definition at line 51 of file LocalsLocator.cpp.
References m_drop_for_conds, and m_scopes.
Referenced by Ark::internal::ASTLowerer::compileIf().
| std::optional< std::size_t > Ark::internal::LocalsLocator::lookupLastScopeByName | ( | const std::string & | name | ) |
Search for a local in the current scope. Returns std::nullopt in case of closure scopes or if the variable is in a parent scope.
| name | local's name |
Definition at line 20 of file LocalsLocator.cpp.
References Closure, and m_scopes.
Referenced by Ark::internal::ASTLowerer::compileSymbol().
| void Ark::internal::LocalsLocator::saveScopeLengthForBranch | ( | ) |
Save the current scope length before entering a branch, so that we can ignore variable definitions inside the branch and generate valid indices.
Definition at line 46 of file LocalsLocator.cpp.
References m_drop_for_conds, and m_scopes.
Referenced by Ark::internal::ASTLowerer::compileIf().
|
private |
Needed to drop variables inside if/else branches since they don't have their own scope.
Definition at line 80 of file LocalsLocator.hpp.
Referenced by dropVarsForBranch(), and saveScopeLengthForBranch().
|
private |
Definition at line 79 of file LocalsLocator.hpp.
Referenced by addLocal(), createScope(), deleteScope(), dropVarsForBranch(), LocalsLocator(), lookupLastScopeByName(), and saveScopeLengthForBranch().