infix parsing and prebind fixes

This commit is contained in:
Ellen Arvidsson 2025-06-27 02:48:48 +02:00
parent 65066c493e
commit 33f38c03d6
14 changed files with 1555 additions and 1089 deletions

View file

@ -39,6 +39,8 @@
enum msph_tok_type {
TOK_INVAL = -1, // special: invalid, use to mark invalid toks
TOK_EOF = 0, // special: end-of-file
TOK_LBRACE, // {
TOK_RBRACE, // }
TOK_LBRAK, // [
@ -67,9 +69,10 @@ enum msph_tok_type {
TOK_CONST_FALSE, // False
TOK_IDENT, // identifiers
TOK_INVAL, // special: invalid, use to mark invalid toks
TOK_WSPACE, // special: whitespace
TOK_END // special: end of array/token stream
TOK_WSPACE, // whitespace
TOK_NOPE // special indicator: end of info array,
// start of parsing
};
#define MSPH_TAB_WIDTH 8

View file

@ -37,6 +37,8 @@ struct msph_decor {
#define MSPH_TREE_BOX 0x004a
#define MSPH_TREE_FORALL 0x004b
#define MSPH_TREE_PAREN 0x004c
#define MSPH_TREE_SUBT 0x004d
#define MSPH_TREE_IDENT 0x0100
#define MSPH_TREE_NAMEDECL 0x0101
@ -162,8 +164,7 @@ struct msph_tree_membdecl {
struct msph_tree_assert {
struct msph_tree_dir hd_dir;
struct msph_tree_tpexpr *ltp;
struct msph_tree_tpexpr *rtp;
struct msph_tree_tpexpr *tp;
};
struct msph_tree_namedecl {
@ -209,6 +210,7 @@ struct msph_tree_trait {
struct msph_tree_body *body;
};
/* XXX should probably merge all binary type ops into one */
struct msph_tree_conj {
struct msph_tree_tpexpr hd_tpe;
@ -230,6 +232,13 @@ struct msph_tree_impl {
struct msph_tree_tpexpr *rtp;
};
struct msph_tree_subt {
struct msph_tree_tpexpr hd_tpe;
struct msph_tree_tpexpr *ltp;
struct msph_tree_tpexpr *rtp;
};
struct msph_tree_arrow {
struct msph_tree_tpexpr hd_tpe;
@ -259,7 +268,11 @@ struct msph_tree_paren {
struct msph_tree_root *msph_tree_makeroot(struct msph_ctx *);
int msph_tree_parse(struct msph_token_stream *, struct msph_tree_root *);
#define MSPH_PARSE_PREFIX 1
#define MSPH_PARSE_INFIX 2
int msph_tree_parse(struct msph_token_stream *, struct msph_tree_root *,
int);
ssize_t msph_tree_fprint(FILE *, struct msph_tree *);

View file

@ -14,6 +14,8 @@ struct spho_ctx {
int err_info;
char errbuf[SPHO_ERR_BUF_LEN];
unsigned int nom_cnt;
#ifdef SPHO_DEBUG
char filebuf[SPHO_ERR_FILEBUF_LEN];
int errline;
@ -22,6 +24,7 @@ struct spho_ctx {
};
struct spho_ctx *spho_ctx_create(void);
void spho_ctx_init(struct spho_ctx *);
void spho_ctx_destroy(struct spho_ctx *);
const char *spho_ctx_strerror(struct spho_ctx *);

View file

@ -39,7 +39,7 @@
(ctx)->err = (e); \
(ctx)->err_info = (info); \
snprintf((ctx)->filebuf, sizeof((ctx)->filebuf), \
__FILE__); \
__FILE__ ":%s", __func__); \
(ctx)->errline = __LINE__; \
} while (0)

View file

@ -7,13 +7,22 @@
#define SPHO_NOM_LEN 128
/* name */
struct spho_nom {
char s[SPHO_NOM_LEN];
SLIST_ENTRY(spho_nom) next; // TODO change to allocs
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;
};
SLIST_HEAD(spho_nom_l, spho_nom);
#define TP_KONST_KEY_TRUE 0x43445 /* don't change!!!!! */
@ -76,6 +85,7 @@ struct spho_tp {
int kind;
union tp_data d;
union spho_ext_data ext_data;
STAILQ_ENTRY(spho_tp) entries;
};
@ -85,30 +95,20 @@ struct spho_tp_op {
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_ptr {
struct spho_tp *p;
STAILQ_ENTRY(spho_tp_ptr) entries;
};
STAILQ_HEAD(spho_tp_ptr_l, spho_tp_ptr);
struct spho_tp_alloc {
union {
struct spho_tp tp;
struct spho_tp_op tp_op;
} alloc;
TAILQ_ENTRY(spho_tp_alloc) allocs;
STAILQ_ENTRY(spho_tp_alloc) entries;
};
TAILQ_HEAD(spho_tp_alloc_l, spho_tp_alloc);
SLIST_HEAD(spho_scope_l, spho_scope);
/* defined in spho/bind.h */
struct spho_bind;
@ -116,33 +116,38 @@ 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;
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;
SLIST_ENTRY(spho_scope) next;
STAILQ_ENTRY(spho_scope) entries;
};
#define SPHO_SC_ERR(sc, err) SPHO_ERR((sc)->ctx, (err))
int spho_scope_init(struct spho_scope *, struct spho_ctx *,
void spho_scope_init(struct spho_scope *, struct spho_ctx *,
struct spho_scope *);
void spho_scope_term(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(struct spho_scope *);
struct spho_scope *spho_scope_create_subscope(struct spho_scope *);
void spho_scope_destroy(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_str(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_str_strict(struct spho_scope *, const char *,
int spho_scope_nom_lookup_strict(struct spho_scope *, const char *,
size_t, struct spho_nom **);
int spho_scope_prebind_init(struct spho_scope *);