Skip to content

Commit

Permalink
abstract_context: Make parent contexts const
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Oct 17, 2023
1 parent ca1a8f6 commit 2b84363
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion asteria/compiler/expression_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ generate_code(cow_vector<AIR_Node>& code, const Compiler_Options& opts,
// If a named reference is found, it will not be replaced or hidden by a
// later-declared one.
const Reference* qref;
Abstract_Context* qctx = &ctx;
const Abstract_Context* qctx = &ctx;
uint32_t depth = 0;

for(;;) {
Expand Down
4 changes: 2 additions & 2 deletions asteria/runtime/abstract_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Abstract_Context
do_is_analytic() const noexcept = 0;

virtual
Abstract_Context*
const Abstract_Context*
do_get_parent_opt() const noexcept = 0;

// This function is called when a name is not found in `m_named_refs`.
Expand All @@ -57,7 +57,7 @@ class Abstract_Context
is_analytic() const noexcept
{ return this->do_is_analytic(); }

Abstract_Context*
const Abstract_Context*
get_parent_opt() const noexcept
{ return this->do_get_parent_opt(); }

Expand Down
4 changes: 2 additions & 2 deletions asteria/runtime/air_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ struct Traits_push_local_reference
execute(Executive_Context& ctx, AVMC_Queue::Uparam up, phsh_stringR name)
{
// Get the context.
Executive_Context* qctx = &ctx;
const Executive_Context* qctx = &ctx;
for(uint32_t k = 0; k != up.u32; ++k)
qctx = qctx->get_parent_opt();

Expand Down Expand Up @@ -4888,7 +4888,7 @@ rebind_opt(Abstract_Context& ctx) const
const auto& altr = this->m_stor.as<index_push_local_reference>();

// Get the context.
Abstract_Context* qctx = &ctx;
const Abstract_Context* qctx = &ctx;
for(uint32_t k = 0; k != altr.depth; ++k)
qctx = qctx->get_parent_opt();

Expand Down
6 changes: 3 additions & 3 deletions asteria/runtime/analytic_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Analytic_Context
public Abstract_Context
{
private:
Abstract_Context* m_parent_opt;
const Abstract_Context* m_parent_opt;

public:
// A plain context must have a parent context.
Expand All @@ -37,7 +37,7 @@ class Analytic_Context
do_is_analytic() const noexcept final
{ return true; }

Abstract_Context*
const Abstract_Context*
do_get_parent_opt() const noexcept override
{ return this->m_parent_opt; }

Expand All @@ -48,7 +48,7 @@ class Analytic_Context
public:
ASTERIA_NONCOPYABLE_DESTRUCTOR(Analytic_Context);

Abstract_Context*
const Abstract_Context*
get_parent_opt() const noexcept
{ return this->m_parent_opt; }
};
Expand Down
6 changes: 3 additions & 3 deletions asteria/runtime/executive_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Executive_Context
public Abstract_Context
{
private:
Executive_Context* m_parent_opt;
const Executive_Context* m_parent_opt;

// Store some references to the enclosing function,
// so they are not passed here and there upon each native call.
Expand Down Expand Up @@ -64,7 +64,7 @@ class Executive_Context
do_is_analytic() const noexcept final
{ return false; }

Abstract_Context*
const Abstract_Context*
do_get_parent_opt() const noexcept override
{ return this->m_parent_opt; }

Expand All @@ -80,7 +80,7 @@ class Executive_Context
public:
ASTERIA_NONCOPYABLE_DESTRUCTOR(Executive_Context);

Executive_Context*
const Executive_Context*
get_parent_opt() const noexcept
{ return this->m_parent_opt; }

Expand Down
2 changes: 1 addition & 1 deletion asteria/runtime/global_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Global_Context
do_is_analytic() const noexcept final
{ return false; }

Abstract_Context*
const Abstract_Context*
do_get_parent_opt() const noexcept final
{ return nullptr; }

Expand Down

0 comments on commit 2b84363

Please sign in to comment.