From fe3d4ce758822d65a0a5d617b7b77df2dbc972d8 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sun, 16 Mar 2014 14:55:57 -0700 Subject: Implement new magic frontend using sexpr --- src/map/magic-expr.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src/map/magic-expr.cpp') diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 279ba56..1be1b0b 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -358,7 +358,7 @@ int fun_neg(dumb_ptr, val_t *result, const_array args) static int fun_gte(dumb_ptr, val_t *result, const_array args) { - if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) + if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); @@ -373,6 +373,14 @@ int fun_gte(dumb_ptr, val_t *result, const_array args) return 0; } +static +int fun_lt(dumb_ptr env, val_t *result, const_array args) +{ + fun_gte(env, result, args); + RESULTINT = !RESULTINT; + return 0; +} + static int fun_gt(dumb_ptr, val_t *result, const_array args) { @@ -391,6 +399,14 @@ int fun_gt(dumb_ptr, val_t *result, const_array args) return 0; } +static +int fun_lte(dumb_ptr env, val_t *result, const_array args) +{ + fun_gt(env, result, args); + RESULTINT = !RESULTINT; + return 0; +} + static int fun_eq(dumb_ptr, val_t *result, const_array args) { @@ -423,6 +439,14 @@ int fun_eq(dumb_ptr, val_t *result, const_array args) return 0; } +static +int fun_ne(dumb_ptr env, val_t *result, const_array args) +{ + fun_eq(env, result, args); + RESULTINT = !RESULTINT; + return 0; +} + static int fun_bitand(dumb_ptr, val_t *result, const_array args) { @@ -753,7 +777,7 @@ magic_find_item(const_array args, int index, struct item *item_, int *sta if (ARG_TYPE(index) == TYPE::INT) item_data = itemdb_exists(ARGINT(index)); else if (ARG_TYPE(index) == TYPE::STRING) - item_data = itemdb_searchname(stringish(ARGSTR(index))); + item_data = itemdb_searchname(ARGSTR(index)); else return -1; @@ -1250,9 +1274,12 @@ std::map functions = MAGIC_FUNCTION("%", "ii", 'i', fun_mod), MAGIC_FUNCTION("||", "ii", 'i', fun_or), MAGIC_FUNCTION("&&", "ii", 'i', fun_and), + MAGIC_FUNCTION("<", "..", 'i', fun_lt), MAGIC_FUNCTION(">", "..", 'i', fun_gt), + MAGIC_FUNCTION("<=", "..", 'i', fun_lte), MAGIC_FUNCTION(">=", "..", 'i', fun_gte), - MAGIC_FUNCTION("=", "..", 'i', fun_eq), + MAGIC_FUNCTION("==", "..", 'i', fun_eq), + MAGIC_FUNCTION("!=", "..", 'i', fun_ne), MAGIC_FUNCTION("|", "..", 'i', fun_bitor), MAGIC_FUNCTION("&", "ii", 'i', fun_bitand), MAGIC_FUNCTION("^", "ii", 'i', fun_bitxor), -- cgit v1.2.3-60-g2f50