diff options
author | David Robillard <d@drobilla.net> | 2009-01-26 10:04:22 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-01-26 10:04:22 +0000 |
commit | fdc9bf82c50fe51fb03b201d81f022153a1700b4 (patch) | |
tree | 3ce7507a5652d4433f7569a1b4f39934f36c0476 | |
parent | 607afdbd7a221705bddd48c3b2411777e753c0ae (diff) | |
download | resp-fdc9bf82c50fe51fb03b201d81f022153a1700b4.tar.gz resp-fdc9bf82c50fe51fb03b201d81f022153a1700b4.tar.bz2 resp-fdc9bf82c50fe51fb03b201d81f022153a1700b4.zip |
Make SExp a template generic.
git-svn-id: http://svn.drobilla.net/resp/llvm-lisp@20 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | ll.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -48,21 +48,23 @@ struct Error : public std::exception { const char* msg; }; +template<typename A> +struct Exp { // ::= Atom | (Exp*) + Exp() : type(LIST) {} + Exp(const std::list<Exp>& l) : type(LIST), list(l) {} + Exp(const A& a) : type(ATOM), atom(a) {} + enum { ATOM, LIST } type; + A atom; + std::list< Exp<A> > list; +}; + /*************************************************************************** * S-Expression Lexer :: text -> S-Expressions (SExp) * ***************************************************************************/ struct SyntaxError : public Error { SyntaxError(const char* m) : Error(m) {} }; - -struct SExp { - SExp() : type(LIST) {} - SExp(const std::list<SExp>& l) : type(LIST), list(l) {} - SExp(const std::string& s) : type(ATOM), atom(s) {} - enum { ATOM, LIST } type; - std::string atom; - std::list<SExp> list; -}; +typedef Exp<string> SExp; static SExp readExpression(std::istream& in) @@ -461,7 +463,7 @@ ASTCall::constrain(TEnv& tenv) const { FOREACH(TupV::const_iterator, p, tup) (*p)->constrain(tenv); - AType* retT = tenv.type(this); + AType* retT = tenv.type(this); TupV texp = tuple(tenv.penv.sym("Fn"), tenv.var(), retT, NULL); tenv.constrain(tup[0], new AType(texp)); } |