aboutgitcodelistschat:MatrixIRC
path: root/cooker/parse.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2023-06-01 11:04:38 +0200
committerStefano Brivio <sbrivio@redhat.com>2023-06-01 11:10:27 +0200
commit1644bbec6161ec971a2ba3c213ce285b995cac22 (patch)
tree75974577237f8ae1a0989755be0a953c631f794e /cooker/parse.c
parentbb47d77d316137c9deddd46135b22dc144ae1ea9 (diff)
downloadseitan-1644bbec6161ec971a2ba3c213ce285b995cac22.tar
seitan-1644bbec6161ec971a2ba3c213ce285b995cac22.tar.gz
seitan-1644bbec6161ec971a2ba3c213ce285b995cac22.tar.bz2
seitan-1644bbec6161ec971a2ba3c213ce285b995cac22.tar.lz
seitan-1644bbec6161ec971a2ba3c213ce285b995cac22.tar.xz
seitan-1644bbec6161ec971a2ba3c213ce285b995cac22.tar.zst
seitan-1644bbec6161ec971a2ba3c213ce285b995cac22.zip
cooker: OP_CALL and OP_COPY stuff
...mostly. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'cooker/parse.c')
-rw-r--r--cooker/parse.c92
1 files changed, 83 insertions, 9 deletions
diff --git a/cooker/parse.c b/cooker/parse.c
index acb6810..64901f5 100644
--- a/cooker/parse.c
+++ b/cooker/parse.c
@@ -12,18 +12,11 @@
#include "calls.h"
#include "cooker.h"
#include "gluten.h"
+#include "call.h"
#include "match.h"
#include "emit.h"
#include "util.h"
-#include "calls/net.h"
-
-static void handle_call(struct gluten_ctx *g, JSON_Value *value)
-{
- (void)g;
- (void)value;
-}
-
static void handle_inject(struct gluten_ctx *g, JSON_Value *value)
{
(void)g;
@@ -64,7 +57,7 @@ struct rule_parser {
void (*fn)(struct gluten_ctx *g, JSON_Value *value);
} parsers[] = {
{ "match", handle_matches },
- { "call", handle_call },
+ { "call", handle_calls },
{ "inject", handle_inject },
{ "limit", handle_limit },
{ "return", handle_return },
@@ -74,6 +67,87 @@ struct rule_parser {
};
/**
+ * value_get_num() - Get numeric value from description matching JSON input
+ * @desc: Description of possible values from model
+ * @value: JSON value
+ *
+ * Return: numeric value
+ */
+long long value_get_num(struct num *desc, JSON_Value *value)
+{
+ const char *s = NULL;
+ long long n;
+
+ if (desc) {
+ s = json_value_get_string(value);
+ for (; desc->name && s && strcmp(s, desc->name); desc++);
+ if (s && !desc->name)
+ die(" Invalid value %s", s);
+
+ n = desc->value;
+ }
+
+ if (!s) {
+ if (json_value_get_type(value) != JSONNumber)
+ die(" Invalid value type");
+
+ n = json_value_get_number(value);
+ }
+
+ return n;
+}
+
+/**
+ * value_get() - Get generic value from description matching JSON input
+ * @desc: Description of possible values from model
+ * @type: Data type from model
+ * @value: JSON value
+ * @out: Corresponding bytecode value, set on return
+ */
+void value_get(union desc desc, enum type type, JSON_Value *value,
+ union value *out)
+{
+ if (TYPE_IS_NUM(type))
+ out->v_num = value_get_num(desc.d_num, value);
+}
+
+/**
+ * select_field() - Select field based on value and description
+ * @g: gluten context
+ * @pos: Index of syscall argument being parsed
+ * @s: Possible selection choices
+ * @v: Selector value
+ *
+ * Return: pointer to field, NULL if selector refers to a different argument
+ */
+struct field *select_field(struct gluten_ctx *g, int pos,
+ struct select *s, union value v)
+{
+ if (TYPE_IS_NUM(s->field->type)) {
+ struct select_num *d_num;
+
+ for (d_num = s->desc.d_num; d_num->target.f.type; d_num++) {
+ if (d_num->value == v.v_num) {
+ if (d_num->target.pos == pos)
+ return &d_num->target.f;
+
+ if (g) {
+ pos = d_num->target.pos;
+ g->selected_arg[pos] = &d_num->target;
+ }
+
+ return NULL;
+ }
+ }
+
+ if (!d_num->target.f.type)
+ die(" No match for numeric selector %i", v.v_num);
+ }
+
+ die(" not supported yet");
+}
+
+/**
* parse_block() - Parse a transformation block with rules
* @g: gluten context
* @block: Array of rules in block