skopy/lib/include/state.h

142 lines
3.6 KiB
C
Raw Normal View History

2024-03-31 21:10:56 +00:00
#ifndef SK_STATE_H
#define SK_STATE_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;
2024-04-05 16:31:11 +00:00
struct fun* fun;
struct frame* parent;
2024-03-31 21:10:56 +00:00
};
struct global
{
int id;
size_t addr;
};
2024-03-31 21:10:56 +00:00
struct state
{
struct vec frames;
size_t addr;
int global_id;
struct vec globals;
struct vec global_values;
2024-03-31 21:10:56 +00:00
};
typedef SK (*nfun_body)(struct state*, struct sym*, struct vec*);
2024-04-06 18:44:58 +00:00
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);
2024-04-07 18:43:13 +00:00
struct frame* frame_new_clone(struct frame* self);
2024-03-31 21:10:56 +00:00
void frame_free(struct frame* self);
void state_init(struct state* self);
2024-04-07 18:43:13 +00:00
struct state* state_new_clone(struct state* self);
2024-03-31 21:10:56 +00:00
void state_free(struct state* self);
SK state_make_ref(struct state* self);
struct value* state_try_deref(struct state* self, size_t ref);
2024-03-31 21:10:56 +00:00
struct frame* state_frame(struct state* self);
void state_push_frame(struct state* self);
void state_pop_frame(struct state* self);
struct value* frame_try_get_value(struct frame* self, SK value);
struct local* frame_try_get_local_by_id(struct frame* self, int id);
2024-03-31 21:10:56 +00:00
SK state_top(struct state* self);
struct value* state_try_get_value(struct state* self, SK value);
2024-04-05 16:31:11 +00:00
struct local* state_try_get_local_by_id(struct state* self, int id);
2024-03-31 21:10:56 +00:00
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);
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);
SK state_push_fun(struct state* self, struct fun* fun, int line);
SK state_push_ref(struct state* self, size_t ref, int line);
2024-04-07 18:43:13 +00:00
SK state_push_mod(struct state* self, struct module* mod, 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);
2024-04-05 16:31:11 +00:00
void state_closure_store(struct state* self,
int id);
2024-04-02 15:33:31 +00:00
void state_local_load(struct state* self,
int id);
void state_global_load(struct state* self,
int id);
2024-04-05 16:31:11 +00:00
void state_closure_load(struct state* self,
int id);
2024-04-07 18:43:13 +00:00
void state_module_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);
int state_add_global(struct state* self,
struct value* value);
struct global* state_try_get_global(struct state* self,
int id);
2024-04-05 16:31:11 +00:00
void state_call(struct state* self, struct fun* fun);
void state_ret(struct state* self);
2024-04-06 18:44:58 +00:00
SK state_add_nfun(struct state* self,
nfun_body body,
int arity);
2024-03-31 21:10:56 +00:00
#endif