AST: Make parent type for Function and Lambda
This commit is contained in:
@@ -41,6 +41,7 @@ public:
|
|||||||
virtual bool isNumber() const { return false; }
|
virtual bool isNumber() const { return false; }
|
||||||
virtual bool isValue() const { return false; }
|
virtual bool isValue() const { return false; }
|
||||||
virtual bool isSymbol() const { return false; }
|
virtual bool isSymbol() const { return false; }
|
||||||
|
virtual bool isCallable() const { return false; }
|
||||||
virtual bool isFunction() const { return false; }
|
virtual bool isFunction() const { return false; }
|
||||||
virtual bool isLambda() const { return false; }
|
virtual bool isLambda() const { return false; }
|
||||||
virtual bool isAtom() const { return false; }
|
virtual bool isAtom() const { return false; }
|
||||||
@@ -62,7 +63,7 @@ public:
|
|||||||
bool empty() const { return m_nodes.size() == 0; }
|
bool empty() const { return m_nodes.size() == 0; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Collection() {}
|
Collection() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool isCollection() const override { return true; }
|
virtual bool isCollection() const override { return true; }
|
||||||
@@ -201,9 +202,22 @@ private:
|
|||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
|
class Callable : public ASTNode {
|
||||||
|
public:
|
||||||
|
virtual ~Callable() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Callable() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual bool isCallable() const override { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
using FunctionType = std::function<ASTNodePtr(std::list<ASTNodePtr>)>;
|
using FunctionType = std::function<ASTNodePtr(std::list<ASTNodePtr>)>;
|
||||||
|
|
||||||
class Function final : public ASTNode {
|
class Function final : public Callable {
|
||||||
public:
|
public:
|
||||||
Function(const std::string& name, FunctionType function);
|
Function(const std::string& name, FunctionType function);
|
||||||
virtual ~Function() = default;
|
virtual ~Function() = default;
|
||||||
@@ -220,7 +234,7 @@ private:
|
|||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
class Lambda final : public ASTNode {
|
class Lambda final : public Callable {
|
||||||
public:
|
public:
|
||||||
Lambda(std::vector<std::string> bindings, ASTNodePtr body, EnvironmentPtr env);
|
Lambda(std::vector<std::string> bindings, ASTNodePtr body, EnvironmentPtr env);
|
||||||
virtual ~Lambda() = default;
|
virtual ~Lambda() = default;
|
||||||
@@ -292,6 +306,9 @@ inline bool ASTNode::fastIs<Value>() const { return isValue(); }
|
|||||||
template<>
|
template<>
|
||||||
inline bool ASTNode::fastIs<Symbol>() const { return isSymbol(); }
|
inline bool ASTNode::fastIs<Symbol>() const { return isSymbol(); }
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline bool ASTNode::fastIs<Callable>() const { return isCallable(); }
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline bool ASTNode::fastIs<Function>() const { return isFunction(); }
|
inline bool ASTNode::fastIs<Function>() const { return isFunction(); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user