diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-01-03 12:53:06 +0000 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-01-03 12:53:23 +0000 |
commit | 925ec3751f3b407c17412b0fa04a84fe39c1e0b7 (patch) | |
tree | 8265b8193050e20387cfce770dfa5c625b6122fe /builtin.c | |
parent | c013b557a2bc72dff8795d89d4529e17946a5f3a (diff) |
Fix negative number syntax. Add a unary '-' operator.
Closes #63.
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -65,6 +65,15 @@ static jv f_plus(jv input, jv a, jv b) { } } +static jv f_negate(jv input) { + if (jv_get_kind(input) != JV_KIND_NUMBER) { + return type_error(input, "cannot be negated"); + } + jv ret = jv_number(-jv_number_value(input)); + jv_free(input); + return ret; +} + static jv f_minus(jv input, jv a, jv b) { jv_free(input); if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) { @@ -462,6 +471,7 @@ static jv f_error(jv input, jv msg) { static struct cfunction function_list[] = { {(cfunction_ptr)f_plus, "_plus", 3}, + {(cfunction_ptr)f_negate, "_negate", 1}, {(cfunction_ptr)f_minus, "_minus", 3}, {(cfunction_ptr)f_multiply, "_multiply", 3}, {(cfunction_ptr)f_divide, "_divide", 3}, |