// joycub - an interpeter for the programming language Joy
// 
// (c) 2004-2006 Sergey Zubkov 
// $Id: symtab.h,v 1.5 2006/02/27 18:44:01 cubbi Exp $
//
// The Symtab
#ifndef _SYMTAB
#define _SYMTAB 1

#include <functional>
#include <string>
#include <vector>
#include <map>
#include "builtins.h"

class JC_symtab_f {
	private:
		std::string name;
		std::string body;
		void (*f)(JC_Stack&);
	public:
		JC_symtab_f::JC_symtab_f(const std::string &, const std::string &);
		JC_symtab_f::JC_symtab_f(const std::string &, void (*)(JC_Stack&));
		void operator()(JC_Stack &);
		bool is_userdef(void);
		std::string get_body(void);
};

class JC_symtab {
private:
//	std::vector<void (*)( JC_Stack &)> contents;
	std::vector<JC_symtab_f *> contents;
	std::map<const std::string, int> index_to_contents;
	std::map<const std::string, std::string> name_to_help;
	void add_to_symtab(void (*)(JC_Stack&), const std::string &, const std::string &);

public:
	JC_symtab(void);
	void JC_symtab::execute(int, JC_Stack&);
	bool check(const std::string &);
	bool is_userdef(int);
	std::string get_body(int);
	int name_to_opnum(const std::string & );
	void new_userdef(const std::string &, const std::string &);
	vector<std::string> JC_symtab::get_all_names(void) const;
	std::string JC_symtab::get_help(const std::string &);
};

#endif // _SYMTAB
