diff options
Diffstat (limited to 'src/rt/vm.cc')
-rw-r--r-- | src/rt/vm.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/rt/vm.cc b/src/rt/vm.cc index 7f5cd5fc..4cedc030 100644 --- a/src/rt/vm.cc +++ b/src/rt/vm.cc @@ -33,6 +33,9 @@ // --% Author: Gabriel Dos Reis #include <open-axiom/vm> +#include <iterator> +#include <algorithm> +#include <ostream> namespace OpenAxiom { namespace VM { @@ -46,6 +49,15 @@ namespace OpenAxiom { p->symbol->value = p->value; } + Environment::Binding* + Environment::lookup(InternedString name) { + for (auto& b : lexical) { + if (b.symbol->name == name) + return &b; + } + return nullptr; + } + // -- Dynamic Dynamic::~Dynamic() { } @@ -59,11 +71,24 @@ namespace OpenAxiom { attributes() { } + void Symbol::format_on(std::ostream& os) const { + // FIXME: handle escapes. + std::copy(name->begin(), name->end(), + std::ostream_iterator<char>(os)); + } + // -- Package Package::Package(InternedString s) : name(s) { } + void Package::format_on(std::ostream& os) const { + os << "#<PACKAGE \""; + std::copy(name->begin(), name->end(), + std::ostream_iterator<char>(os)); + os << '"' << '>'; + } + Symbol* Package::make_symbol(InternedString s) { auto sym = const_cast<Symbol*>(&*symbols.insert(Symbol(s)).first); @@ -71,6 +96,19 @@ namespace OpenAxiom { return sym; } + Symbol* + Package::find_symbol(InternedString s) { + auto p = symbols.find(Symbol(s)); + return p == symbols.end() ? nullptr : const_cast<Symbol*>(&*p); + } + + // -- FunctionBase + void FunctionBase::format_on(std::ostream& os) const { + os << "#<FUNCTION "; + name->format_on(os); + os << '>'; + } + Fixnum count_nodes(Pair p) { FixnumBits n = 1; |