2024-03-31 21:10:56 +00:00
|
|
|
#ifndef SK_STATE_H
|
|
|
|
#define SK_STATE_H
|
|
|
|
|
|
|
|
#include "commons.h"
|
|
|
|
#include "value.h"
|
2024-04-02 15:33:31 +00:00
|
|
|
|
2024-03-31 21:10:56 +00:00
|
|
|
#define SK size_t
|
2024-04-02 15:33:31 +00:00
|
|
|
#define SK_NO_ID (-1)
|
2024-03-31 21:10:56 +00:00
|
|
|
|
|
|
|
struct local
|
2024-04-02 15:33:31 +00:00
|
|
|
{
|
|
|
|
int id;
|
|
|
|
size_t addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stack_value
|
2024-03-31 21:10:56 +00:00
|
|
|
{
|
|
|
|
size_t addr;
|
|
|
|
struct value* value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct frame
|
|
|
|
{
|
2024-04-02 15:33:31 +00:00
|
|
|
struct vec stack_values;
|
2024-03-31 21:10:56 +00:00
|
|
|
struct vec locals;
|
|
|
|
struct vec stack;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct state
|
|
|
|
{
|
|
|
|
struct vec frames;
|
|
|
|
size_t addr;
|
|
|
|
};
|
|
|
|
|
2024-04-02 15:33:31 +00:00
|
|
|
void stack_value_init(struct stack_value* self,
|
2024-03-31 21:10:56 +00:00
|
|
|
size_t addr,
|
|
|
|
struct value* new_value);
|
|
|
|
|
2024-04-02 15:33:31 +00:00
|
|
|
void stack_value_free(struct stack_value* self);
|
2024-03-31 21:10:56 +00:00
|
|
|
|
|
|
|
void frame_init(struct frame* self);
|
|
|
|
void frame_free(struct frame* self);
|
|
|
|
|
|
|
|
void state_init(struct state* self);
|
|
|
|
void state_free(struct state* self);
|
|
|
|
|
|
|
|
struct frame* state_frame(struct state* self);
|
|
|
|
void state_push_frame(struct state* self);
|
2024-04-02 20:44:34 +00:00
|
|
|
void state_pop_frame(struct state* self);
|
2024-03-31 21:10:56 +00:00
|
|
|
|
|
|
|
bool state_has_top(struct state* self);
|
|
|
|
SK state_top(struct state* self);
|
|
|
|
struct value* state_try_get_value(struct state* self, SK value);
|
|
|
|
|
2024-03-31 23:32:47 +00:00
|
|
|
SK state_pop(struct state* self);
|
|
|
|
|
2024-04-02 15:33:31 +00:00
|
|
|
SK state_push(struct state* self,
|
|
|
|
TypeKind type,
|
|
|
|
union val val,
|
2024-04-01 12:00:06 +00:00
|
|
|
int line);
|
|
|
|
|
2024-04-01 05:20:42 +00:00
|
|
|
SK state_push_int(struct state* self, int integer, int line);
|
2024-04-01 12:00:06 +00:00
|
|
|
SK state_push_bool(struct state* self, bool boolean, int line);
|
2024-04-01 19:08:42 +00:00
|
|
|
SK state_push_float(struct state* self, double real, int line);
|
2024-04-01 19:42:36 +00:00
|
|
|
SK state_push_string(struct state* self, char const* str, int line);
|
2024-04-02 20:44:34 +00:00
|
|
|
SK state_push_fun(struct state* self, struct fun* fun, int line);
|
2024-04-01 19:08:42 +00:00
|
|
|
|
2024-04-02 15:33:31 +00:00
|
|
|
struct local* state_try_get_local(struct state* self, int id);
|
|
|
|
|
|
|
|
SK state_local_store(struct state* self,
|
|
|
|
int id);
|
|
|
|
|
|
|
|
void state_local_load(struct state* self,
|
|
|
|
int id);
|
|
|
|
|
2024-04-01 19:08:42 +00:00
|
|
|
TypeKind state_common_num_type(struct state* self, SK lhs, SK rhs);
|
2024-04-01 19:42:36 +00:00
|
|
|
TypeKind state_type(struct state* self, SK value);
|
2024-04-01 19:08:42 +00:00
|
|
|
double state_as_real(struct state* self, SK lhs);
|
|
|
|
int state_line(struct state* self, SK lhs);
|
2024-03-31 21:10:56 +00:00
|
|
|
|
2024-03-31 23:32:47 +00:00
|
|
|
SK state_add(struct state* self);
|
|
|
|
SK state_sub(struct state* self);
|
|
|
|
SK state_usub(struct state* self);
|
|
|
|
SK state_mul(struct state* self);
|
|
|
|
SK state_div(struct state* self);
|
|
|
|
SK state_mod(struct state* self);
|
|
|
|
SK state_pow(struct state* self);
|
|
|
|
|
2024-04-01 12:00:06 +00:00
|
|
|
SK state_and(struct state* self);
|
|
|
|
SK state_or(struct state* self);
|
|
|
|
SK state_not(struct state* self);
|
|
|
|
|
2024-04-01 21:33:43 +00:00
|
|
|
SK state_lt(struct state* self);
|
|
|
|
SK state_gt(struct state* self);
|
|
|
|
SK state_eq(struct state* self);
|
|
|
|
|
2024-04-02 20:44:34 +00:00
|
|
|
void state_call(struct state* self);
|
|
|
|
void state_ret(struct state* self);
|
2024-03-31 21:10:56 +00:00
|
|
|
#endif
|