summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ast.c5
-rw-r--r--ast.h4
-rw-r--r--eval.c22
-rw-r--r--lexer.c6
-rw-r--r--lib.c34
5 files changed, 36 insertions, 35 deletions
diff --git a/ast.c b/ast.c
index bba1316..e20682c 100644
--- a/ast.c
+++ b/ast.c
@@ -108,7 +108,7 @@ double_rounded_to_string(struct json_object *v, struct printbuf *pb, int level,
}
struct json_object *
-json_object_new_double_rounded(double v)
+ut_new_double(double v)
{
struct json_object *d = json_object_new_double(v);
@@ -124,7 +124,8 @@ null_obj_to_string(struct json_object *v, struct printbuf *pb, int level, int fl
}
struct json_object *
-json_object_new_null_obj(void) {
+ut_new_null(void)
+{
struct json_object *d = json_object_new_boolean(false);
json_object_set_serializer(d, null_obj_to_string, NULL, NULL);
diff --git a/ast.h b/ast.h
index d1c8193..92c1816 100644
--- a/ast.h
+++ b/ast.h
@@ -102,8 +102,8 @@ void ut_free(struct ut_state *s);
struct ut_opcode *ut_new_func(struct ut_state *s, struct ut_opcode *name, struct ut_opcode *args, struct ut_opcode *body);
struct json_object *ut_new_object(struct ut_state *s, struct json_object *proto);
-struct json_object *json_object_new_double_rounded(double v);
-struct json_object *json_object_new_null_obj(void);
+struct json_object *ut_new_double(double v);
+struct json_object *ut_new_null(void);
bool ut_register_extended_type(const char *name, void (*freefn)(void *));
struct json_object *ut_set_extended_type(struct ut_state *s, struct json_object *v, struct json_object *proto, const char *name, void *data);
diff --git a/eval.c b/eval.c
index 1043c49..0016f9a 100644
--- a/eval.c
+++ b/eval.c
@@ -780,7 +780,7 @@ ut_execute_inc_dec(struct ut_state *state, struct ut_opcode *op)
ut_putval(scope);
if (ut_cast_number(val, &n, &d) == json_type_double)
- nval = json_object_new_double_rounded(d + (op->type == T_INC ? 1.0 : -1.0));
+ nval = ut_new_double(d + (op->type == T_INC ? 1.0 : -1.0));
else
nval = json_object_new_int64(n + (op->type == T_INC ? 1 : -1));
@@ -978,7 +978,7 @@ ut_execute_unary_plus_minus(struct ut_state *state, struct ut_opcode *op)
return json_object_new_int64((op->type == T_SUB) ? -n : n);
default:
- return json_object_new_double_rounded((op->type == T_SUB) ? -d : d);
+ return ut_new_double((op->type == T_SUB) ? -d : d);
}
}
@@ -1038,22 +1038,22 @@ ut_execute_arith(struct ut_state *state, struct ut_opcode *op)
switch (op->type) {
case T_ADD:
- return json_object_new_double_rounded(d1 + d2);
+ return ut_new_double(d1 + d2);
case T_SUB:
- return json_object_new_double_rounded(d1 - d2);
+ return ut_new_double(d1 - d2);
case T_MUL:
- return json_object_new_double_rounded(d1 * d2);
+ return ut_new_double(d1 * d2);
case T_DIV:
if (d2 == 0.0)
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
- return json_object_new_double_rounded(d1 / d2);
+ return ut_new_double(d1 / d2);
case T_MOD:
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
}
}
@@ -1069,7 +1069,7 @@ ut_execute_arith(struct ut_state *state, struct ut_opcode *op)
case T_DIV:
if (n2 == 0)
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
return json_object_new_int64(n1 / n2);
@@ -1077,7 +1077,7 @@ ut_execute_arith(struct ut_state *state, struct ut_opcode *op)
return json_object_new_int64(n1 % n2);
}
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
}
static struct json_object *
@@ -1149,7 +1149,7 @@ ut_execute_return(struct ut_state *state, struct ut_opcode *op)
struct json_object *val = op->operand[0] ? ut_execute_op(state, op->operand[0]) : NULL;
if (!val)
- val = json_object_new_null_obj();
+ val = ut_new_null();
json_object_set_userdata(val, op, NULL);
diff --git a/lexer.c b/lexer.c
index 26ee3e1..f7b822d 100644
--- a/lexer.c
+++ b/lexer.c
@@ -539,13 +539,13 @@ parse_number(const char *buf, struct ut_opcode *op, struct ut_state *s)
if (!strncmp(buf, "Infinity", 8)) {
op->type = T_DOUBLE;
- op->val = json_object_new_double_rounded(INFINITY);
+ op->val = ut_new_double(INFINITY);
return 8;
}
else if (!strncmp(buf, "NaN", 3)) {
op->type = T_DOUBLE;
- op->val = json_object_new_double_rounded(NAN);
+ op->val = ut_new_double(NAN);
return 3;
}
@@ -558,7 +558,7 @@ parse_number(const char *buf, struct ut_opcode *op, struct ut_state *s)
if (e > buf) {
op->type = T_DOUBLE;
- op->val = json_object_new_double_rounded(d);
+ op->val = ut_new_double(d);
return (e - buf);
}
diff --git a/lib.c b/lib.c
index 3cb8818..eff1cae 100644
--- a/lib.c
+++ b/lib.c
@@ -500,12 +500,12 @@ ut_abs(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
double d;
if (json_object_is_type(v, json_type_null))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
t = ut_cast_number(v, &n, &d);
if (t == json_type_double)
- return (isnan(d) || d < 0) ? json_object_new_double_rounded(-d) : json_object_get(v);
+ return (isnan(d) || d < 0) ? ut_new_double(-d) : json_object_get(v);
return (n < 0) ? json_object_new_int64(-n) : json_object_get(v);
}
@@ -517,9 +517,9 @@ ut_atan2(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
double d2 = ut_cast_double(json_object_array_get_idx(args, 1));
if (isnan(d1) || isnan(d2))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
- return json_object_new_double_rounded(atan2(d1, d2));
+ return ut_new_double(atan2(d1, d2));
}
static struct json_object *
@@ -558,9 +558,9 @@ ut_cos(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
double d = ut_cast_double(json_object_array_get_idx(args, 0));
if (isnan(d))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
- return json_object_new_double_rounded(cos(d));
+ return ut_new_double(cos(d));
}
static struct json_object *
@@ -620,9 +620,9 @@ ut_exp(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
double d = ut_cast_double(json_object_array_get_idx(args, 0));
if (isnan(d))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
- return json_object_new_double_rounded(exp(d));
+ return ut_new_double(exp(d));
}
static struct json_object *
@@ -682,12 +682,12 @@ ut_hex(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
char *e;
if (!val || !isxdigit(*val))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
n = strtoll(val, &e, 16);
if (e == val || *e)
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
return json_object_new_int64(n);
}
@@ -698,7 +698,7 @@ ut_int(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
int64_t n = ut_cast_int64(json_object_array_get_idx(args, 0));
if (errno == EINVAL || errno == EOVERFLOW)
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
return json_object_new_int64(n);
}
@@ -816,9 +816,9 @@ ut_log(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
double d = ut_cast_double(json_object_array_get_idx(args, 0));
if (isnan(d))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
- return json_object_new_double_rounded(log(d));
+ return ut_new_double(log(d));
}
static struct json_object *
@@ -978,9 +978,9 @@ ut_sin(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
double d = ut_cast_double(json_object_array_get_idx(args, 0));
if (isnan(d))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
- return json_object_new_double_rounded(sin(d));
+ return ut_new_double(sin(d));
}
@@ -1153,9 +1153,9 @@ ut_sqrt(struct ut_state *s, struct ut_opcode *op, struct json_object *args)
double d = ut_cast_double(json_object_array_get_idx(args, 0));
if (isnan(d))
- return json_object_new_double_rounded(NAN);
+ return ut_new_double(NAN);
- return json_object_new_double_rounded(sqrt(d));
+ return ut_new_double(sqrt(d));
}
static struct json_object *