-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsl.h
More file actions
198 lines (176 loc) · 5.39 KB
/
Copy pathdsl.h
File metadata and controls
198 lines (176 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* This file dsl.h is part of L1vm.
*
* (c) Copyright Stefan Pietzonke (info@midnight-coding.de), 2026
*
* L1vm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L1vm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with L1vm. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DSL_H
#define DSL_H
#include "brackets-code.h"
#define MAX_DSL_RULES 512
#define MAX_DSL_TOKENS 16
#define MAX_DSL_CODE_LINES 256
#define MAX_DSL_VARS 64
#define MAX_DSL_INCLUDES 16
#define MAX_DSL_INCLUDES_POST 16
#define DSL_LINE_SIZE 1024
#define MAX_DSL_KEYWORDS 32
#define MAX_DSL_PARAMS 16
#define MAX_DSL_EXAMPLES 8
#define MAX_DSL_ALIASES 16
#define MAX_DSL_TESTS 8
#define MAX_DSL_COMPOSE 8
#define MAX_DSL_VALIDATE 8
typedef enum {
DSL_TOKEN_INT64,
DSL_TOKEN_DOUBLE,
DSL_TOKEN_STRING,
DSL_TOKEN_CONST_INT64,
DSL_TOKEN_CONST_DOUBLE,
DSL_TOKEN_CONST_STRING,
DSL_TOKEN_INT64_ARRAY,
DSL_TOKEN_DOUBLE_ARRAY,
DSL_TOKEN_STRING_ARRAY,
DSL_TOKEN_CONST_INT64_ARRAY,
DSL_TOKEN_INT64_REF,
DSL_TOKEN_DOUBLE_REF,
DSL_TOKEN_UNKNOWN
} DslTokenType;
typedef struct {
DslTokenType type;
char name[64];
char l1vm_type[32];
int is_array;
int array_size;
char default_value[256];
} DslToken;
typedef struct {
char type[64];
char name[64];
int count;
char value[256];
} DslVarDecl;
typedef struct {
char type[32];
char name[64];
char desc[256];
char default_value[256];
char min[64];
char max[64];
char pattern[256];
int required;
} DslParam;
typedef struct {
char prompt[256];
char expected[256];
} DslExample;
typedef struct {
char input[256];
char expect[256];
} DslTest;
typedef struct {
char keyword[64];
DslToken tokens[MAX_DSL_TOKENS];
int num_tokens;
DslToken result;
int has_result;
char includes[MAX_DSL_INCLUDES][256];
int num_includes;
char includes_post[MAX_DSL_INCLUDES_POST][256];
int num_includes_post;
DslVarDecl vars[MAX_DSL_VARS];
int num_vars;
char desc[512];
char code[MAX_DSL_CODE_LINES][DSL_LINE_SIZE];
int num_code_lines;
char array_name[64];
char array_index[64];
char array_element_type[32];
int has_array_rule;
char match_flags[MAX_DSL_TOKENS][64];
int num_match_flags;
char filename[512];
int is_learned;
DslParam params[MAX_DSL_PARAMS];
int num_params;
char aliases[MAX_DSL_ALIASES][64];
int num_aliases;
char category[256];
char version[32];
char complexity[32];
DslExample examples[MAX_DSL_EXAMPLES];
int num_examples;
DslTest tests[MAX_DSL_TESTS];
int num_tests;
char help[2048];
char validate_names[MAX_DSL_VALIDATE][128];
int num_validate;
char compose_names[MAX_DSL_COMPOSE][64];
int num_compose;
char init_code[MAX_DSL_CODE_LINES][DSL_LINE_SIZE];
int num_init_lines;
char cleanup_code[MAX_DSL_CODE_LINES][DSL_LINE_SIZE];
int num_cleanup_lines;
} DslRule;
typedef struct {
char parser_keywords[256];
char token_decl[1024];
char result_decl[256];
char include_list[1024];
char include_post_list[1024];
char var_decls[2048];
char code_lines[4096];
char desc_text[512];
char array_rule_name[64];
char array_rule_index[64];
char array_rule_elem_type[32];
char match_text[1024];
char param_decls[4096];
char alias_text[1024];
char category_text[256];
char version_text[32];
char complexity_text[32];
char example_lines[4096];
char test_lines[4096];
char help_text[2048];
char validate_text[1024];
char compose_text[1024];
char init_code_lines[4096];
char cleanup_code_lines[4096];
} DslRawRule;
extern DslRule dsl_rules[MAX_DSL_RULES];
extern int dsl_num_rules;
int dsl_load_rules(const char *dir_path);
int dsl_load_rule_file(const char *path);
void dsl_free_rules(void);
int dsl_match_rule(const char *prompt, DslRule **rule, float *score);
int dsl_match_all_rules(const char *prompt, DslRule **rules, float *scores, int max_rules, float min_score);
int dsl_generate_code(Program *prog, DslRule *rule, L1vmFunction *f);
int dsl_add_array_rule(const char *name, const char *index_var, const char *element_type);
int dsl_parse_raw(DslRawRule *raw, DslRule *rule);
int parse_token_decl(const char *line, DslToken *token);
int dsl_save_rule(DslRule *rule, const char *path);
int learn_dsl(const char *keyword, const char *out_dir, DslRule *new_rule);
int learn_dsl_load_code_file(const char *code_file, DslRule *rule);
void dsl_print_rule(DslRule *rule);
int dsl_generate_from_task(Program *prog, TaskProfile *task, L1vmFunction *f);
int dsl_match_task_flags(DslRule *rule, TaskProfile *task);
DslParam* dsl_find_param(DslRule *rule, const char *name);
int dsl_has_alias(DslRule *rule, const char *alias);
int dsl_find_rule_by_keyword(const char *keyword);
DslTokenType dsl_token_type_from_string(const char *str);
const char *dsl_token_type_to_string(DslTokenType type);
const char *dsl_token_l1vm_type(DslTokenType type);
#endif