aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/set.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-10-01 01:04:30 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2026-10-05 00:38:49 +0200
commit2b0d4ead061a39da9dbd705c18c9955549c4d405 (patch)
tree1412ac39adce3428b96caf67b1e7543f6c1246a5 /src/prc1/set.c
parent9140988be4e5bb028b7140aca1a67af1370c72a7 (diff)
downloadprc-sym.tar.gz
WIP symsym
Diffstat (limited to 'src/prc1/set.c')
-rw-r--r--src/prc1/set.c113
1 files changed, 68 insertions, 45 deletions
diff --git a/src/prc1/set.c b/src/prc1/set.c
index 3b83fc9..43d600b 100644
--- a/src/prc1/set.c
+++ b/src/prc1/set.c
@@ -8,12 +8,23 @@
#include "prv.h"
#include "stmt.h"
#include "storage.h"
+#include "sym.h"
#include "type.h"
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+static int to(const struct lex *, struct prv *);
+
+static const struct seq seqs[] =
+{
+ {(struct step[]){{ID, "to"}, {0}}, .fn = to},
+ {0}
+};
+
+#if 0
+
static int mv(const struct lex *l, struct prv *p);
static int maddr(const struct lex *l, struct prv *p);
static int msz(const struct lex *l, struct prv *p);
@@ -132,29 +143,6 @@ static unsigned long long tonum(const char *s)
return v;
}
-static int dst(const struct lex *l, const struct tk *tk, struct set *s,
- struct prv *p)
-{
- const struct stentry *e = fn_var(fn_cur(p), tk);
- size_t n = s->ndsts + 1;
- struct setdst *dsts;
-
- if (!e)
- {
- errloc(tk, "undefined reference to \"%s\"", tk->s);
- return -1;
- }
- else if (!(dsts = realloc(s->dsts, n * sizeof *dsts)))
- {
- perror("realloc(3)");
- return -1;
- }
-
- s->dsts = dsts;
- s->dsts[s->ndsts++] = (struct setdst){.entry = e};
- return 0;
-}
-
static int checkzero(const struct tk *tk, const struct set *s,
unsigned long long v)
{
@@ -260,7 +248,7 @@ static int mv(const struct lex *l, struct prv *p)
}
}
- dbg("\t\tadding set ");
+ dbg("\t\tadd set ");
for (size_t i = 0; i < s->ndsts; i++)
dbg("%s ", s->dsts[i].entry->tk->s);
@@ -308,7 +296,7 @@ static int maddr(const struct lex *l, struct prv *p)
s->type = SET_ADDR;
s->src = e;
p->stk = ++tk;
- dbg("\t\tadding set ");
+ dbg("\t\tadd set ");
for (size_t i = 0; i < s->ndsts; i++)
dbg("%s ", s->dsts[i].entry->tk->s);
@@ -369,7 +357,7 @@ static int msz(const struct lex *l, struct prv *p)
s->type = SET_VAL;
p->stk = ++tk;
- dbg("\t\tadding set ");
+ dbg("\t\tadd set ");
for (size_t i = 0; i < s->ndsts; i++)
dbg("%s ", s->dsts[i].entry->tk->s);
@@ -392,7 +380,7 @@ static int mimb(const struct lex *l, struct prv *p)
/* skip "to" */
tk++;
- dbg("\t\tadding set ");
+ dbg("\t\tadd set ");
for (size_t i = 0; i < s->ndsts; i++)
dbg("%s ", s->dsts[i].entry->tk->s);
@@ -428,7 +416,7 @@ static int mimb(const struct lex *l, struct prv *p)
p->stk = ++tk;
return 1;
}
-
+#endif
void set_free(struct set *m)
{
if (m)
@@ -511,43 +499,78 @@ int set_cgen(const struct set *s, struct cgen *c)
return 0;
}
-int set(const struct lex *l, struct prv *p)
+static int to(const struct lex *l, struct prv *p)
{
- const struct tk *next = p->tk;
- const char *ns;
- struct fn *fn = fn_cur(p);
- size_t n = fn->nstmts + 1;
- struct stmt *stmts;
+ fprintf(stderr, "%s: TODO\n", __func__);
+ return -1;
+}
+
+static int dst(const struct lex *l, struct prv *p, const struct sym *s)
+{
+ const struct fn *fn = fn = fn_cur(p);
+ struct stmt *stmt = stmt_cur(p);
- if (lex_eof(l, next))
+ if (sym_rval(s))
{
- errloc(next - 1, "incomplete set statement");
+ errloc(p->stk, "expression is not assignable");
return -1;
}
- else if (kw((ns = next->s)))
+
+ fprintf(stderr, "%s: TODO\n", __func__);
+ return -1;
+#if 0
+ const struct stentry *e;
+ size_t n = s->ndsts + 1;
+ struct setdst *dsts;
+
+ if (rval())
+
+ if (!(e = fn_var(fn, )))
{
- errloc(next, "incomplete set statement");
+ errloc(tk, "undefined reference to \"%s\"", tk->s);
return -1;
}
- else if (!(stmts = realloc(fn->stmts, n * sizeof *stmts)))
+ else if (!(dsts = realloc(s->dsts, n * sizeof *dsts)))
{
perror("realloc(3)");
return -1;
}
- fn->stmts = stmts;
- fn->stmts[fn->nstmts++] = (struct stmt){.type = SET};
+ s->dsts = dsts;
+ s->dsts[s->ndsts++] = (struct setdst){.entry = e};
+ return 0;
+#endif
+}
+
+static int finalize(const struct lex *l, struct prv *p)
+{
+ fprintf(stderr, "%s: TODO\n", __func__);
+ return -1;
+}
+int set(const struct lex *l, struct prv *p)
+{
+ struct fn *fn = fn_cur(p);
+ size_t n = fn->nstmts + 1;
+ struct stmt *stmts;
struct pos init =
{
+ .name = __func__,
.seq = seqs,
- .stseq = seqs,
- .step = seqs->steps
+ .end = finalize
};
+ if (!(stmts = realloc(fn->stmts, n * sizeof *stmts)))
+ {
+ perror("realloc(3)");
+ return -1;
+ }
+
+ fn->stmts = stmts;
+ fn->stmts[fn->nstmts++] = (struct stmt){.type = SET};
+
if (push(&init, p))
return -1;
- p->stk = p->tk;
- return 1;
+ return sym(p, dst);
}