Skip to content

Commit 594c7cd

Browse files
committed
me_compile() returns now a code error
1 parent a735076 commit 594c7cd

51 files changed

Lines changed: 1964 additions & 1639 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ miniexpr provides a simple, focused API with just two main functions:
2020

2121
### `me_compile()`
2222
```c
23-
me_expr *me_compile(const char *expression, const me_variable *variables,
24-
int var_count, me_dtype dtype, int *error);
23+
int me_compile(const char *expression, const me_variable *variables,
24+
int var_count, me_dtype dtype, int *error, me_expr **out);
2525
```
2626
Compiles an expression for evaluation. Variable and output pointers are provided during evaluation rather than compilation.
2727
2828
**Simple Usage**: Just provide variable names - everything else is optional:
2929
3030
```c
3131
me_variable vars[] = {{"x"}, {"y"}}; // Just the names!
32-
me_expr *expr = me_compile("x + y", vars, 2, ME_FLOAT64, &err);
33-
32+
me_expr *expr = NULL;
33+
if (me_compile("x + y", vars, 2, ME_FLOAT64, &err, &expr) != ME_COMPILE_SUCCESS) { /* handle error */ }
3434
// Later, provide data in the same order as vars array
3535
const void *data[] = {x_array, y_array}; // x first, y second
3636
if (me_eval(expr, data, 2, output, nitems) != ME_EVAL_SUCCESS) { /* handle error */ }
@@ -39,7 +39,8 @@ if (me_eval(expr, data, 2, output, nitems) != ME_EVAL_SUCCESS) { /* handle error
3939
For mixed types (use `ME_AUTO` for output dtype to infer from variables):
4040
```c
4141
me_variable vars[] = {{"temp", ME_FLOAT64}, {"count", ME_INT32}};
42-
me_expr *expr = me_compile("temp * count", vars, 2, ME_AUTO, &err);
42+
me_expr *expr = NULL;
43+
if (me_compile("temp * count", vars, 2, ME_AUTO, &err, &expr) != ME_COMPILE_SUCCESS) { /* handle error */ }
4344
// Result type will be inferred (ME_FLOAT64 in this case)
4445
```
4546
@@ -104,8 +105,8 @@ me_variable vars[] = {{"x"}, {"y"}};
104105
int err;
105106
106107
// Compile expression
107-
me_expr *expr = me_compile("x + y", vars, 2, ME_FLOAT64, &err);
108-
108+
me_expr *expr = NULL;
109+
if (me_compile("x + y", vars, 2, ME_FLOAT64, &err, &expr) != ME_COMPILE_SUCCESS) { /* handle error */ }
109110
// Prepare data
110111
double x_data[] = {1.0, 2.0, 3.0};
111112
double y_data[] = {4.0, 5.0, 6.0};

bench/benchmark_blocksize.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ static void benchmark_block_sizes(size_t total_elems) {
6161

6262
me_variable vars[] = {{"a"}, {"b"}, {"c"}};
6363
int err = 0;
64-
me_expr *expr = me_compile("(a + b) * c", vars, 3, ME_FLOAT64, &err);
65-
if (!expr) {
64+
me_expr *expr = NULL;
65+
int rc_expr = me_compile("(a + b) * c", vars, 3, ME_FLOAT64, &err, &expr);
66+
if (rc_expr != ME_COMPILE_SUCCESS) {
6667
printf("ERROR: Failed to compile expression (err=%d)\n", err);
6768
free(a);
6869
free(b);

bench/benchmark_blocksize_threads.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ static void benchmark_block_sizes(size_t total_elems) {
110110

111111
me_variable vars[] = {{"a"}, {"b"}, {"c"}};
112112
int err = 0;
113-
me_expr *expr = me_compile("(a + b) * c", vars, 3, ME_FLOAT64, &err);
114-
if (!expr) {
113+
me_expr *expr = NULL;
114+
int rc_expr = me_compile("(a + b) * c", vars, 3, ME_FLOAT64, &err, &expr);
115+
if (rc_expr != ME_COMPILE_SUCCESS) {
115116
printf("ERROR: Failed to compile expression (err=%d)\n", err);
116117
free(a);
117118
free(b);

bench/benchmark_chunked.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ void benchmark_expression(const char *expr_str, int total_size, int chunk_size)
3636
int err;
3737

3838
// Compile expression for chunked evaluation
39-
me_expr *expr = me_compile(expr_str, vars, 2, ME_FLOAT64, &err);
40-
if (!expr) {
39+
me_expr *expr = NULL;
40+
int rc_expr = me_compile(expr_str, vars, 2, ME_FLOAT64, &err, &expr);
41+
if (rc_expr != ME_COMPILE_SUCCESS) {
4142
printf("Failed to compile expression\n");
4243
free(a);
4344
free(b);

bench/benchmark_chunksize.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ static double benchmark_chunksize(thread_pool_t *pool, size_t chunk_bytes,
153153
// Compile expression
154154
me_variable vars[] = {{"a"}, {"b"}, {"c"}};
155155
int error;
156-
me_expr *expr = me_compile("(a + b) * c", vars, 3, ME_FLOAT64, &error);
157-
if (!expr) return 0.0;
156+
me_expr *expr = NULL;
157+
int rc_expr = me_compile("(a + b) * c", vars, 3, ME_FLOAT64, &error, &expr);
158+
if (rc_expr != ME_COMPILE_SUCCESS) return 0.0;
158159

159160
const void *inputs[] = {a, b, c};
160161

bench/benchmark_comparisons.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ static void benchmark_comparison(const char *name, const char *expr_str,
7979
/*
8080
* Benchmark 1: ME_BOOL output
8181
*/
82-
me_expr *expr_bool = me_compile(expr_str, vars, num_vars, ME_BOOL, &err);
83-
if (!expr_bool) {
82+
me_expr *expr_bool = NULL;
83+
int rc_expr_bool = me_compile(expr_str, vars, num_vars, ME_BOOL, &err, &expr_bool);
84+
if (rc_expr_bool != ME_COMPILE_SUCCESS) {
8485
fprintf(stderr, "Failed to compile %s with ME_BOOL: error %d\n", name, err);
8586
free(result_bool);
8687
free(result_f64);
@@ -105,8 +106,9 @@ static void benchmark_comparison(const char *name, const char *expr_str,
105106
/*
106107
* Benchmark 2: ME_FLOAT64 output (for comparison)
107108
*/
108-
me_expr *expr_f64 = me_compile(expr_str, vars, num_vars, ME_FLOAT64, &err);
109-
if (!expr_f64) {
109+
me_expr *expr_f64 = NULL;
110+
int rc_expr_f64 = me_compile(expr_str, vars, num_vars, ME_FLOAT64, &err, &expr_f64);
111+
if (rc_expr_f64 != ME_COMPILE_SUCCESS) {
110112
fprintf(stderr, "Failed to compile %s with ME_FLOAT64: error %d\n", name, err);
111113
free(result_bool);
112114
free(result_f64);

bench/benchmark_memory_efficiency.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ void demonstrate_memory_usage(int total_size, int chunk_size) {
102102
};
103103

104104
int err;
105-
me_expr *expr = me_compile("a + b", vars, 2, ME_FLOAT32, &err);
105+
me_expr *expr = NULL;
106+
int rc_expr = me_compile("a + b", vars, 2, ME_FLOAT32, &err, &expr);
106107

107-
if (!expr) {
108+
if (rc_expr != ME_COMPILE_SUCCESS) {
108109
printf("❌ Compilation failed: %d\n", err);
109110
free(a);
110111
free(b);

bench/benchmark_mixed_types.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ static double benchmark_chunksize(thread_pool_t *pool, size_t chunk_bytes,
175175
{"c", ME_INT16}
176176
};
177177
int error;
178-
me_expr *expr = me_compile("(a + b) * c", vars, 3, ME_AUTO, &error);
179-
if (!expr) {
178+
me_expr *expr = NULL;
179+
int rc_expr = me_compile("(a + b) * c", vars, 3, ME_AUTO, &error, &expr);
180+
if (rc_expr != ME_COMPILE_SUCCESS) {
180181
fprintf(stderr, "Failed to compile expression, error: %d\n", error);
181182
return 0.0;
182183
}

bench/benchmark_reductions.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ static bench_result_t benchmark_sum_int32(size_t total_elems, int iterations) {
4141

4242
me_variable vars[] = {{"x", ME_INT32, data}};
4343
int err = 0;
44-
me_expr *expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err);
45-
if (!expr) {
44+
me_expr *expr = NULL;
45+
int rc_expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err, &expr);
46+
if (rc_expr != ME_COMPILE_SUCCESS) {
4647
printf("Failed to compile sum(x) for int32 (err=%d)\n", err);
4748
free(data);
4849
bench_result_t empty = {0};
@@ -104,8 +105,9 @@ static bench_result_t benchmark_sum_float32(size_t total_elems, int iterations)
104105

105106
me_variable vars[] = {{"x", ME_FLOAT32, data}};
106107
int err = 0;
107-
me_expr *expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err);
108-
if (!expr) {
108+
me_expr *expr = NULL;
109+
int rc_expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err, &expr);
110+
if (rc_expr != ME_COMPILE_SUCCESS) {
109111
printf("Failed to compile sum(x) for float32 (err=%d)\n", err);
110112
free(data);
111113
bench_result_t empty = {0};

bench/benchmark_reductions_threads.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ static void benchmark_sum_threads_int32(size_t total_elems, int iterations) {
117117

118118
me_variable vars[] = {{"x", ME_INT32, data}};
119119
int err = 0;
120-
me_expr *expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err);
121-
if (!expr) {
120+
me_expr *expr = NULL;
121+
int rc_expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err, &expr);
122+
if (rc_expr != ME_COMPILE_SUCCESS) {
122123
printf("Failed to compile sum(x) for int32 (err=%d)\n", err);
123124
free(data);
124125
return;
@@ -180,8 +181,9 @@ static void benchmark_sum_threads_float32(size_t total_elems, int iterations) {
180181

181182
me_variable vars[] = {{"x", ME_FLOAT32, data}};
182183
int err = 0;
183-
me_expr *expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err);
184-
if (!expr) {
184+
me_expr *expr = NULL;
185+
int rc_expr = me_compile("sum(x)", vars, 1, ME_AUTO, &err, &expr);
186+
if (rc_expr != ME_COMPILE_SUCCESS) {
185187
printf("Failed to compile sum(x) for float32 (err=%d)\n", err);
186188
free(data);
187189
return;

0 commit comments

Comments
 (0)