From fdc9bf82c50fe51fb03b201d81f022153a1700b4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 26 Jan 2009 10:04:22 +0000 Subject: Make SExp a template generic. git-svn-id: http://svn.drobilla.net/resp/llvm-lisp@20 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- ll.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ll.cpp b/ll.cpp index e6822c6..eb8708a 100644 --- a/ll.cpp +++ b/ll.cpp @@ -48,21 +48,23 @@ struct Error : public std::exception { const char* msg; }; +template +struct Exp { // ::= Atom | (Exp*) + Exp() : type(LIST) {} + Exp(const std::list& l) : type(LIST), list(l) {} + Exp(const A& a) : type(ATOM), atom(a) {} + enum { ATOM, LIST } type; + A atom; + std::list< Exp > 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& l) : type(LIST), list(l) {} - SExp(const std::string& s) : type(ATOM), atom(s) {} - enum { ATOM, LIST } type; - std::string atom; - std::list list; -}; +typedef Exp 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)); } -- cgit v1.2.1