summaryrefslogtreecommitdiff
path: root/stmt.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-05-09 02:56:07 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2026-05-17 11:13:23 +0200
commit527c23b73c8dae16f02cca6f450edb7d8225f60f (patch)
tree6b2bfd9e8d814026d6d2c1839d8cfe1bcadc825c /stmt.c
downloadslcob-master.tar.gz
Add project skeletonHEADmaster
Diffstat (limited to 'stmt.c')
-rw-r--r--stmt.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/stmt.c b/stmt.c
new file mode 100644
index 0000000..97cbe70
--- /dev/null
+++ b/stmt.c
@@ -0,0 +1,59 @@
+#include "stmt.h"
+#include "call.h"
+#include "fn.h"
+#include "parse.h"
+#include "prv.h"
+#include "display.h"
+#include "exit.h"
+#include "set.h"
+
+void stmt_free(struct stmt *s)
+{
+ switch (s->type)
+ {
+ case DISPLAY:
+ display_free(&s->u.display);
+ break;
+ case SET:
+ set_free(&s->u.set);
+ break;
+ case CALL:
+ call_free(&s->u.call);
+ break;
+ }
+}
+
+int stmt_cgen(const struct stmt *s, struct cgen *c)
+{
+ switch (s->type)
+ {
+ case DISPLAY:
+ return display_cgen(&s->u.display, c);
+ case SET:
+ return set_cgen(&s->u.set, c);
+ case CALL:
+ return call_cgen(&s->u.call, c);
+ }
+
+ fprintf(stderr, "%s: unreachable\n", __func__);
+ return -1;
+}
+
+struct stmt *stmt_cur(const struct prv *p)
+{
+ const struct fn *fn = fn_cur(p);
+
+ return &fn->stmts[fn->nstmts - 1];
+}
+
+const struct seq stmts[] =
+{
+ {(const struct step[]){
+ {ID, "display"}, {ANY, NULL, 1}, {ID, "etc"}, {0}}, .fn = display},
+ {(const struct step[])
+ {{ID, "display"}, {ANY, NULL, 1}, {0}}, .fn = display},
+ {(const struct step[]){{ID, "exit"}, {0}}, .fn = s_exit},
+ {(const struct step[]){{ID, "set"}, {0}}, .fn = set},
+ {(const struct step[]){{ID, "call"}, {0}}, .fn = call},
+ {0}
+};