recursive lockstep example
This commit is contained in:
parent
26d0d3158f
commit
e036fa16f8
15 changed files with 536 additions and 133 deletions
|
@ -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_bind_static_tp_names(struct msph_tree_root *);
|
||||
|
||||
int msph_sphophi(struct msph_tree_root *);
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@
|
|||
* Trait ({ ... }, creates scoping)
|
||||
*/
|
||||
|
||||
#define MSPH_TREE_ROOT 0x0000
|
||||
#define MSPH_TREE_UNIT 0x0001
|
||||
#define MSPH_TREE_ROOT (0x0000 | MSPH_TREE_FLAG_SCOPE)
|
||||
#define MSPH_TREE_UNIT (0x0001 | MSPH_TREE_FLAG_SCOPE)
|
||||
|
||||
#define MSPH_TREE_BODY 0x0010
|
||||
|
||||
|
@ -72,17 +72,25 @@
|
|||
#define MSPH_TREE_FALSE 0x0042
|
||||
#define MSPH_TREE_NAME 0x0043
|
||||
#define MSPH_TREE_APPL 0x0044
|
||||
#define MSPH_TREE_TRAIT 0x0045
|
||||
#define MSPH_TREE_TRAIT (0x0045 | MSPH_TREE_FLAG_SCOPE)
|
||||
#define MSPH_TREE_CONJ 0x0046
|
||||
#define MSPH_TREE_DISJ 0x0047
|
||||
#define MSPH_TREE_IMPL 0x0048
|
||||
#define MSPH_TREE_ARROW 0x0049
|
||||
#define MSPH_TREE_BOX 0x004a
|
||||
#define MSPH_TREE_FORALL 0x004b
|
||||
#define MSPH_TREE_FORALL (0x004b | MSPH_TREE_FLAG_SCOPE)
|
||||
#define MSPH_TREE_PAREN 0x004c
|
||||
|
||||
#define MSPH_TREE_IDENT 0x0100
|
||||
#define MSPH_TREE_IDENT 0x0080
|
||||
|
||||
#define MSPH_TREE_MASK_ID 0x0fff
|
||||
#define MSPH_TREE_MASK_FLAGS 0xf000
|
||||
|
||||
#define MSPH_TREE_FLAG_SCOPE 0x1000
|
||||
#define MSPH_TREE_FLAG_STATIC_BIND 0x2000
|
||||
|
||||
#define MSPH_TREE_SCOPE(type) (type & MSPH_TREE_FLAG_SCOPE)
|
||||
#define MSPH_TREE_STATIC_BIND(type) (type & MSPH_TREE_FLAG_STATIC_BIND)
|
||||
|
||||
struct msph_tree {
|
||||
int type;
|
||||
|
@ -145,6 +153,7 @@ struct msph_tree_nomindecl {
|
|||
struct msph_tree_dir hdir;
|
||||
|
||||
struct msph_tree_ident *id;
|
||||
struct msph_tree_tpexpr *tp;
|
||||
};
|
||||
|
||||
struct msph_tree_membdecl {
|
||||
|
@ -257,7 +266,6 @@ struct msph_tree_ident {
|
|||
struct msph_nom_decor dec;
|
||||
};
|
||||
|
||||
|
||||
struct msph_tree_root *msph_tree_makeroot(struct msph_ctx *);
|
||||
|
||||
int msph_tree_parse(struct msph_token_stream *, struct msph_tree_root *);
|
||||
|
|
|
@ -5,24 +5,49 @@
|
|||
|
||||
#include "spho/scope.h"
|
||||
|
||||
#define SPHO_BIND_KIND_TP 1
|
||||
#define SPHO_BIND_KIND_TPOP 2
|
||||
|
||||
union spho_bound {
|
||||
struct spho_tp *tp;
|
||||
struct spho_tpop *op;
|
||||
};
|
||||
|
||||
struct spho_binding {
|
||||
struct spho_nom *nom;
|
||||
struct spho_tp *tp;
|
||||
|
||||
STAILQ_ENTRY(spho_binding) entries;
|
||||
int kind;
|
||||
union spho_bound bound;
|
||||
};
|
||||
|
||||
struct spho_bind_scope {
|
||||
struct spho_scope *sc;
|
||||
|
||||
size_t cap_bds;
|
||||
size_t n_bds;
|
||||
struct spho_binding *bds;
|
||||
};
|
||||
|
||||
struct spho_bind {
|
||||
STAILQ_HEAD(spho_binding_l, spho_binding) head;
|
||||
|
||||
struct spho_ctx *ctx;
|
||||
struct spho_bind_scope *binder;
|
||||
struct spho_bind *parent;
|
||||
};
|
||||
|
||||
struct spho_bind_scope *spho_bind_scope_create(struct spho_scope *);
|
||||
|
||||
struct spho_bind *spho_bind_create(struct spho_ctx *, struct spho_bind *);
|
||||
int spho_bind_scope_add_tp(struct spho_bind_scope *, struct spho_nom *,
|
||||
struct spho_tp *);
|
||||
int spho_bind_scope_add_tpop(struct spho_bind_scope *, struct spho_nom *,
|
||||
struct spho_tpop *);
|
||||
|
||||
int spho_bind_add(struct spho_bind *, struct spho_nom *, struct spho_tp *);
|
||||
void spho_bind_scope_destroy(struct spho_bind_scope *);
|
||||
|
||||
struct spho_bind *spho_bind_create(struct spho_ctx *, struct spho_bind_scope *,
|
||||
struct spho_bind *);
|
||||
|
||||
int spho_bind_lkp(int, struct spho_bind *, struct spho_nom *,
|
||||
union spho_bound **);
|
||||
|
||||
void spho_bind_destroy(struct spho_bind *);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#define SPHO_ERR_ARGINVAL 0x010003
|
||||
#define SPHO_ERR_NOM_INUSE 0x020001
|
||||
#define SPHO_ERR_NOM_NOTINSCOPE 0x020002
|
||||
#define SPHO_ERR_BIND_EXISTS 0x030001
|
||||
|
||||
#define SPHO_ERR_IS_SYSERR(err) (SPHO_ERR_SYS == err)
|
||||
|
||||
|
|
|
@ -15,10 +15,6 @@ struct spho_nom {
|
|||
|
||||
SLIST_HEAD(spho_nom_l, spho_nom);
|
||||
|
||||
/* binding
|
||||
*
|
||||
* bindings needs to be able to change, so we do not store it in names directly.
|
||||
*/
|
||||
|
||||
#define TP_KONST_KEY_TRUE 0x43445 /* don't change!!!!! */
|
||||
#define TP_KONST_KEY_FALSE 0x66a57 /* don't change!1! */
|
||||
|
@ -33,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;
|
||||
};
|
||||
|
@ -52,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;
|
||||
|
||||
|
@ -62,10 +63,11 @@ 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 */
|
||||
|
@ -95,6 +97,10 @@ struct spho_tp_alloc {
|
|||
|
||||
TAILQ_HEAD(spho_tp_alloc_l, spho_tp_alloc);
|
||||
|
||||
struct spho_tpop {
|
||||
struct spho_scope *sc;
|
||||
struct spho_tp *tp;
|
||||
};
|
||||
|
||||
SLIST_HEAD(spho_scope_l, spho_scope);
|
||||
|
||||
|
@ -109,7 +115,7 @@ struct spho_scope {
|
|||
struct spho_nom_l noms;
|
||||
struct spho_tp_alloc_l tps;
|
||||
|
||||
struct spho_bind *bind;
|
||||
struct spho_bind_scope *stat_bind;
|
||||
|
||||
SLIST_ENTRY(spho_scope) next;
|
||||
};
|
||||
|
@ -127,9 +133,13 @@ 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_tp_bind_init(struct spho_scope *);
|
||||
int spho_scope_tp_bind_nom(struct spho_scope *, struct spho_nom *,
|
||||
struct spho_tp *);
|
||||
|
||||
#endif /* _SPHO_SCOPE_H */
|
||||
|
|
|
@ -6,4 +6,23 @@
|
|||
#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
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#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
|
||||
|
@ -22,8 +23,8 @@
|
|||
|
||||
#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_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))
|
||||
|
||||
|
|
|
@ -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