skopy/lib/include/state.h

105 lines
2.5 KiB
C

#ifndef SK_STATE_H
#define SK_STATE_H
#include "commons.h"
#include "value.h"
#define SK size_t
#define SK_NO_ID (-1)
struct local
{
int id;
size_t addr;
};
struct stack_value
{
size_t addr;
struct value* value;
};
struct frame
{
struct vec stack_values;
struct vec locals;
struct vec stack;
};
struct state
{
struct vec frames;
size_t addr;
struct vec globals;
};
void stack_value_init(struct stack_value* self,
size_t addr,
struct value* new_value);
void stack_value_free(struct stack_value* self);
void frame_init(struct frame* self);
void frame_free(struct frame* self);
void state_init(struct state* self);
void state_free(struct state* self);
SK state_make_ref(struct state* self);
struct value* state_try_deref(struct state* self, size_t ref);
struct frame* state_frame(struct state* self);
void state_push_frame(struct state* self);
void state_pop_frame(struct state* self);
bool state_has_top(struct state* self);
SK state_top(struct state* self);
struct value* state_try_get_value(struct state* self, SK value);
SK state_pop(struct state* self);
SK state_push(struct state* self,
TypeKind type,
union val val,
int line);
SK state_push_int(struct state* self, int integer, int line);
SK state_push_bool(struct state* self, bool boolean, int line);
SK state_push_float(struct state* self, double real, int line);
SK state_push_string(struct state* self, char const* str, int line);
SK state_push_fun(struct state* self, struct fun* fun, int line);
SK state_push_ref(struct state* self, size_t ref, int line);
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);
TypeKind state_common_num_type(struct state* self, SK lhs, SK rhs);
TypeKind state_type(struct state* self, SK value);
double state_as_real(struct state* self, SK lhs);
int state_line(struct state* self, SK lhs);
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);
SK state_and(struct state* self);
SK state_or(struct state* self);
SK state_not(struct state* self);
SK state_lt(struct state* self);
SK state_gt(struct state* self);
SK state_eq(struct state* self);
void state_call(struct state* self);
void state_ret(struct state* self);
#endif