log-e-sappho/include/spho/scope.h

160 lines
3.1 KiB
C

#ifndef _SPHO_SCOPE_H
#define _SPHO_SCOPE_H
#include <sys/queue.h>
#include <stdlib.h>
#define SPHO_NOM_LEN 128
union spho_ext_data {
void *ptr;
uint64_t n;
};
/* name */
struct spho_nom {
unsigned int id;
char s[SPHO_NOM_LEN];
union spho_ext_data ext_data;
SLIST_ENTRY(spho_nom) entries;
};
#define TP_KONST_KEY_TRUE 0x43445 /* don't change!!!!! */
#define TP_KONST_KEY_FALSE 0x66a57 /* don't change!1! */
/* type data */
struct tp_binop_data {
struct spho_tp *left;
struct spho_tp *right;
};
struct tp_unop_data {
struct spho_tp *operand;
};
struct tp_nom_data {
struct spho_nom *nom;
};
struct tp_appl_data {
struct spho_nom *nom;
struct spho_tp_l *args;
};
struct tp_konst_data {
int key;
const char *str;
};
struct tp_forall_data {
struct spho_nom *nom;
struct spho_tp *tp;
};
struct tp_member_data {
struct spho_nom *nom;
struct spho_tp *tp;
};
extern const struct tp_konst_data tp_konst_true;
extern const struct tp_konst_data tp_konst_false;
#define SPHO_K_TRUE (&tp_konst_true)
#define SPHO_K_FALSE (&tp_konst_false)
/* type data union */
union tp_data {
struct tp_binop_data binop;
struct tp_unop_data unop;
struct tp_appl_data appl;
struct tp_nom_data nom;
struct tp_konst_data konst;
struct tp_forall_data fa;
struct tp_member_data memb;
};
/* sappho type */
struct spho_tp {
struct spho_scope *sc;
int kind;
union tp_data d;
union spho_ext_data ext_data;
STAILQ_ENTRY(spho_tp) entries;
};
struct spho_tp_op {
struct spho_scope *sc;
struct spho_scope *op_sc;
struct spho_tp *op_tp;
union spho_ext_data ext_data;
};
STAILQ_HEAD(spho_tp_l, spho_tp);
struct spho_tp_alloc {
union {
struct spho_tp tp;
struct spho_tp_op tp_op;
} alloc;
STAILQ_ENTRY(spho_tp_alloc) entries;
};
/* defined in spho/bind.h */
struct spho_bind;
struct spho_scope {
struct spho_ctx *ctx;
struct spho_scope *parent;
STAILQ_HEAD(
spho_scope_l,
spho_scope) subs;
STAILQ_HEAD(
spho_tp_alloc_l,
spho_tp_alloc) tps;
SLIST_HEAD(
spho_nom_l,
spho_nom) noms;
size_t nom_cnt;
struct spho_prebind *bind_loc;
union spho_ext_data ext_data;
STAILQ_ENTRY(spho_scope) entries;
};
#define SPHO_SC_ERR(sc, err) SPHO_ERR((sc)->ctx, (err))
void spho_scope_init(struct spho_scope *, struct spho_ctx *,
struct spho_scope *);
void spho_scope_cleanup(struct spho_scope *);
struct spho_scope *spho_scope_global(struct spho_ctx *);
struct spho_scope *spho_scope_create_subscope(struct spho_scope *);
void spho_scope_free(struct spho_scope *);
struct spho_nom *spho_scope_nom_add(struct spho_scope *, const char *, size_t);
int spho_scope_nom_lookup(struct spho_scope *, const char *, size_t,
struct spho_nom **);
int spho_scope_nom_lookup_strict(struct spho_scope *, const char *,
size_t, struct spho_nom **);
int spho_scope_prebind_init(struct spho_scope *);
int spho_scope_prebind_tp(struct spho_scope *, struct spho_nom *,
struct spho_tp *);
int spho_scope_prebind_tp_op(struct spho_scope *, struct spho_nom *,
struct spho_tp_op *);
int spho_scope_prebind_undef(struct spho_scope *, struct spho_nom *);
#endif /* _SPHO_SCOPE_H */