xo-interpreter: plumb initial global symtab so builtins reach parser
This commit is contained in:
parent
fc2c9a5629
commit
1ae512b261
8 changed files with 27 additions and 11 deletions
|
|
@ -46,10 +46,11 @@ main() {
|
|||
using span_type = xo::scm::span<const char>;
|
||||
|
||||
bool interactive = isatty(STDIN_FILENO);
|
||||
|
||||
bool c_debug_flag = false;
|
||||
|
||||
reader rdr(c_debug_flag);
|
||||
auto toplevel_symtab = GlobalSymtab::make_empty();
|
||||
|
||||
reader rdr(toplevel_symtab, c_debug_flag);
|
||||
rdr.begin_interactive_session();
|
||||
|
||||
string input_str;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,9 @@ main()
|
|||
|
||||
constexpr bool c_debug_flag = false;
|
||||
|
||||
reader rdr(c_debug_flag);
|
||||
rp<GlobalSymtab> toplevel_symtab = GlobalSymtab::make_empty();
|
||||
|
||||
reader rdr(toplevel_symtab, c_debug_flag);
|
||||
rdr.begin_interactive_session();
|
||||
|
||||
string input_str;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "envframestack.hpp"
|
||||
#include "parser_result.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "xo/expression/GlobalSymtab.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -161,9 +162,12 @@ namespace xo {
|
|||
/** create parser in initial state;
|
||||
* parser is ready to receive tokens via @ref include_token
|
||||
*
|
||||
* At least for xo-interpreter will have non-empty symbol table.
|
||||
*
|
||||
* @p toplevel_symtab symbol table.
|
||||
* @p debug_flag true to enable debug logging
|
||||
**/
|
||||
explicit parser(bool debug_flag);
|
||||
parser(const rp<GlobalSymtab> & toplevel_symtab, bool debug_flag);
|
||||
|
||||
bool debug_flag() const { return psm_.debug_flag(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "parser.hpp"
|
||||
#include "reader_error.hpp"
|
||||
#include "xo/expression/Expression.hpp"
|
||||
#include "xo/expression/GlobalSymtab.hpp"
|
||||
#include "xo/expression/pretty_expression.hpp"
|
||||
#include "xo/tokenizer/tokenizer.hpp"
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ namespace xo {
|
|||
using span_type = tokenizer_type::span_type;
|
||||
|
||||
public:
|
||||
explicit reader(bool debug_flag);
|
||||
reader(const rp<GlobalSymtab> & toplevel_symtab, bool debug_flag);
|
||||
|
||||
bool debug_flag() const { return parser_.debug_flag(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,15 @@ namespace xo {
|
|||
namespace scm {
|
||||
// ----- parser -----
|
||||
|
||||
parser::parser(bool debug_flag)
|
||||
parser::parser(const rp<GlobalSymtab> & toplevel_symtab, bool debug_flag)
|
||||
: psm_{debug_flag}
|
||||
{
|
||||
#ifdef OBSOLETE
|
||||
/* top-level environment. initially empty */
|
||||
rp<SymbolTable> toplevel_env = GlobalSymtab::make_empty();
|
||||
#endif
|
||||
|
||||
this->psm_.env_stack_.push_envframe(toplevel_env);
|
||||
this->psm_.env_stack_.push_envframe(toplevel_symtab);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
reader::reader(bool debug_flag) :
|
||||
reader::reader(const rp<GlobalSymtab> & toplevel_symtab, bool debug_flag) :
|
||||
tokenizer_{debug_flag},
|
||||
parser_{debug_flag}
|
||||
parser_{toplevel_symtab, debug_flag}
|
||||
{}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
namespace xo {
|
||||
using parser_type = xo::scm::parser;
|
||||
using token_type = parser_type::token_type;
|
||||
using xo::scm::GlobalSymtab;
|
||||
using xo::scm::exprstatetype;
|
||||
using xo::scm::define_xs;
|
||||
using xo::scm::defexprstatetype;
|
||||
|
|
@ -23,7 +24,9 @@ namespace xo {
|
|||
for (std::size_t i_tc = 0; i_tc < 2; ++i_tc) {
|
||||
constexpr bool c_debug_flag = true;
|
||||
|
||||
parser_type parser(c_debug_flag);
|
||||
rp<GlobalSymtab> toplevel_symtab = GlobalSymtab::make_empty();
|
||||
|
||||
parser_type parser(toplevel_symtab, c_debug_flag);
|
||||
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("i_tc", i_tc));
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
namespace xo {
|
||||
using xo::scm::reader;
|
||||
using xo::scm::GlobalSymtab;
|
||||
|
||||
namespace ut {
|
||||
namespace {
|
||||
|
|
@ -30,7 +31,9 @@ namespace xo {
|
|||
for (std::size_t i_tc = 0; i_tc < s_testcase_v.size(); ++i_tc) {
|
||||
const test_case & tc = s_testcase_v[i_tc];
|
||||
|
||||
reader rdr(c_debug_flag);
|
||||
rp<GlobalSymtab> toplevel_symtab = GlobalSymtab::make_empty();
|
||||
|
||||
reader rdr(toplevel_symtab, c_debug_flag);
|
||||
|
||||
scope log(XO_ENTER2(always, c_debug_flag, "reader.testcase"),
|
||||
xtag("i_tc", i_tc));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue