//  Copyright (c) 2012-2024 Jakub Filipowicz <jakubf@gmail.com>
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc.,
//  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#ifndef __EVAL_H__
#define __EVAL_H__

#include <inttypes.h>

enum eval_est_type {
	EVAL_AST_N_NONE,
	EVAL_AST_N_ERR,
	EVAL_AST_N_OP,
	EVAL_AST_N_VAL,
	EVAL_AST_N_REG,
	EVAL_AST_N_MEM,
	EVAL_AST_N_RZ,
	EVAL_AST_N_RZ_BIT,
	EVAL_AST_N_ALARM,
	EVAL_AST_N_MC,
	EVAL_AST_N_FLAG,
	EVAL_AST_N_NB,
	EVAL_AST_N_Q,
	EVAL_AST_N_BS,
	EVAL_AST_N_RM,
	EVAL_AST_N_LOC,
};

struct eval_est;

// node creation
void eval_est_delete(struct eval_est *n);
struct eval_est * eval_est_leaf(int type, int16_t val);
struct eval_est * eval_est_op(int oper, struct eval_est *n1, struct eval_est *n2);
struct eval_est * eval_est_mem(struct eval_est *n1, struct eval_est *n2);
struct eval_est * eval_est_loc(int nb, int addr);
struct eval_est * eval_est_err(const char *err);

// node evaluation
int eval_est_eval(struct eval_est *n);
struct eval_est * eval_str_parse(char *str, char **err_msg, int *err_beg, int *err_end);
int eval_str_eval(char *str, char **err_msg, int *err_beg, int *err_end);

#endif

// vim: tabstop=4 shiftwidth=4 autoindent
