diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 4 | ||||
-rw-r--r-- | src/Makefile.in | 4 | ||||
-rw-r--r-- | src/algebra/Makefile.in | 4 | ||||
-rw-r--r-- | src/boot/Makefile.in | 4 | ||||
-rw-r--r-- | src/include/Lisp.H | 13 | ||||
-rw-r--r-- | src/include/sexpr.H | 17 | ||||
-rw-r--r-- | src/include/vm.H | 91 | ||||
-rw-r--r-- | src/io/Makefile.in | 4 | ||||
-rw-r--r-- | src/lisp/Makefile.in | 2 | ||||
-rw-r--r-- | src/lisp/core.lisp.in | 5 | ||||
-rw-r--r-- | src/rt/Makefile.in | 4 | ||||
-rw-r--r-- | src/rt/vm.cc | 38 | ||||
-rw-r--r-- | src/syntax/Makefile.in | 4 | ||||
-rw-r--r-- | src/syntax/sexpr.cc | 58 |
14 files changed, 205 insertions, 47 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 0a1f925a..c78e2f3d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2014-11-15 Gabriel Dos Reis <gdr@axiomatics.org> + + * llvm/: New directory. + 2014-10-03 Gabriel Dos Reis <gdr@integrable-solutions.net> * gui/server.cc (Server::input): Replace toAscii() with toLatin1() diff --git a/src/Makefile.in b/src/Makefile.in index 0c6143c5..d2c15738 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.14.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -253,6 +253,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIPO = @LIPO@ +LLVM_CONFIG = @LLVM_CONFIG@ LNKEXT = @LNKEXT@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ @@ -373,6 +374,7 @@ oa_target_texdir = @oa_target_texdir@ oa_targetdir = $(top_builddir)/$(target) oa_use_dynamic_lib = @oa_use_dynamic_lib@ oa_use_libtool_for_shared_lib = @oa_use_libtool_for_shared_lib@ +oa_use_llvm = @oa_use_llvm@ oa_use_x = @oa_use_x@ oldincludedir = @oldincludedir@ open_axiom_installdir = @open_axiom_installdir@ diff --git a/src/algebra/Makefile.in b/src/algebra/Makefile.in index 5e4c5b0a..804b5ec3 100644 --- a/src/algebra/Makefile.in +++ b/src/algebra/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.14.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -437,6 +437,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIPO = @LIPO@ +LLVM_CONFIG = @LLVM_CONFIG@ LNKEXT = @LNKEXT@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ @@ -557,6 +558,7 @@ oa_target_texdir = @oa_target_texdir@ oa_targetdir = @oa_targetdir@ oa_use_dynamic_lib = @oa_use_dynamic_lib@ oa_use_libtool_for_shared_lib = @oa_use_libtool_for_shared_lib@ +oa_use_llvm = @oa_use_llvm@ oa_use_x = @oa_use_x@ oldincludedir = @oldincludedir@ open_axiom_installdir = @open_axiom_installdir@ diff --git a/src/boot/Makefile.in b/src/boot/Makefile.in index c5f9a06e..86bd3aa8 100644 --- a/src/boot/Makefile.in +++ b/src/boot/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.14.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -282,6 +282,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIPO = @LIPO@ +LLVM_CONFIG = @LLVM_CONFIG@ LNKEXT = @LNKEXT@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ @@ -402,6 +403,7 @@ oa_target_texdir = @oa_target_texdir@ oa_targetdir = @oa_targetdir@ oa_use_dynamic_lib = @oa_use_dynamic_lib@ oa_use_libtool_for_shared_lib = @oa_use_libtool_for_shared_lib@ +oa_use_llvm = @oa_use_llvm@ oa_use_x = @oa_use_x@ oldincludedir = @oldincludedir@ open_axiom_installdir = @open_axiom_installdir@ diff --git a/src/include/Lisp.H b/src/include/Lisp.H index 119d07f8..a189dd38 100644 --- a/src/include/Lisp.H +++ b/src/include/Lisp.H @@ -78,6 +78,16 @@ namespace OpenAxiom { struct IntegerOverflow : Diagnostics::BasicError { explicit IntegerOverflow(const std::string&); }; + + // -- Unbound symbol + struct UnboundSymbol : Diagnostics::BasicError { + explicit UnboundSymbol(const std::string&); + }; + + // -- Unbound functiom symbol + struct UnboundFunctionSymbol : Diagnostics::BasicError { + explicit UnboundFunctionSymbol(const std::string&); + }; // -- Anchor maps using AnchorTable = std::map<Ordinal, Value>; @@ -85,14 +95,17 @@ namespace OpenAxiom { // -- Evaluator -- struct Evaluator : VM::BasicContext { Evaluator(); + Value eval(const Sexpr::Syntax*); Package* core_package() { return core; } Package* current_package() { return ns; } Value toplevel_form(const Sexpr::Syntax*); Value make_value(const Sexpr::Syntax*); + Value* lexical_binding(String); Environment* global_environment(); private: Package* core; Package* ns; + Symbol* feature_list; std::list<Environment> env_stack; AnchorTable anchor_map; }; diff --git a/src/include/sexpr.H b/src/include/sexpr.H index d3dafcb7..82dba2a3 100644 --- a/src/include/sexpr.H +++ b/src/include/sexpr.H @@ -146,6 +146,10 @@ namespace OpenAxiom { }; SymbolSyntax(const Lexeme&, Kind); Kind kind() const { return sort; } + const Byte* begin() const { return lexeme().begin(); } + const Byte* end() const { return lexeme().end(); } + std::size_t size() const { return lexeme().size(); } + Byte operator[](std::size_t i) const { return begin()[i]; } void accept(Visitor&) const; private: const Kind sort; @@ -386,19 +390,24 @@ namespace OpenAxiom { }; // -- Reader -- + struct RawInput { + const Byte* start; + const Byte* end; + Ordinal lineno; + }; + struct Reader { struct State { - const Byte* start; - const Byte* end; + RawInput bytes; const Byte* cur; const Byte* line; - Ordinal lineno; Allocator alloc; }; + explicit Reader(const RawInput&); Reader(const Byte*, const Byte*); const Byte* position(Ordinal); - bool at_start() const { return st.cur == st.start; } + bool at_start() const { return st.cur == st.bytes.start; } const Syntax* read(); private: State st; diff --git a/src/include/vm.H b/src/include/vm.H index 9337955b..2c1eafde 100644 --- a/src/include/vm.H +++ b/src/include/vm.H @@ -163,14 +163,22 @@ namespace OpenAxiom { t = 0x10, // distinguished T value }; - constexpr bool to_bool(Value v) { - return v != Value::nil; + // -- Testing for nil value. + constexpr Value null(Value v) { + return v == Value::nil ? Value::t : Value::nil; } + // -- Convert VM Boolean value to C++ view + constexpr bool to_bool(Value v) { return v != Value::nil; } + + // -- Convert a C++ Boolean value to VM view. constexpr Value to_value(bool b) { return b ? Value::t : Value::nil; } + // -- Identity equality. + constexpr Value eq(Value x, Value y) { return to_value(x == y); } + template<typename> struct ValueTrait { }; @@ -194,12 +202,23 @@ namespace OpenAxiom { return ValueBits(v) & ~ValueTrait<T>::tag_mask; } + // -- Arity: number of arguments or forms taken by a function + // or a special operator. + enum class Arity : intptr_t { + variable = -1, // Any number of arguments. + zero = 0, // Exactly no argument. + one = 1, // Exactly one argument. + two = 2, // Exactly two arguments. + three = 3, // Exactly three arguments. + }; + // ------------- // -- Dynamic -- // ------------- // Any internal value is of a class derived from this. internal_type Dynamic { virtual ~Dynamic(); + virtual void format_on(std::ostream&) const = 0; }; template<> @@ -324,10 +343,19 @@ namespace OpenAxiom { return Value(ValueBits(p) | ValueTrait<Pair>::tag); } + // Return true if argument designates a pair. + constexpr Value consp(Value v) { + return to_value(v != Value::nil and v != Value::t and is<Pair>(v)); + } + + inline Value atom(Value v) { + return null(consp(v)); + } + // If `v' designates a pair, return a pointer to its // concrete representation. inline Pair to_pair_if_can(Value v) { - return is<Pair>(v) ? to_pair(v) : nullptr; + return consp(v) == Value::t ? to_pair(v) : nullptr; } Fixnum count_nodes(Pair); @@ -368,14 +396,19 @@ namespace OpenAxiom { struct Package; - enum class SymbolAttribute { + enum class SymbolAttribute : ValueBits { None = 0x0, // No particular attribute. Constant = 0x1, // Symbol defined constant. - SpecialBinding = 0x2, // Symbol declared special. + Special = 0x2, // Symbol declared special. Keyword = 0x4, // A keyword symbol. - SpecialConstant = Constant | SpecialBinding, + SpecialConstant = Constant | Special, }; + constexpr SymbolAttribute + operator&(SymbolAttribute x, SymbolAttribute y) { + return SymbolAttribute(ValueBits(x) & ValueBits(y)); + } + // ------------ // -- Symbol -- // ------------ @@ -387,6 +420,8 @@ namespace OpenAxiom { Package* package; SymbolAttribute attributes; explicit Symbol(InternedString); + void format_on(std::ostream&) const override; + bool has(SymbolAttribute x) const { return (attributes & x) == x; } }; inline Symbol* to_symbol_if_can(Value v) { @@ -397,6 +432,18 @@ namespace OpenAxiom { return to_symbol_if_can(v) != nullptr; } + // -- Test if a value is a symbol. + inline Value symbolp(Value v) { + return to_value(v == Value::nil or v == Value::t or is_symbol(v)); + } + + // -- Test if a value is a keyword symbol. + inline Value keywordp(Value v) { + if (auto sym = to_symbol_if_can(v)) + return to_value(sym->has(SymbolAttribute::Keyword)); + return Value::nil; + } + struct CmpByName { template<typename T> bool operator()(const T& x, const T& y) const { @@ -421,6 +468,7 @@ namespace OpenAxiom { ~Environment(); void bind(Symbol*, Value); + Binding* lookup(InternedString); private: std::vector<Binding> lexical; std::vector<Binding> dynamic; @@ -434,7 +482,9 @@ namespace OpenAxiom { std::set<Symbol, CmpByName> symbols; explicit Package(InternedString); + void format_on(std::ostream&) const override; Symbol* make_symbol(InternedString); + Symbol* find_symbol(InternedString); }; // -------------- @@ -445,6 +495,7 @@ namespace OpenAxiom { Value type; FunctionBase(const Symbol* n, Value t = Value::nil) : name(n), type(t) { } + void format_on(std::ostream&) const override; }; // ------------------------ @@ -452,10 +503,13 @@ namespace OpenAxiom { // ------------------------ // Types for native implementation of builtin operators. struct BasicContext; - using NullaryCode = Value (*)(BasicContext*); - using UnaryCode = Value (*)(BasicContext*, Value); - using BinaryCode = Value (*)(BasicContext*, Value, Value); - using TernaryCode = Value (*)(BasicContext*, Value, Value, Value); + + template<typename... Ts> + using RuntimeOperation = Value(*)(BasicContext*, Ts...); + using NullaryCode = RuntimeOperation<>; + using UnaryCode = RuntimeOperation<Value>; + using BinaryCode = RuntimeOperation<Value, Value>; + using TernaryCode = RuntimeOperation<Value, Value, Value>; template<typename Code> struct BuiltinFunction : FunctionBase { @@ -470,6 +524,23 @@ namespace OpenAxiom { using BinaryOperator = BuiltinFunction<BinaryCode>; using TernaryOperator = BuiltinFunction<TernaryCode>; + // -- Operand stack. + struct OperandStack : private std::vector<Value> { + using super = std::vector<Value>; + using iterator = std::reverse_iterator<super::iterator>; + using super::size; + using super::empty; + iterator begin() { return rbegin(); } + iterator end() { return rend(); } + Value top() { return back(); } + void push(Value v) { push_back(v); } + Value pop() { auto v = back(); pop_back(); return v; } + void operator-=(std::size_t i) { resize(size() - i); } + Value operator[](std::size_t i) { + return super::operator[](size() - i - 1); + } + }; + // ------------------ // -- BasicContext -- // ------------------ diff --git a/src/io/Makefile.in b/src/io/Makefile.in index cc7e0232..49c6ade9 100644 --- a/src/io/Makefile.in +++ b/src/io/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.14.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -250,6 +250,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIPO = @LIPO@ +LLVM_CONFIG = @LLVM_CONFIG@ LNKEXT = @LNKEXT@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ @@ -370,6 +371,7 @@ oa_target_texdir = @oa_target_texdir@ oa_targetdir = @oa_targetdir@ oa_use_dynamic_lib = @oa_use_dynamic_lib@ oa_use_libtool_for_shared_lib = @oa_use_libtool_for_shared_lib@ +oa_use_llvm = @oa_use_llvm@ oa_use_x = @oa_use_x@ oldincludedir = @oldincludedir@ open_axiom_installdir = @open_axiom_installdir@ diff --git a/src/lisp/Makefile.in b/src/lisp/Makefile.in index de4f1f60..3602fe53 100644 --- a/src/lisp/Makefile.in +++ b/src/lisp/Makefile.in @@ -131,6 +131,7 @@ $(oa_target_lispdir)/linkset: $(oa_target_lispdir)/core.$(LNKEXT) oa_optimize_options = @oa_optimize_options@ oa_delay_ffi = @oa_delay_ffi@ +oa_use_llvm = @oa_use_llvm@ oa_editor = @oa_editor@ @@ -161,6 +162,7 @@ edit = sed \ -e 's|@oa_standard_linking[@]|$(oa_standard_linking)|g' \ -e 's|@oa_enable_profiling[@]|$(oa_enable_lisp_profiling)|g' \ -e 's|@oa_delay_ffi[@]|$(oa_delay_ffi)|g' \ + -e 's|@oa_use_llvm[@]|$(oa_use_llvm)|g' \ -e 's|@void_type[@]|$(void_type)|g' \ -e 's|@char_type[@]|$(char_type)|g' \ -e 's|@int_type[@]|$(int_type)|g' \ diff --git a/src/lisp/core.lisp.in b/src/lisp/core.lisp.in index 81fd0f2f..025791f2 100644 --- a/src/lisp/core.lisp.in +++ b/src/lisp/core.lisp.in @@ -180,6 +180,7 @@ "$faslType" "$delayedFFI" + "$useLLVM" "$effectiveFaslType" "$NativeModuleExt" "$systemInstallationDirectory" @@ -437,6 +438,10 @@ (defconstant |$delayedFFI| (eq '@oa_delay_ffi@ 'yes)) +;; True if the host has usable framework +(defconstant |$useLLVM| + (eq '@oa_use_llvm@ 'yes)) + ;; The top level read-eval-print loop function of the base ;; Lisp system we are using. This is a very brittle way ;; of achieving something conceptually simple. diff --git a/src/rt/Makefile.in b/src/rt/Makefile.in index f1dfdf20..61aa22ba 100644 --- a/src/rt/Makefile.in +++ b/src/rt/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.14.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -250,6 +250,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIPO = @LIPO@ +LLVM_CONFIG = @LLVM_CONFIG@ LNKEXT = @LNKEXT@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ @@ -370,6 +371,7 @@ oa_target_texdir = @oa_target_texdir@ oa_targetdir = @oa_targetdir@ oa_use_dynamic_lib = @oa_use_dynamic_lib@ oa_use_libtool_for_shared_lib = @oa_use_libtool_for_shared_lib@ +oa_use_llvm = @oa_use_llvm@ oa_use_x = @oa_use_x@ oldincludedir = @oldincludedir@ open_axiom_installdir = @open_axiom_installdir@ 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; diff --git a/src/syntax/Makefile.in b/src/syntax/Makefile.in index a22f7613..8a9c93c5 100644 --- a/src/syntax/Makefile.in +++ b/src/syntax/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.14.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -250,6 +250,7 @@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIPO = @LIPO@ +LLVM_CONFIG = @LLVM_CONFIG@ LNKEXT = @LNKEXT@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ @@ -370,6 +371,7 @@ oa_target_texdir = @oa_target_texdir@ oa_targetdir = @oa_targetdir@ oa_use_dynamic_lib = @oa_use_dynamic_lib@ oa_use_libtool_for_shared_lib = @oa_use_libtool_for_shared_lib@ +oa_use_llvm = @oa_use_llvm@ oa_use_x = @oa_use_x@ oldincludedir = @oldincludedir@ open_axiom_installdir = @open_axiom_installdir@ diff --git a/src/syntax/sexpr.cc b/src/syntax/sexpr.cc index 97413935..f9d76825 100644 --- a/src/syntax/sexpr.cc +++ b/src/syntax/sexpr.cc @@ -44,7 +44,7 @@ namespace OpenAxiom { namespace Sexpr { static void invalid_character(Reader::State& s) { - auto line = std::to_string(s.lineno); + auto line = std::to_string(s.bytes.lineno); auto column = std::to_string(s.cur - s.line); auto msg = "invalid character on line " + line + " and column " + column; @@ -77,10 +77,10 @@ namespace OpenAxiom { // return true if there are more input characters to consider. static bool skip_blank(Reader::State& s) { - for (bool done = false; s.cur < s.end and not done; ) + for (bool done = false; s.cur < s.bytes.end and not done; ) switch (*s.cur) { case '\n': - ++s.lineno; + ++s.bytes.lineno; s.line = ++s.cur; break; case ' ': case '\t': case '\v': case '\r': case '\f': @@ -88,14 +88,14 @@ namespace OpenAxiom { break; default: done = true; break; } - return s.cur < s.end; + return s.cur < s.bytes.end; } // Move `cur' to end-of-line marker. static void skip_to_eol(Reader::State& s) { // FIXME: properly handle CR+LF. - while (s.cur < s.end and *s.cur != '\n') + while (s.cur < s.bytes.end and *s.cur != '\n') ++s.cur; } @@ -103,7 +103,7 @@ namespace OpenAxiom { // Return true if the character was seen. static bool skip_to_nonescaped_char(Reader::State& s, char c) { - for (bool saw_escape = false; s.cur < s.end; ++s.cur) + for (bool saw_escape = false; s.cur < s.bytes.end; ++s.cur) if (saw_escape) saw_escape = false; else if (*s.cur == '\\') @@ -125,9 +125,9 @@ namespace OpenAxiom { template<typename Pred> static bool advance_while(Reader::State& s, Pred p) { - while (s.cur < s.end and p(*s.cur)) + while (s.cur < s.bytes.end and p(*s.cur)) ++s.cur; - return s.cur < s.end; + return s.cur < s.bytes.end; } // Return true if the character `c' be part of a non-absolute @@ -365,7 +365,11 @@ namespace OpenAxiom { // -- Reader -- Reader::Reader(const Byte* f, const Byte* l) - : st{ f, l, f, f, 1, } + : st{ { f, l, 1 }, f, f } + { } + + Reader::Reader(const RawInput& ri) + : st { ri, ri.start, ri.start } { } static const Syntax* read_sexpr(Reader::State&); @@ -376,7 +380,7 @@ namespace OpenAxiom { auto start = s.cur++; if (not skip_to_quote(s)) syntax_error("missing closing quote sign for string literal"); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_string(t); } @@ -386,7 +390,7 @@ namespace OpenAxiom { auto start = ++s.cur; if (not skip_to_nonescaped_char(s, '|')) syntax_error("missing closing bar sign for an absolute symbol"); - Lexeme t = { { start, s.cur - 1 }, s.lineno }; + Lexeme t = { { start, s.cur - 1 }, s.bytes.lineno }; return s.alloc.make_symbol(SymbolSyntax::absolute, t); } @@ -395,12 +399,12 @@ namespace OpenAxiom { read_maybe_natural(Reader::State& s) { auto start = s.cur; advance_while (s, isdigit); - if (s.cur >= s.end or is_delimiter(*s.cur)) { - Lexeme t = { { start, s.cur }, s.lineno }; + if (s.cur >= s.bytes.end or is_delimiter(*s.cur)) { + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_integer(t); } advance_while(s, identifier_part); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_symbol(SymbolSyntax::ordinary, t); } @@ -409,7 +413,7 @@ namespace OpenAxiom { read_identifier(Reader::State& s) { auto start = s.cur; advance_while(s, identifier_part); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_symbol(SymbolSyntax::ordinary, t); } @@ -418,15 +422,15 @@ namespace OpenAxiom { static const Syntax* read_maybe_signed_number(Reader::State& s) { auto start = s.cur++; - if (s.cur < s.end and isdigit(*s.cur)) { + if (s.cur < s.bytes.end and isdigit(*s.cur)) { advance_while(s, isdigit); - if (s.cur >= s.end or is_delimiter(*s.cur)) { - Lexeme t = { { start, s.cur }, s.lineno }; + if (s.cur >= s.bytes.end or is_delimiter(*s.cur)) { + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_integer(t); } } advance_while(s, identifier_part); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_symbol(SymbolSyntax::ordinary, t); } @@ -434,7 +438,7 @@ namespace OpenAxiom { read_keyword(Reader::State& s) { auto start = s.cur++; advance_while(s, identifier_part); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_symbol(SymbolSyntax::keyword, t); } @@ -491,7 +495,7 @@ namespace OpenAxiom { else syntax_error("syntax error while reading vector elements"); } - if (s.cur >= s.end) + if (s.cur >= s.bytes.end) syntax_error("unfinished literal vector"); else ++s.cur; @@ -504,12 +508,12 @@ namespace OpenAxiom { finish_anchor_or_reference(Reader::State& s) { auto start = s.cur; advance_while(s, isdigit); - if (s.cur >= s.end) + if (s.cur >= s.bytes.end) syntax_error("end-of-input after sharp-number sign"); const Byte c = *s.cur; if (c != '#' and c != '=') syntax_error("syntax error after sharp-number-equal sign"); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; auto n = natural_value(start, s.cur); ++s.cur; if (c == '#') @@ -534,7 +538,7 @@ namespace OpenAxiom { ++s.cur; // skip colon sign. auto start = s.cur; advance_while(s, identifier_part); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_symbol(SymbolSyntax::uninterned, t); } @@ -552,7 +556,7 @@ namespace OpenAxiom { ++s.cur; // skip backslash sign auto start = s.cur; advance_while(s, identifier_part); - Lexeme t = { { start, s.cur }, s.lineno }; + Lexeme t = { { start, s.cur }, s.bytes.lineno }; return s.alloc.make_character(t); } @@ -574,7 +578,7 @@ namespace OpenAxiom { static const Syntax* read_sharp_et_al(Reader::State& s) { - if (++s.cur >= s.end) + if (++s.cur >= s.bytes.end) syntax_error("end-of-input reached after sharp sign"); switch (*s.cur) { case '(': return finish_literal_vector(s); @@ -655,7 +659,7 @@ namespace OpenAxiom { const Byte* Reader::position(Ordinal p) { - st.cur = st.start + p; + st.cur = st.bytes.start + p; st.line = st.cur; // while (st.line > st.start and st.line[-1] != '\n') // --st.line; |