type fixes and bindings + notes on subtyping
This commit is contained in:
parent
7e3c7c88ea
commit
c18f56f7be
28 changed files with 2253 additions and 783 deletions
|
@ -1,33 +0,0 @@
|
|||
#ifndef _MSPH_DECOR_H
|
||||
#define _MSPH_DECOR_H
|
||||
|
||||
struct msph_tp_decor {
|
||||
struct spho_tp *tp;
|
||||
};
|
||||
|
||||
#define TP_DECOR_INIT(ptr) \
|
||||
do { \
|
||||
(ptr)->tp = NULL; \
|
||||
} while (0)
|
||||
|
||||
struct msph_scope_decor {
|
||||
struct spho_scope *sc;
|
||||
};
|
||||
|
||||
#define SCOPE_DECOR_INIT(ptr) \
|
||||
do { \
|
||||
(ptr)->sc = NULL; \
|
||||
} while (0)
|
||||
|
||||
struct msph_nom_decor {
|
||||
struct spho_nom *nom;
|
||||
};
|
||||
|
||||
#define NOM_DECOR_INIT(ptr) \
|
||||
do { \
|
||||
(ptr)->nom = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define GET_SCOPE(ptr) ((ptr)->dec.sc)
|
||||
|
||||
#endif /* _MSPH_DECOR_H */
|
|
@ -7,6 +7,7 @@ int msph_sphophi_init(struct msph_tree_root *);
|
|||
int msph_sphophi_scope(struct msph_tree_root *);
|
||||
int msph_sphophi_nom_lookup(struct msph_tree_root *);
|
||||
int msph_sphophi_tp(struct msph_tree_root *);
|
||||
int msph_sphophi_tp_prebind(struct msph_tree_root *);
|
||||
|
||||
int msph_sphophi(struct msph_tree_root *);
|
||||
|
||||
|
|
|
@ -5,56 +5,13 @@
|
|||
|
||||
#include "msph/common.h"
|
||||
#include "msph/token.h"
|
||||
#include "msph/decor.h"
|
||||
|
||||
/*
|
||||
* TYPES:
|
||||
* Conj
|
||||
* Disj
|
||||
* Impl
|
||||
* Arrow
|
||||
* Box
|
||||
* (Sub)
|
||||
* Forall
|
||||
*
|
||||
* True
|
||||
* False
|
||||
* Var
|
||||
* Nominal
|
||||
*
|
||||
* Record
|
||||
*
|
||||
* DEFINITIONS/DIRECTIVES:
|
||||
* Type definition (type A[X..] = T)
|
||||
* Nominal definition (nominal N)
|
||||
* Member definition (member mname : T)
|
||||
*
|
||||
* {
|
||||
* member a: A
|
||||
* member b: B
|
||||
* }
|
||||
*
|
||||
* Subtyping assert (assert A <: B, asserts that A <: B)
|
||||
*
|
||||
* EXTRA DEFINITIONS
|
||||
* Class definition (class C[...] { ... }, shorthand)
|
||||
*
|
||||
* EXPRESSIONS
|
||||
* Conj
|
||||
* Disj
|
||||
* Impl
|
||||
* Arrow
|
||||
* Box
|
||||
* (Sub)
|
||||
* Forall
|
||||
*
|
||||
* True
|
||||
* False
|
||||
* Var
|
||||
* Nominal
|
||||
*
|
||||
* Trait ({ ... }, creates scoping)
|
||||
*/
|
||||
/* tree decorations */
|
||||
struct msph_decor {
|
||||
struct spho_scope *sc;
|
||||
struct spho_tp *tp;
|
||||
struct spho_nom *nom;
|
||||
};
|
||||
|
||||
#define MSPH_TREE_ROOT 0x0000
|
||||
#define MSPH_TREE_UNIT 0x0001
|
||||
|
@ -70,8 +27,8 @@
|
|||
#define MSPH_TREE_TPEXPR 0x0040
|
||||
#define MSPH_TREE_TRUE 0x0041
|
||||
#define MSPH_TREE_FALSE 0x0042
|
||||
#define MSPH_TREE_NAME 0x0043
|
||||
#define MSPH_TREE_APPL 0x0044
|
||||
#define MSPH_TREE_TPNAME 0x0043
|
||||
#define MSPH_TREE_TPAPPL 0x0044
|
||||
#define MSPH_TREE_TRAIT 0x0045
|
||||
#define MSPH_TREE_CONJ 0x0046
|
||||
#define MSPH_TREE_DISJ 0x0047
|
||||
|
@ -82,11 +39,64 @@
|
|||
#define MSPH_TREE_PAREN 0x004c
|
||||
|
||||
#define MSPH_TREE_IDENT 0x0100
|
||||
#define MSPH_TREE_NAMEDECL 0x0101
|
||||
#define MSPH_TREE_NAMEREF 0x0102
|
||||
|
||||
#define MSPH_TREE_FLAG_OFFSET 16
|
||||
|
||||
#define MSPH_TREE_FLAG_SCOPE (1 << (MSPH_TREE_FLAG_OFFSET))
|
||||
#define MSPH_TREE_FLAG_TP (1 << (MSPH_TREE_FLAG_OFFSET + 1))
|
||||
#define MSPH_TREE_FLAG_NOM (1 << (MSPH_TREE_FLAG_OFFSET + 2))
|
||||
|
||||
#define MSPH_TREE_MASK_FLAGS ((~0x0u) << MSPH_TREE_FLAG_OFFSET)
|
||||
#define MSPH_TREE_MASK_ID ((~0x0u) ^ MSPH_TREE_MASK_FLAGS)
|
||||
|
||||
#define ADD_FLAG(tree, flag) \
|
||||
do { \
|
||||
TREE(tree)->type |= flag; \
|
||||
} while (0)
|
||||
#define HAS_FLAG(tree, flag) (TREE(tree)->type & (flag))
|
||||
|
||||
#define TREE(tree) ((struct msph_tree *)tree)
|
||||
#define TEXT(tree) ((struct msph_tree_text *)tree)
|
||||
#define IDENT(tree) ((struct msph_tree_ident *)tree)
|
||||
#define TPEXPR(tree) ((struct msph_tree_tpexpr *)tree)
|
||||
|
||||
#define HAS_SCOPE(tree) HAS_FLAG((tree), MSPH_TREE_FLAG_SCOPE)
|
||||
#define HAS_TP(tree) HAS_FLAG((tree), MSPH_TREE_FLAG_TP)
|
||||
#define HAS_NOM(tree) HAS_FLAG((tree), MSPH_TREE_FLAG_NOM)
|
||||
|
||||
#define HAS_PARAMS(tpdef) (! STAILQ_EMPTY(&(tpdef)->params))
|
||||
|
||||
#define TREE_ID(tree) (((struct msph_tree *)tree)->type & \
|
||||
MSPH_TREE_MASK_ID)
|
||||
|
||||
#define DECOR(tree) (TREE(tree)->decor)
|
||||
#define SCOPE(tree) (TREE(tree)->decor.sc)
|
||||
#define TP(tree) (TREE(tree)->decor.tp)
|
||||
#define NOM(tree) (TREE(tree)->decor.nom)
|
||||
|
||||
#define DECOR_INIT(tree) \
|
||||
do { \
|
||||
DECOR(tree) = (struct msph_decor) { NULL, NULL, NULL }; \
|
||||
} while (0)
|
||||
|
||||
struct msph_tree {
|
||||
int type;
|
||||
unsigned int type;
|
||||
struct msph_tree *parent;
|
||||
struct msph_decor decor;
|
||||
};
|
||||
|
||||
|
||||
struct msph_tree_text {
|
||||
struct msph_tree hd_tr;
|
||||
struct msph_text_pos pos;
|
||||
};
|
||||
|
||||
struct msph_tree_ident {
|
||||
struct msph_tree_text hd_txt;
|
||||
|
||||
char str[MSPH_IDENT_LEN];
|
||||
};
|
||||
|
||||
struct msph_tree_root;
|
||||
|
@ -100,7 +110,7 @@ struct msph_tree_ident;
|
|||
struct msph_tree_tpexpr;
|
||||
|
||||
struct msph_tree_root {
|
||||
struct msph_tree htr;
|
||||
struct msph_tree hd_tr;
|
||||
|
||||
struct msph_ctx *ctx;
|
||||
|
||||
|
@ -108,155 +118,144 @@ struct msph_tree_root {
|
|||
};
|
||||
|
||||
struct msph_tree_unit {
|
||||
struct msph_tree htr;
|
||||
struct msph_tree hd_tr;
|
||||
|
||||
char name[MSPH_NAME_LEN];
|
||||
struct msph_tree_body *body;
|
||||
struct msph_scope_decor dec;
|
||||
|
||||
STAILQ_ENTRY(msph_tree_unit) entries;
|
||||
};
|
||||
|
||||
struct msph_tree_text {
|
||||
struct msph_tree htr;
|
||||
struct msph_text_pos pos;
|
||||
};
|
||||
|
||||
struct msph_tree_body {
|
||||
struct msph_tree htr;
|
||||
struct msph_tree hd_tr;
|
||||
|
||||
STAILQ_HEAD(msph_tree_dir_l, msph_tree_dir) head;
|
||||
};
|
||||
|
||||
struct msph_tree_dir {
|
||||
struct msph_tree_text htxt;
|
||||
struct msph_tree_text hd_txt;
|
||||
|
||||
STAILQ_ENTRY(msph_tree_dir) entries;
|
||||
};
|
||||
|
||||
struct msph_tree_tpdef {
|
||||
struct msph_tree_dir hdir;
|
||||
struct msph_tree_dir hd_dir;
|
||||
|
||||
struct msph_tree_ident *id;
|
||||
struct msph_tree_namedecl *name;
|
||||
STAILQ_HEAD(msph_tree_namedecl_l, msph_tree_namedecl) params;
|
||||
struct msph_tree_tpexpr *tp;
|
||||
};
|
||||
|
||||
struct msph_tree_nomindecl {
|
||||
struct msph_tree_dir hdir;
|
||||
struct msph_tree_dir hd_dir;
|
||||
|
||||
struct msph_tree_ident *id;
|
||||
struct msph_tree_namedecl *name;
|
||||
};
|
||||
|
||||
struct msph_tree_membdecl {
|
||||
struct msph_tree_dir hdir;
|
||||
struct msph_tree_dir hd_dir;
|
||||
|
||||
struct msph_tree_ident *id;
|
||||
struct msph_tree_tpexpr *tp;
|
||||
struct msph_tree_namedecl *name;
|
||||
struct msph_tree_tpexpr *tp;
|
||||
};
|
||||
|
||||
struct msph_tree_assert {
|
||||
struct msph_tree_dir hdir;
|
||||
struct msph_tree_dir hd_dir;
|
||||
|
||||
struct msph_tree_tpexpr *ltp;
|
||||
struct msph_tree_tpexpr *rtp;
|
||||
};
|
||||
|
||||
struct msph_tree_tpexpr {
|
||||
struct msph_tree_text htxt;
|
||||
struct msph_tree_namedecl {
|
||||
struct msph_tree_ident hd_id;
|
||||
|
||||
STAILQ_ENTRY(msph_tree_tpexpr) entries;
|
||||
|
||||
struct msph_tp_decor dec;
|
||||
STAILQ_ENTRY(msph_tree_namedecl) entries;
|
||||
};
|
||||
|
||||
struct msph_tree_tpexpr {
|
||||
struct msph_tree_text hd_txt;
|
||||
|
||||
STAILQ_ENTRY(msph_tree_tpexpr) entries;
|
||||
};
|
||||
|
||||
struct msph_tree_true {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
};
|
||||
|
||||
struct msph_tree_false {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
};
|
||||
|
||||
struct msph_tree_name {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
|
||||
struct msph_tree_ident *id;
|
||||
struct msph_tree_nameref {
|
||||
struct msph_tree_ident hd_id;
|
||||
};
|
||||
|
||||
struct msph_tree_appl {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpname {
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_ident *id;
|
||||
STAILQ_HEAD(msph_tree_tpexpr_l, msph_tree_tpexpr) head;
|
||||
struct msph_tree_nameref *name;
|
||||
};
|
||||
|
||||
struct msph_tree_tpappl {
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_nameref *name;
|
||||
STAILQ_HEAD(msph_tree_tpexpr_l, msph_tree_tpexpr) args;
|
||||
};
|
||||
|
||||
struct msph_tree_trait {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_body *body;
|
||||
|
||||
struct msph_scope_decor dec;
|
||||
};
|
||||
|
||||
struct msph_tree_conj {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_tpexpr *ltp;
|
||||
struct msph_tree_tpexpr *rtp;
|
||||
};
|
||||
|
||||
struct msph_tree_disj {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_tpexpr *ltp;
|
||||
struct msph_tree_tpexpr *rtp;
|
||||
};
|
||||
|
||||
struct msph_tree_impl {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_tpexpr *ltp;
|
||||
struct msph_tree_tpexpr *rtp;
|
||||
};
|
||||
|
||||
struct msph_tree_arrow {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_tpexpr *ltp;
|
||||
struct msph_tree_tpexpr *rtp;
|
||||
};
|
||||
|
||||
struct msph_tree_box {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_tpexpr *inner;
|
||||
};
|
||||
|
||||
struct msph_tree_forall {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_ident *id;
|
||||
struct msph_tree_tpexpr *inner;
|
||||
|
||||
struct msph_scope_decor dec;
|
||||
struct msph_tree_namedecl *name;
|
||||
struct msph_tree_tpexpr *inner;
|
||||
};
|
||||
|
||||
struct msph_tree_paren {
|
||||
struct msph_tree_tpexpr htpe;
|
||||
struct msph_tree_tpexpr hd_tpe;
|
||||
|
||||
struct msph_tree_tpexpr *inner;
|
||||
};
|
||||
|
||||
struct msph_tree_ident {
|
||||
struct msph_tree_text htxt;
|
||||
|
||||
char str[MSPH_IDENT_LEN];
|
||||
STAILQ_ENTRY(msph_tree_ident) entries;
|
||||
|
||||
struct msph_nom_decor dec;
|
||||
};
|
||||
|
||||
|
||||
struct msph_tree_root *msph_tree_makeroot(struct msph_ctx *);
|
||||
|
||||
|
@ -264,7 +263,4 @@ int msph_tree_parse(struct msph_token_stream *, struct msph_tree_root *);
|
|||
|
||||
ssize_t msph_tree_fprint(FILE *, struct msph_tree *);
|
||||
|
||||
#define T(ptr) ((struct msph_tree *)ptr)
|
||||
#define TXT(ptr) ((struct msph_tree_text *)ptr)
|
||||
|
||||
#endif
|
||||
|
|
54
include/spho/bind.h
Normal file
54
include/spho/bind.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef _SPHO_BIND_H
|
||||
#define _SPHO_BIND_H
|
||||
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include "spho/scope.h"
|
||||
|
||||
#define SPHO_BIND_UNDECLARED 0x0
|
||||
#define SPHO_BIND_UNDEFINED 0x01
|
||||
#define SPHO_BIND_TP 0x11
|
||||
#define SPHO_BIND_TP_OP 0x12
|
||||
#define SPHO_BIND_MEMB_TP 0x13
|
||||
|
||||
union spho_prebind_val {
|
||||
const void *undef;
|
||||
const struct spho_tp *tp;
|
||||
const struct spho_tp_op *op;
|
||||
};
|
||||
|
||||
struct spho_prebind_pair {
|
||||
const struct spho_nom *nom;
|
||||
|
||||
int kind;
|
||||
union spho_prebind_val val;
|
||||
};
|
||||
|
||||
struct spho_prebind {
|
||||
struct spho_scope *sc;
|
||||
|
||||
size_t sz;
|
||||
struct spho_prebind_pair *binds;
|
||||
};
|
||||
|
||||
struct spho_prebind *spho_prebind_create(struct spho_scope *);
|
||||
|
||||
int spho_prebind_undef(struct spho_prebind *, const struct spho_nom *);
|
||||
int spho_prebind_tp(struct spho_prebind *, const struct spho_nom *,
|
||||
const struct spho_tp *);
|
||||
int spho_prebind_tp_op(struct spho_prebind *, const struct spho_nom *,
|
||||
const struct spho_tp_op *);
|
||||
int spho_prebind_member_tp(struct spho_prebind *, const struct spho_nom *,
|
||||
const struct spho_tp *);
|
||||
|
||||
struct spho_prebind *spho_prebind_dupl(const struct spho_prebind *);
|
||||
|
||||
void spho_prebind_free(struct spho_prebind *);
|
||||
|
||||
|
||||
struct spho_bind {
|
||||
struct spho_prebind *loc;
|
||||
struct spho_bind *parent;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -14,6 +14,8 @@
|
|||
#define SPHO_ERR_ARGINVAL 0x010003
|
||||
#define SPHO_ERR_NOM_INUSE 0x020001
|
||||
#define SPHO_ERR_NOM_NOTINSCOPE 0x020002
|
||||
#define SPHO_ERR_BIND_DUPL 0x030001
|
||||
#define SPHO_ERR_BIND_NOTFOUND 0x030002
|
||||
|
||||
#define SPHO_ERR_IS_SYSERR(err) (SPHO_ERR_SYS == err)
|
||||
|
||||
|
@ -41,54 +43,6 @@
|
|||
(ctx)->errline = __LINE__; \
|
||||
} while (0)
|
||||
|
||||
#define SPHO_STRINGIFY(a) #a
|
||||
#define SPHO_MACRO_STR(b) SPHO_STRINGIFY(b)
|
||||
|
||||
#define __LINE__S SPHO_MACRO_STR(__LINE__)
|
||||
|
||||
#define SPHO_PRECOND(cond) \
|
||||
do { \
|
||||
if (! (cond) ) { \
|
||||
fprintf(stderr, "SPHO_PRECOND(" #cond ")@" \
|
||||
__FILE__ ":" __LINE__S \
|
||||
" failed. Aborting.\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SPHO_ASSERT(cond) \
|
||||
do { \
|
||||
if (! (cond) ) { \
|
||||
fprintf(stderr, "SPHO_ASSERT(" #cond ")@" \
|
||||
__FILE__ ":" __LINE__S \
|
||||
" failed. Aborting.\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SPHO_POSTCOND(cond) \
|
||||
do { \
|
||||
if (! (cond) ) { \
|
||||
fprintf(stderr, "SPHO_POSTCOND(" #cond ")@" \
|
||||
__FILE__ ":" __LINE__S \
|
||||
" failed. Aborting.\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef SPHO_ENABLE_DEBUG_PRINT
|
||||
|
||||
#define SPHO_DEBUG_PRINT(fmt, ...) \
|
||||
do { \
|
||||
fprintf(stderr, fmt __VA_OPT__(,) __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#else /* SPHO_ENABLE_DEBUG_PRINT */
|
||||
|
||||
#define SPHO_DEBUG_PRINT(fmt, ...)
|
||||
|
||||
#endif /* SPHO_ENABLE_DEBUG_PRINT */
|
||||
|
||||
#else /* SPHO_DEBUG */
|
||||
|
||||
|
|
|
@ -7,40 +7,18 @@
|
|||
|
||||
#define SPHO_NOM_LEN 128
|
||||
|
||||
/* name */
|
||||
struct spho_nom {
|
||||
char s[SPHO_NOM_LEN];
|
||||
SLIST_ENTRY(spho_nom) next;
|
||||
SLIST_ENTRY(spho_nom) next; // TODO change to allocs
|
||||
};
|
||||
|
||||
SLIST_HEAD(spho_nom_l, spho_nom);
|
||||
|
||||
|
||||
#define TP_KONST_KEY_TRUE 0x43445 /* don't change!!!!! */
|
||||
#define TP_KONST_KEY_FALSE 0x66a57 /* don't change!1! */
|
||||
|
||||
|
||||
struct spho_var {
|
||||
struct spho_nom nom;
|
||||
|
||||
STAILQ_ENTRY(spho_var) next;
|
||||
};
|
||||
|
||||
STAILQ_HEAD(spho_var_l, spho_var);
|
||||
|
||||
struct spho_bind {
|
||||
struct spho_nom nom;
|
||||
struct spho_tpop *op;
|
||||
};
|
||||
|
||||
struct spho_tpop {
|
||||
struct spho_var_l params;
|
||||
struct spho_tp *def;
|
||||
};
|
||||
|
||||
struct spho_rec {
|
||||
struct spho_nom mnom;
|
||||
struct spho_tp *tp;
|
||||
};
|
||||
|
||||
/* type data */
|
||||
struct tp_binop_data {
|
||||
struct spho_tp *left;
|
||||
|
@ -51,11 +29,6 @@ struct tp_unop_data {
|
|||
struct spho_tp *operand;
|
||||
};
|
||||
|
||||
struct tp_binding_data {
|
||||
struct spho_nom *nom;
|
||||
struct spho_tp *bound;
|
||||
};
|
||||
|
||||
struct tp_nom_data {
|
||||
struct spho_nom *nom;
|
||||
};
|
||||
|
@ -70,6 +43,16 @@ struct tp_konst_data {
|
|||
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;
|
||||
|
||||
|
@ -80,22 +63,30 @@ extern const struct tp_konst_data tp_konst_false;
|
|||
union tp_data {
|
||||
struct tp_binop_data binop;
|
||||
struct tp_unop_data unop;
|
||||
struct tp_binding_data bind;
|
||||
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 form;
|
||||
int kind;
|
||||
union tp_data d;
|
||||
|
||||
STAILQ_ENTRY(spho_tp) entries;
|
||||
};
|
||||
|
||||
struct spho_tp_op {
|
||||
struct spho_scope *sc;
|
||||
|
||||
struct spho_scope *op_sc;
|
||||
struct spho_tp *op_tp;
|
||||
};
|
||||
|
||||
STAILQ_HEAD(spho_tp_l, spho_tp);
|
||||
|
||||
struct spho_tp_ptr {
|
||||
|
@ -106,24 +97,33 @@ struct spho_tp_ptr {
|
|||
STAILQ_HEAD(spho_tp_ptr_l, spho_tp_ptr);
|
||||
|
||||
struct spho_tp_alloc {
|
||||
struct spho_tp tp;
|
||||
union {
|
||||
struct spho_tp tp;
|
||||
struct spho_tp_op tp_op;
|
||||
} alloc;
|
||||
|
||||
TAILQ_ENTRY(spho_tp_alloc) allocs;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(spho_tp_alloc_l, spho_tp_alloc);
|
||||
|
||||
|
||||
SLIST_HEAD(spho_scope_l, spho_scope);
|
||||
|
||||
/* defined in spho/bind.h */
|
||||
struct spho_bind;
|
||||
|
||||
struct spho_scope {
|
||||
struct spho_ctx *ctx;
|
||||
struct spho_scope *parent;
|
||||
|
||||
struct spho_scope_l subs;
|
||||
|
||||
size_t n_noms;
|
||||
struct spho_nom_l noms;
|
||||
struct spho_tp_alloc_l tps;
|
||||
|
||||
struct spho_prebind *bind_loc;
|
||||
|
||||
SLIST_ENTRY(spho_scope) next;
|
||||
};
|
||||
|
||||
|
@ -140,9 +140,16 @@ struct spho_scope *spho_scope_create(struct spho_scope *);
|
|||
void spho_scope_destroy(struct spho_scope *);
|
||||
|
||||
struct spho_nom *spho_scope_nom_add(struct spho_scope *, const char *, size_t);
|
||||
int spho_scope_nom_get(struct spho_scope *, const char *, size_t,
|
||||
struct spho_nom **);
|
||||
int spho_scope_nom_lookup(struct spho_scope *, const char *, size_t,
|
||||
struct spho_nom **);
|
||||
int spho_scope_nom_lookup_str(struct spho_scope *, const char *, size_t,
|
||||
struct spho_nom **);
|
||||
int spho_scope_nom_lookup_str_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 */
|
||||
|
|
|
@ -6,4 +6,81 @@
|
|||
#include "spho/err.h"
|
||||
#include "spho/ctx.h"
|
||||
|
||||
|
||||
#define SPHO_UTIL_SLIST_DESTROY(l, elmtype, next, term) \
|
||||
do { \
|
||||
struct elmtype *elm; \
|
||||
while (! SLIST_EMPTY(l)) { \
|
||||
elm = SLIST_FIRST(l); \
|
||||
SLIST_REMOVE_HEAD(l, next); \
|
||||
term(elm); \
|
||||
free(elm); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef SPHO_USE_STRLCPY
|
||||
#define SPHO_STRLCPY(dst, src, len) strlcpy(dst, src, len)
|
||||
#else
|
||||
#define SPHO_STRLCPY(dst, src, len) \
|
||||
(size_t)snprintf(dst, len, "%s", src)
|
||||
#endif /* ifdef SPHO_USE_STRLCPY */
|
||||
|
||||
#define SPHO_STRINGIFY(a) #a
|
||||
#define SPHO_MACRO_STR(b) SPHO_STRINGIFY(b)
|
||||
#define __LINE__S SPHO_MACRO_STR(__LINE__)
|
||||
|
||||
|
||||
#define SPHO_RIP(msg, ...) \
|
||||
do { \
|
||||
fprintf(stderr, "SPHO_RIP(" msg ")@" \
|
||||
__FILE__ ":" __LINE__S \
|
||||
" failed. Aborting.\n" __VA_OPT__(,) __VA_ARGS__); \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef SPHO_DEBUG
|
||||
|
||||
#define SPHO_PRECOND(cond) \
|
||||
do { \
|
||||
if (! (cond) ) { \
|
||||
fprintf(stderr, "SPHO_PRECOND(" #cond ")@" \
|
||||
__FILE__ ":" __LINE__S \
|
||||
" failed. Aborting.\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SPHO_ASSERT(cond) \
|
||||
do { \
|
||||
if (! (cond) ) { \
|
||||
fprintf(stderr, "SPHO_ASSERT(" #cond ")@" \
|
||||
__FILE__ ":" __LINE__S \
|
||||
" failed. Aborting.\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SPHO_POSTCOND(cond) \
|
||||
do { \
|
||||
if (! (cond) ) { \
|
||||
fprintf(stderr, "SPHO_POSTCOND(" #cond ")@" \
|
||||
__FILE__ ":" __LINE__S \
|
||||
" failed. Aborting.\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef SPHO_ENABLE_DEBUG_PRINT
|
||||
#define SPHO_DEBUG_PRINT(fmt, ...) \
|
||||
do { \
|
||||
fprintf(stderr, fmt __VA_OPT__(,) __VA_ARGS__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define SPHO_DEBUG_PRINT(fmt, ...)
|
||||
#endif /* ifdef SPHO_ENABLE_DEBUG_PRINT */
|
||||
|
||||
#endif /* ifdef SPHO_DEBUG */
|
||||
|
||||
#endif
|
||||
|
|
9
include/spho/subt.h
Normal file
9
include/spho/subt.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef _SPHO_SUBT_H
|
||||
#define _SPHO_SUBT_H
|
||||
|
||||
#include "spho/scope.h"
|
||||
|
||||
int spho_is_subt(struct spho_ctx *, const struct spho_tp *,
|
||||
const struct spho_tp *);
|
||||
|
||||
#endif /* ifndef _SPHO_SUBT_H */
|
|
@ -12,20 +12,24 @@
|
|||
#define SPHO_TP_FORM_BOX 0x14
|
||||
#define SPHO_TP_FORM_FORALL 0x15
|
||||
#define SPHO_TP_FORM_APPL 0x16
|
||||
#define SPHO_TP_FORM_MEMBER 0x17
|
||||
#define SPHO_TP_FORM_NOMINAL 0x18
|
||||
|
||||
#define SPHO_TP_FORM_TRUE 0x20
|
||||
#define SPHO_TP_FORM_FALSE 0x21
|
||||
#define SPHO_TP_FORM_NOM 0x23
|
||||
#define SPHO_TP_FORM_NAME 0x23
|
||||
|
||||
#define SPHO_TP_FORM_MEMBER 0x24
|
||||
#define SPHO_TP_FORM_VAR 0x40
|
||||
|
||||
// #define SPHO_TP_FORM_SUB 0x96
|
||||
#define SPHO_TP_FORM_MASK 0xff
|
||||
|
||||
#define SPHO_TP_MOD_FIRST (SPHO_TP_FORM_MASK + 1)
|
||||
|
||||
// #define SPHO_TP_MOD_VAR (SPHO_TP_FLAG_FIRST)
|
||||
// #define SPHO_TP_MOD_NOMINAL (SPHO_TP_FLAG_FIRST << 1)
|
||||
|
||||
#define SPHO_TP_ERR(tp, err) SPHO_ERR((tp)->sc->ctx, (err))
|
||||
|
||||
//struct spho_var *spho_var_create(struct spho_scope *, char *, size_t);
|
||||
//struct spho_var *spho_var_get(struct spho_scope *, char *, size_t);
|
||||
|
||||
struct spho_tp *spho_tp_create_conj(struct spho_scope *, struct spho_tp *,
|
||||
struct spho_tp *);
|
||||
struct spho_tp *spho_tp_create_disj(struct spho_scope *, struct spho_tp *,
|
||||
|
@ -45,10 +49,11 @@ struct spho_tp *spho_tp_create_appl(struct spho_scope *, struct spho_nom *,
|
|||
struct spho_tp_l *);
|
||||
struct spho_tp *spho_tp_create_member(struct spho_scope *, struct spho_nom *,
|
||||
struct spho_tp *);
|
||||
//struct spho_tp *spho_tp_create_const(struct spho_scope *, struct spho_const *);
|
||||
// struct spho_tp *spho_tp_create_var(struct spho_scope *, struct spho_var *);
|
||||
// struct spho_tp *spho_tp_create_sub(struct spho_scope *, struct spho_tp *,
|
||||
// struct spho_tp *);
|
||||
struct spho_tp *spho_tp_create_var(struct spho_scope *, struct spho_nom *);
|
||||
struct spho_tp *spho_tp_create_nominal(struct spho_scope *, struct spho_nom *);
|
||||
|
||||
struct spho_tp_op *spho_tp_op_create(struct spho_scope *,
|
||||
struct spho_scope *, struct spho_tp *);
|
||||
|
||||
void spho_tp_destroy(struct spho_tp *);
|
||||
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef _SPHO_UTIL_H
|
||||
#define _SPHO_UTIL_H
|
||||
|
||||
|
||||
#define SPHO_UTIL_SLIST_DESTROY(l, elmtype, next, term) \
|
||||
do { \
|
||||
struct elmtype *elm; \
|
||||
while (! SLIST_EMPTY(l)) { \
|
||||
elm = SLIST_FIRST(l); \
|
||||
SLIST_REMOVE_HEAD(l, next); \
|
||||
term(elm); \
|
||||
free(elm); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef SPHO_USE_STRLCPY
|
||||
#define SPHO_STRLCPY(dst, src, len) strlcpy(dst, src, len)
|
||||
#else
|
||||
#define SPHO_STRLCPY(dst, src, len) \
|
||||
(size_t)snprintf(dst, len, "%s", src)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue