2010-01-30 07:26:05 +03:00
|
|
|
#ifndef FUNCTION_H_
|
|
|
|
#define FUNCTION_H_
|
|
|
|
|
|
|
|
#include "value.h"
|
2011-09-03 08:10:36 +04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2010-01-30 07:26:05 +03:00
|
|
|
|
|
|
|
class AbstractFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~AbstractFunction();
|
2011-09-03 08:10:36 +04:00
|
|
|
virtual Value evaluate(const class Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const;
|
|
|
|
virtual std::string dump(const std::string &indent, const std::string &name) const;
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class BuiltinFunction : public AbstractFunction
|
|
|
|
{
|
|
|
|
public:
|
2011-09-03 08:10:36 +04:00
|
|
|
typedef Value (*eval_func_t)(const Context *ctx, const std::vector<std::string> &argnames, const std::vector<Value> &args);
|
2010-01-30 07:26:05 +03:00
|
|
|
eval_func_t eval_func;
|
|
|
|
|
|
|
|
BuiltinFunction(eval_func_t f) : eval_func(f) { }
|
|
|
|
virtual ~BuiltinFunction();
|
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
virtual Value evaluate(const Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const;
|
|
|
|
virtual std::string dump(const std::string &indent, const std::string &name) const;
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class Function : public AbstractFunction
|
|
|
|
{
|
|
|
|
public:
|
2011-09-03 08:10:36 +04:00
|
|
|
std::vector<std::string> argnames;
|
|
|
|
std::vector<class Expression*> argexpr;
|
2010-01-30 07:26:05 +03:00
|
|
|
|
|
|
|
Expression *expr;
|
|
|
|
|
|
|
|
Function() { }
|
|
|
|
virtual ~Function();
|
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
virtual Value evaluate(const Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const;
|
|
|
|
virtual std::string dump(const std::string &indent, const std::string &name) const;
|
2010-01-30 07:26:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|