Changeset 0153c87 in mainline for uspace/app/bithenge/expression.c


Ignore:
Timestamp:
2012-08-10T20:09:36Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6be4142
Parents:
c9797067
Message:

Bithenge: more FAT, operators, and fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/expression.c

    rc9797067 r0153c87  
    104104        case BITHENGE_EXPRESSION_ADD: /* fallthrough */
    105105        case BITHENGE_EXPRESSION_SUBTRACT: /* fallthrough */
    106         case BITHENGE_EXPRESSION_MULTIPLY:
     106        case BITHENGE_EXPRESSION_MULTIPLY: /* fallthrough */
     107        case BITHENGE_EXPRESSION_INTEGER_DIVIDE: /* fallthrough */
     108        case BITHENGE_EXPRESSION_MODULO: /* fallthrough */
     109        case BITHENGE_EXPRESSION_LESS_THAN: /* fallthrough */
     110        case BITHENGE_EXPRESSION_LESS_THAN_OR_EQUAL: /* fallthrough */
     111        case BITHENGE_EXPRESSION_GREATER_THAN: /* fallthrough */
     112        case BITHENGE_EXPRESSION_GREATER_THAN_OR_EQUAL:
    107113                rc = EINVAL;
    108114                if (bithenge_node_type(a) != BITHENGE_NODE_INTEGER)
     
    127133                rc = bithenge_new_integer_node(out, a_int * b_int);
    128134                break;
     135        case BITHENGE_EXPRESSION_INTEGER_DIVIDE:
     136                /* Integer division can behave in three major ways when the
     137                 * operands are signed: truncated, floored, or Euclidean. When
     138                 * b > 0, we give the same result as floored and Euclidean;
     139                 * otherwise, we currently raise an error. See
     140                 * https://en.wikipedia.org/wiki/Modulo_operation and its
     141                 * references. */
     142                if (b_int <= 0) {
     143                        rc = EINVAL;
     144                        break;
     145                }
     146                rc = bithenge_new_integer_node(out,
     147                    (a_int / b_int) + (a_int % b_int < 0 ? -1 : 0));
     148                break;
     149        case BITHENGE_EXPRESSION_MODULO:
     150                /* This is consistent with division; see above. */
     151                if (b_int <= 0) {
     152                        rc = EINVAL;
     153                        break;
     154                }
     155                rc = bithenge_new_integer_node(out,
     156                    (a_int % b_int) + (a_int % b_int < 0 ? b_int : 0));
     157                break;
     158        case BITHENGE_EXPRESSION_LESS_THAN:
     159                rc = bithenge_new_boolean_node(out, a_int < b_int);
     160                break;
     161        case BITHENGE_EXPRESSION_LESS_THAN_OR_EQUAL:
     162                rc = bithenge_new_boolean_node(out, a_int <= b_int);
     163                break;
     164        case BITHENGE_EXPRESSION_GREATER_THAN:
     165                rc = bithenge_new_boolean_node(out, a_int > b_int);
     166                break;
     167        case BITHENGE_EXPRESSION_GREATER_THAN_OR_EQUAL:
     168                rc = bithenge_new_boolean_node(out, a_int >= b_int);
     169                break;
    129170        case BITHENGE_EXPRESSION_EQUALS:
    130171                rc = bithenge_new_boolean_node(out, bithenge_node_equal(a, b));
     172                break;
     173        case BITHENGE_EXPRESSION_NOT_EQUALS:
     174                rc = bithenge_new_boolean_node(out,
     175                    ~bithenge_node_equal(a, b));
    131176                break;
    132177        case BITHENGE_EXPRESSION_INVALID_BINARY_OP:
     
    495540        for (; scope && !bithenge_scope_is_barrier(scope);
    496541            scope = bithenge_scope_outer(scope)) {
     542                bithenge_node_t *cur = bithenge_scope_get_current_node(scope);
     543                if (!cur)
     544                        continue;
    497545                bithenge_node_inc_ref(self->key);
    498                 bithenge_node_t *cur = bithenge_scope_get_current_node(scope);
    499546                int rc = bithenge_node_get(cur, self->key, out);
    500547                bithenge_node_dec_ref(cur);
Note: See TracChangeset for help on using the changeset viewer.