starting to add code for name bindings
This commit is contained in:
parent
15fc99b8c8
commit
55970b1baf
8 changed files with 131 additions and 59 deletions
40
src/spho/bind.c
Normal file
40
src/spho/bind.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include <sys/queue.h>
|
||||
|
||||
#include "spho/ctx.h"
|
||||
#include "spho/bind.h"
|
||||
|
||||
struct spho_bind *
|
||||
spho_bind_create(struct spho_ctx *ctx, struct spho_bind *parent)
|
||||
{
|
||||
struct spho_bind *bind;
|
||||
|
||||
if ((bind = malloc(sizeof(*bind))) == NULL) {
|
||||
SPHO_ERR(ctx, SPHO_ERR_SYS);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
STAILQ_INIT(&bind->head);
|
||||
bind->ctx = ctx;
|
||||
bind->parent = parent;
|
||||
|
||||
return (bind);
|
||||
}
|
||||
|
||||
int
|
||||
spho_bind_add(struct spho_bind *bind, struct spho_nom *nom, struct spho_tp *tp)
|
||||
{
|
||||
struct spho_binding *b;
|
||||
|
||||
if ((b = malloc(sizeof(*b))) == NULL) {
|
||||
SPHO_ERR(bind->ctx, SPHO_ERR_SYS);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
b->nom = nom;
|
||||
b->tp = tp;
|
||||
|
||||
STAILQ_INSERT_TAIL(&bind->head, b, entries);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -16,12 +16,14 @@ int
|
|||
spho_scope_init(struct spho_scope *sc, struct spho_ctx *ctx,
|
||||
struct spho_scope *p)
|
||||
{
|
||||
sc->ctx = ctx;
|
||||
sc->parent = p;
|
||||
|
||||
SLIST_INIT(&sc->subs);
|
||||
SLIST_INIT(&sc->noms);
|
||||
TAILQ_INIT(&sc->tps);
|
||||
|
||||
sc->ctx = ctx;
|
||||
sc->parent = p;
|
||||
sc->bind = NULL;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -10,13 +10,6 @@
|
|||
const struct tp_konst_data tp_konst_true = { TP_KONST_KEY_TRUE, "True" };
|
||||
const struct tp_konst_data tp_konst_false = { TP_KONST_KEY_FALSE, "False" };
|
||||
|
||||
//struct spho_tp *
|
||||
//spho_tp_create_disj(struct spho_ctx *, struct spho_tp *, struct spho_tp *,
|
||||
// struct spho_tp *)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
static struct spho_tp *
|
||||
spho_tp_alloc(struct spho_scope *sc)
|
||||
{
|
||||
|
@ -56,7 +49,7 @@ spho_tp_create_conj(struct spho_scope *sc, struct spho_tp *ltp,
|
|||
if ((tp = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
tp->form = SPHO_TP_FORM_CONJ;
|
||||
tp->kind = SPHO_TP_FORM_CONJ;
|
||||
tp->d.binop.left = ltp;
|
||||
tp->d.binop.right = rtp;
|
||||
|
||||
|
@ -72,7 +65,7 @@ spho_tp_create_disj(struct spho_scope *sc, struct spho_tp *ltp,
|
|||
if ((tp = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
tp->form = SPHO_TP_FORM_DISJ;
|
||||
tp->kind = SPHO_TP_FORM_DISJ;
|
||||
tp->d.binop.left = ltp;
|
||||
tp->d.binop.right = rtp;
|
||||
|
||||
|
@ -88,7 +81,7 @@ spho_tp_create_impl(struct spho_scope *sc, struct spho_tp *ltp,
|
|||
if ((tp = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
tp->form = SPHO_TP_FORM_IMPL;
|
||||
tp->kind = SPHO_TP_FORM_IMPL;
|
||||
tp->d.binop.left = ltp;
|
||||
tp->d.binop.right = rtp;
|
||||
|
||||
|
@ -104,7 +97,7 @@ spho_tp_create_arrow(struct spho_scope *sc, struct spho_tp *ltp,
|
|||
if ((tp = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
tp->form = SPHO_TP_FORM_ARROW;
|
||||
tp->kind = SPHO_TP_FORM_ARROW;
|
||||
tp->d.binop.left = ltp;
|
||||
tp->d.binop.right = rtp;
|
||||
|
||||
|
@ -119,7 +112,7 @@ spho_tp_create_box(struct spho_scope *sc, struct spho_tp *inner)
|
|||
if ((tp = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
tp->form = SPHO_TP_FORM_BOX;
|
||||
tp->kind = SPHO_TP_FORM_BOX;
|
||||
tp->d.unop.operand = inner;
|
||||
|
||||
return (tp);
|
||||
|
@ -134,7 +127,7 @@ spho_tp_create_forall(struct spho_scope *sc, struct spho_nom *nom,
|
|||
if ((ret = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
ret->form = SPHO_TP_FORM_FORALL;
|
||||
ret->kind = SPHO_TP_FORM_FORALL;
|
||||
ret->d.bind.nom = nom;
|
||||
ret->d.bind.bound = tp;
|
||||
|
||||
|
@ -149,7 +142,7 @@ spho_tp_create_true(struct spho_scope *sc)
|
|||
if ((ret = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
ret->form = SPHO_TP_FORM_TRUE;
|
||||
ret->kind = SPHO_TP_FORM_TRUE;
|
||||
ret->d.konst = tp_konst_true;
|
||||
|
||||
return (ret);
|
||||
|
@ -163,7 +156,7 @@ spho_tp_create_false(struct spho_scope *sc)
|
|||
if ((ret = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
ret->form = SPHO_TP_FORM_FALSE;
|
||||
ret->kind = SPHO_TP_FORM_FALSE;
|
||||
ret->d.konst = tp_konst_false;
|
||||
|
||||
return (ret);
|
||||
|
@ -177,7 +170,7 @@ spho_tp_create_name(struct spho_scope *sc, struct spho_nom *nom)
|
|||
if ((ret = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
ret->form = SPHO_TP_FORM_NOM;
|
||||
ret->kind = SPHO_TP_FORM_NAME;
|
||||
ret->d.nom.nom = nom;
|
||||
|
||||
return (ret);
|
||||
|
@ -192,7 +185,7 @@ spho_tp_create_appl(struct spho_scope *sc, struct spho_nom *nom,
|
|||
if ((ret = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
ret->form = SPHO_TP_FORM_APPL;
|
||||
ret->kind = SPHO_TP_FORM_APPL;
|
||||
ret->d.appl.nom = nom;
|
||||
ret->d.appl.args = args;
|
||||
|
||||
|
@ -208,7 +201,7 @@ spho_tp_create_member(struct spho_scope *sc, struct spho_nom *nom,
|
|||
if ((ret = spho_tp_alloc(sc)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
ret->form = SPHO_TP_FORM_MEMBER;
|
||||
ret->kind = SPHO_TP_FORM_MEMBER;
|
||||
ret->d.bind.nom = nom;
|
||||
ret->d.bind.bound = tp;
|
||||
|
||||
|
@ -221,10 +214,10 @@ spho_tp_destroy(struct spho_tp *tp)
|
|||
{
|
||||
struct spho_tp *arg;
|
||||
|
||||
switch (tp->form) {
|
||||
switch (tp->kind & SPHO_TP_FORM_MASK) {
|
||||
case SPHO_TP_FORM_TRUE:
|
||||
case SPHO_TP_FORM_FALSE:
|
||||
case SPHO_TP_FORM_NOM:
|
||||
case SPHO_TP_FORM_NAME:
|
||||
break;
|
||||
case SPHO_TP_FORM_CONJ:
|
||||
case SPHO_TP_FORM_DISJ:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue