starting to add code for name bindings

This commit is contained in:
Ellen Arvidsson 2025-05-23 14:02:51 +02:00
parent 15fc99b8c8
commit 55970b1baf
8 changed files with 131 additions and 59 deletions

29
include/spho/bind.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef _SPHO_BIND_H
#define _SPHO_BIND_H
#include <sys/queue.h>
#include "spho/scope.h"
struct spho_binding {
struct spho_nom *nom;
struct spho_tp *tp;
STAILQ_ENTRY(spho_binding) entries;
};
struct spho_bind {
STAILQ_HEAD(spho_binding_l, spho_binding) head;
struct spho_ctx *ctx;
struct spho_bind *parent;
};
struct spho_bind *spho_bind_create(struct spho_ctx *, struct spho_bind *);
int spho_bind_add(struct spho_bind *, struct spho_nom *, struct spho_tp *);
void spho_bind_destroy(struct spho_bind *);
#endif

View file

@ -7,40 +7,22 @@
#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);
/* 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! */
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;
@ -90,7 +72,7 @@ union tp_data {
struct spho_tp {
struct spho_scope *sc;
int form;
int kind;
union tp_data d;
STAILQ_ENTRY(spho_tp) entries;
@ -116,6 +98,9 @@ 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;
@ -124,6 +109,8 @@ struct spho_scope {
struct spho_nom_l noms;
struct spho_tp_alloc_l tps;
struct spho_bind *bind;
SLIST_ENTRY(spho_scope) next;
};

View file

@ -12,20 +12,21 @@
#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_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_MASK 0xff
// #define SPHO_TP_FORM_SUB 0x96
#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 +46,8 @@ 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 *);
void spho_tp_destroy(struct spho_tp *);