xo-expression/xo-reader: refactor Environment -> SymbolTable
This commit is contained in:
parent
628fcc44a1
commit
42147bb7c0
10 changed files with 35 additions and 35 deletions
|
|
@ -8,7 +8,7 @@
|
|||
xxx;
|
||||
|
||||
#include "xo/expression/Variable.hpp"
|
||||
#include "xo/expression/LocalEnv.hpp"
|
||||
#include "xo/expression/LocalSymtab.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "xo/expression/LocalEnv.hpp"
|
||||
#include "xo/expression/LocalSymtab.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -34,16 +34,16 @@ namespace xo {
|
|||
**/
|
||||
void upsert(bp<Variable> target);
|
||||
|
||||
bp<Environment> top_envframe() const;
|
||||
void push_envframe(const rp<Environment> & x);
|
||||
rp<Environment> pop_envframe();
|
||||
bp<SymbolTable> top_envframe() const;
|
||||
void push_envframe(const rp<SymbolTable> & x);
|
||||
rp<SymbolTable> pop_envframe();
|
||||
|
||||
void reset_to_toplevel() { stack_.resize(1); }
|
||||
|
||||
/** relative to top-of-stack.
|
||||
* 0 -> top (last in), z-1 -> bottom (first in)
|
||||
**/
|
||||
bp<Environment> operator[](std::size_t i) {
|
||||
bp<SymbolTable> operator[](std::size_t i) {
|
||||
std::size_t z = stack_.size();
|
||||
|
||||
assert(i < z);
|
||||
|
|
@ -51,7 +51,7 @@ namespace xo {
|
|||
return stack_[z - i - 1].get();
|
||||
}
|
||||
|
||||
bp<Environment> operator[](std::size_t i) const {
|
||||
bp<SymbolTable> operator[](std::size_t i) const {
|
||||
std::size_t z = stack_.size();
|
||||
|
||||
assert(i < z);
|
||||
|
|
@ -63,7 +63,7 @@ namespace xo {
|
|||
bool pretty_print(const ppindentinfo & ppii) const;
|
||||
|
||||
private:
|
||||
std::vector<rp<Environment>> stack_;
|
||||
std::vector<rp<SymbolTable>> stack_;
|
||||
};
|
||||
|
||||
inline std::ostream &
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "exprstate.hpp"
|
||||
#include "xo/expression/LocalEnv.hpp"
|
||||
#include "xo/expression/LocalSymtab.hpp"
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -55,8 +55,8 @@ namespace xo {
|
|||
**/
|
||||
class lambda_xs : public exprstate {
|
||||
public:
|
||||
using Environment = xo::scm::Environment;
|
||||
using LocalEnv = xo::scm::LocalEnv;
|
||||
using Environment = xo::scm::SymbolTable;
|
||||
using LocalEnv = xo::scm::LocalSymtab;
|
||||
|
||||
public:
|
||||
lambda_xs();
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "exprstate.hpp"
|
||||
#include "xo/expression/LocalEnv.hpp"
|
||||
#include "xo/expression/LocalSymtab.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class let1_xs : public exprstate {
|
||||
public:
|
||||
using LocalEnv = xo::scm::LocalEnv;
|
||||
using LocalEnv = xo::scm::LocalSymtab;
|
||||
|
||||
public:
|
||||
/** given local definition equivalent to
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace xo {
|
|||
public:
|
||||
using Expression = xo::scm::Expression;
|
||||
using Variable = xo::scm::Variable;
|
||||
using LocalEnv = xo::scm::LocalEnv;
|
||||
using LocalEnv = xo::scm::LocalSymtab;
|
||||
using token_type = token<char>;
|
||||
|
||||
public:
|
||||
|
|
@ -59,13 +59,13 @@ namespace xo {
|
|||
void upsert_var(bp<Variable> x);
|
||||
|
||||
/** @return available variable bindings in current parsing state **/
|
||||
bp<Environment> top_envframe() const;
|
||||
bp<SymbolTable> top_envframe() const;
|
||||
/** @return frame @p i levels from the top **/
|
||||
bp<Environment> lookup_envframe(std::size_t i) const;
|
||||
bp<SymbolTable> lookup_envframe(std::size_t i) const;
|
||||
/** push frame @p x (with new variable bindings) onto environment stack **/
|
||||
void push_envframe(const rp<LocalEnv> & x);
|
||||
/** @return pop innermost environment frame and return it **/
|
||||
rp<Environment> pop_envframe();
|
||||
rp<SymbolTable> pop_envframe();
|
||||
/** @return number of stacked environment frames **/
|
||||
size_t env_stack_size() const { return env_stack_.size(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
#include "pretty_localenv.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::LocalEnv;
|
||||
using xo::scm::LocalSymtab;
|
||||
using xo::scm::Variable;
|
||||
|
||||
namespace scm {
|
||||
bp<Environment>
|
||||
bp<SymbolTable>
|
||||
envframestack::top_envframe() const {
|
||||
std::size_t z = stack_.size();
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
envframestack::push_envframe(const rp<Environment> & frame)
|
||||
envframestack::push_envframe(const rp<SymbolTable> & frame)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag),
|
||||
|
|
@ -38,7 +38,7 @@ namespace xo {
|
|||
stack_[z] = frame;
|
||||
}
|
||||
|
||||
rp<Environment>
|
||||
rp<SymbolTable>
|
||||
envframestack::pop_envframe() {
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
|
@ -48,7 +48,7 @@ namespace xo {
|
|||
if (z > 0) {
|
||||
//std::unique_ptr<exprstate> top = std::move(stack_[z-1]);
|
||||
|
||||
rp<Environment> retval = stack_.at(z-1);
|
||||
rp<SymbolTable> retval = stack_.at(z-1);
|
||||
|
||||
stack_.resize(z-1);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace xo {
|
||||
using xo::scm::Lambda;
|
||||
using xo::scm::LocalEnv;
|
||||
using xo::scm::LocalSymtab;
|
||||
|
||||
namespace scm {
|
||||
const char *
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ namespace xo {
|
|||
using Apply = xo::scm::Apply;
|
||||
using Lambda = xo::scm::Lambda;
|
||||
using LambdaAccess = xo::scm::LambdaAccess;
|
||||
using Environment = xo::scm::Environment;
|
||||
using LocalEnv = xo::scm::LocalEnv;
|
||||
using Environment = xo::scm::SymbolTable;
|
||||
using LocalEnv = xo::scm::LocalSymtab;
|
||||
using Variable = xo::scm::Variable;
|
||||
|
||||
namespace scm {
|
||||
|
|
@ -37,7 +37,7 @@ namespace xo {
|
|||
const rp<Expression> & rhs,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
rp<Environment> parent_env = p_psm->top_envframe().promote();
|
||||
rp<SymbolTable> parent_env = p_psm->top_envframe().promote();
|
||||
rp<Variable> var1 = Variable::make(lhs_name, rhs->valuetype());
|
||||
rp<LocalEnv> let_env = LocalEnv::make1(var1, parent_env);
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ namespace xo {
|
|||
|
||||
std::string lambda_name = Variable::gensym("let1");
|
||||
|
||||
rp<Environment> parent_env = p_psm->top_envframe().promote();
|
||||
rp<SymbolTable> parent_env = p_psm->top_envframe().promote();
|
||||
|
||||
rp<Expression> lambda
|
||||
= Lambda::make_from_env(lambda_name,
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@
|
|||
#include "xo/expression/DefineExpr.hpp"
|
||||
#include "xo/expression/Constant.hpp"
|
||||
#include "xo/expression/ConvertExpr.hpp"
|
||||
#include "xo/expression/GlobalEnv.hpp"
|
||||
//#include "xo/expression/LocalEnv.hpp"
|
||||
#include "xo/expression/GlobalSymtab.hpp"
|
||||
//#include "xo/expression/LocalSymtab.hpp"
|
||||
//#include <regex>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::Expression;
|
||||
using xo::scm::LocalEnv;
|
||||
using xo::scm::LocalSymtab;
|
||||
using xo::reflect::TypeDescr;
|
||||
|
||||
namespace scm {
|
||||
|
|
@ -28,7 +28,7 @@ namespace xo {
|
|||
: psm_{debug_flag}
|
||||
{
|
||||
/* top-level environment. initially empty */
|
||||
rp<Environment> toplevel_env = GlobalEnv::make_empty();
|
||||
rp<SymbolTable> toplevel_env = GlobalSymtab::make_empty();
|
||||
|
||||
this->psm_.env_stack_.push_envframe(toplevel_env);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include "xo/expression/pretty_expression.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::LocalEnv;
|
||||
using xo::scm::LocalSymtab;
|
||||
using xo::scm::Variable;
|
||||
|
||||
namespace scm {
|
||||
|
|
@ -45,12 +45,12 @@ namespace xo {
|
|||
xs_stack_.push_exprstate(std::move(x));
|
||||
}
|
||||
|
||||
bp<Environment>
|
||||
bp<SymbolTable>
|
||||
parserstatemachine::top_envframe() const {
|
||||
return env_stack_.top_envframe();
|
||||
}
|
||||
|
||||
bp<Environment>
|
||||
bp<SymbolTable>
|
||||
parserstatemachine::lookup_envframe(std::size_t i) const {
|
||||
return env_stack_[i];
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ namespace xo {
|
|||
env_stack_.push_envframe(x);
|
||||
}
|
||||
|
||||
rp<Environment>
|
||||
rp<SymbolTable>
|
||||
parserstatemachine::pop_envframe() {
|
||||
scope log(XO_DEBUG(debug_flag_));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue