Skip to content

Commit 8dca6ca

Browse files
committed
add convinience methods
1 parent a418e05 commit 8dca6ca

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

Diff for: hashmap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef any_t map_t;
3636
/*
3737
* Return an empty hashmap. Returns NULL if empty.
3838
*/
39-
extern map_t hashmap_new();
39+
extern map_t hashmap_new(void);
4040

4141
/*
4242
* Iteratively call f with argument (item, data) for

Diff for: lure.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ Node *lure_compile(const char *s) {
5151
return xp;
5252
}
5353

54-
bool lure_eval(ContextPtr ctx, const char *s) {
55-
Node *node = lure_compile(s);
54+
bool lure_compile_eval(Node *node, ContextPtr ctx) {
5655
Data *data = node->evaluate(node, ctx);
5756
bool flag = data->toBoolean(data);
58-
data->clean(data); free(data); data = NULL;
59-
free_node_deep(node);
57+
data->clean(data); free(data);
6058
return flag;
6159
}
60+
61+
bool lure_eval(ContextPtr ctx, const char *s) {
62+
Node *node = lure_compile(s);
63+
return lure_compile_eval(node, ctx);
64+
}

Diff for: lure.h

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ void setCustomContext(ContextPtr ctx, char *key, char *val, char *typeDesc);
7878
*/
7979
Node *lure_compile(const char *s);
8080

81+
/**
82+
* Eval with pre-compiled AST.
83+
* @param node root of the compiled ast
84+
* @param ctx map of context
85+
*/
86+
bool lure_compile_eval(Node *node, ContextPtr ctx);
87+
8188
/**
8289
* Evaluate expression with ctx, return false in case of error.
8390
* @param ctx a map of context objects

Diff for: node_function.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Data *node_function_evaluate(Node *node, map_t context) {
1414
LURE_ASSERT(node->list != NULL, "function parameter list must not be NULL");
1515
int n_params = node->list->n_all;
1616
Data **params = (Data **)calloc(n_params, sizeof(Data *));
17-
for(size_t i = 0; i < n_params; i++) {
17+
for(size_t i = 0; i < (size_t)n_params; i++) {
1818
Node *pnode = node->list->all[i];
1919
params[i] = pnode->evaluate(pnode, context);
2020
}
@@ -23,7 +23,7 @@ Data *node_function_evaluate(Node *node, map_t context) {
2323
Data *ret = function_derive(fname, params, n_params);
2424
leftRes->clean(leftRes);
2525
free(leftRes);
26-
for(size_t i = 0; i < n_params; i++) {
26+
for(size_t i = 0; i < (size_t)n_params; i++) {
2727
params[i]->clean(params[i]);
2828
free(params[i]);
2929
}

0 commit comments

Comments
 (0)