#include <math.h>
#include <signal.h>
#include <string>
#include <stack>
#include <unordered_map>
#ifdef DEBUG
#	include "debug.h"
#endif

namespace algo{
	/* CONST */
	enum class jmp{
		nop,
		jmp,
		je,
		jne
	};


	const char EMPTY_VAL = '0';

	const char true_[] = "TRUE";
	const char false_[] = "FALSE";

	struct frame{
		unsigned bp;
	};

	const char* const standard_vars[] = {
		"eval",
		"ret",
		"argv-0",
		"argv-1",
		"argv-2",
		"argv-3",
		"argv-4",
		"argv-5",
		"argv-6",
		"argv-7",
		"argv-8",
		"argv-9",
		NULL
	};
	/**/

	/* VARS */
	extern std::stack<struct frame> callstack;
	extern std::unordered_map<std::string, std::string> vars;
	/**/

	bool init();

	std::string arref(std::string s);
	std::string deref(std::string s);
	int aint(std::string s);

	void assign(const std::string &name, const std::string& val);

	void do_eval(const std::string &opr1, char oper, const std::string &opr2);

	void pop(unsigned &head);
	void push(const unsigned &head);

	bool jump(unsigned &head, const jmp &do_jump, const std::string &dest, const char &push);
	void call(unsigned &head, const std::string &dest, const bool &is_push);
}
