Changeset 0153c87 in mainline
- Timestamp:
- 2012-08-10T20:09:36Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6be4142
- Parents:
- c9797067
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/expression.c
rc9797067 r0153c87 104 104 case BITHENGE_EXPRESSION_ADD: /* fallthrough */ 105 105 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: 107 113 rc = EINVAL; 108 114 if (bithenge_node_type(a) != BITHENGE_NODE_INTEGER) … … 127 133 rc = bithenge_new_integer_node(out, a_int * b_int); 128 134 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; 129 170 case BITHENGE_EXPRESSION_EQUALS: 130 171 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)); 131 176 break; 132 177 case BITHENGE_EXPRESSION_INVALID_BINARY_OP: … … 495 540 for (; scope && !bithenge_scope_is_barrier(scope); 496 541 scope = bithenge_scope_outer(scope)) { 542 bithenge_node_t *cur = bithenge_scope_get_current_node(scope); 543 if (!cur) 544 continue; 497 545 bithenge_node_inc_ref(self->key); 498 bithenge_node_t *cur = bithenge_scope_get_current_node(scope);499 546 int rc = bithenge_node_get(cur, self->key, out); 500 547 bithenge_node_dec_ref(cur); -
uspace/app/bithenge/expression.h
rc9797067 r0153c87 96 96 BITHENGE_EXPRESSION_SUBTRACT, 97 97 BITHENGE_EXPRESSION_MULTIPLY, 98 BITHENGE_EXPRESSION_INTEGER_DIVIDE, 99 BITHENGE_EXPRESSION_MODULO, 100 BITHENGE_EXPRESSION_LESS_THAN, 101 BITHENGE_EXPRESSION_GREATER_THAN, 102 BITHENGE_EXPRESSION_LESS_THAN_OR_EQUAL, 103 BITHENGE_EXPRESSION_GREATER_THAN_OR_EQUAL, 98 104 BITHENGE_EXPRESSION_EQUALS, 105 BITHENGE_EXPRESSION_NOT_EQUALS, 99 106 } bithenge_binary_op_t; 100 107 -
uspace/app/bithenge/script.c
rc9797067 r0153c87 56 56 TOKEN_ERROR, 57 57 TOKEN_EOF, 58 TOKEN_GREATER_THAN_OR_EQUAL, 58 59 TOKEN_IDENTIFIER, 59 60 TOKEN_INTEGER, 61 TOKEN_INTEGER_DIVIDE, 60 62 TOKEN_LEFT_ARROW, 63 TOKEN_LESS_THAN_OR_EQUAL, 64 TOKEN_NOT_EQUAL, 61 65 62 66 /* Keywords */ … … 272 276 state->buffer_pos++; 273 277 state->token = TOKEN_LEFT_ARROW; 278 } else if (state->buffer[state->buffer_pos] == '=') { 279 state->buffer_pos++; 280 state->token = TOKEN_LESS_THAN_OR_EQUAL; 281 } 282 } else if (ch == '>') { 283 state->token = ch; 284 state->buffer_pos++; 285 if (state->buffer[state->buffer_pos] == '=') { 286 state->buffer_pos++; 287 state->token = TOKEN_GREATER_THAN_OR_EQUAL; 274 288 } 275 289 } else if (ch == '=') { … … 280 294 state->buffer_pos++; 281 295 } 296 } else if (ch == '/') { 297 state->token = ch; 298 state->buffer_pos++; 299 if (state->buffer[state->buffer_pos] == '/') { 300 state->token = TOKEN_INTEGER_DIVIDE; 301 state->buffer_pos++; 302 } 303 } else if (ch == '!') { 304 state->token = ch; 305 state->buffer_pos++; 306 if (state->buffer[state->buffer_pos] == '=') { 307 state->token = TOKEN_NOT_EQUAL; 308 state->buffer_pos++; 309 } 282 310 } else { 283 311 state->token = ch; … … 388 416 PRECEDENCE_NONE, 389 417 PRECEDENCE_EQUALS, 418 PRECEDENCE_COMPARE, 390 419 PRECEDENCE_ADD, 391 420 PRECEDENCE_MULTIPLY, … … 401 430 case '*': 402 431 return BITHENGE_EXPRESSION_MULTIPLY; 432 case TOKEN_INTEGER_DIVIDE: 433 return BITHENGE_EXPRESSION_INTEGER_DIVIDE; 434 case '%': 435 return BITHENGE_EXPRESSION_MODULO; 436 case '<': 437 return BITHENGE_EXPRESSION_LESS_THAN; 438 case TOKEN_LESS_THAN_OR_EQUAL: 439 return BITHENGE_EXPRESSION_LESS_THAN_OR_EQUAL; 440 case '>': 441 return BITHENGE_EXPRESSION_GREATER_THAN; 442 case TOKEN_GREATER_THAN_OR_EQUAL: 443 return BITHENGE_EXPRESSION_GREATER_THAN_OR_EQUAL; 403 444 case TOKEN_EQUALS: 404 445 return BITHENGE_EXPRESSION_EQUALS; 446 case TOKEN_NOT_EQUAL: 447 return BITHENGE_EXPRESSION_NOT_EQUALS; 405 448 default: 406 449 return BITHENGE_EXPRESSION_INVALID_BINARY_OP; … … 414 457 case BITHENGE_EXPRESSION_SUBTRACT: 415 458 return PRECEDENCE_ADD; 416 case BITHENGE_EXPRESSION_MULTIPLY: 459 case BITHENGE_EXPRESSION_MULTIPLY: /* fallthrough */ 460 case BITHENGE_EXPRESSION_INTEGER_DIVIDE: /* fallthrough */ 461 case BITHENGE_EXPRESSION_MODULO: 417 462 return PRECEDENCE_MULTIPLY; 418 case BITHENGE_EXPRESSION_EQUALS: 463 case BITHENGE_EXPRESSION_LESS_THAN: /* fallthrough */ 464 case BITHENGE_EXPRESSION_LESS_THAN_OR_EQUAL: /* fallthrough */ 465 case BITHENGE_EXPRESSION_GREATER_THAN: /* fallthrough */ 466 case BITHENGE_EXPRESSION_GREATER_THAN_OR_EQUAL: 467 return PRECEDENCE_COMPARE; 468 case BITHENGE_EXPRESSION_EQUALS: /* fallthrough */ 469 case BITHENGE_EXPRESSION_NOT_EQUALS: 419 470 return PRECEDENCE_EQUALS; 420 471 default: … … 614 665 next_token(state); 615 666 616 bithenge_expression_t *expr2 = parse_postfix_expression(state); 667 bithenge_expression_t *expr2 = 668 parse_expression_precedence(state, precedence); 617 669 if (state->error != EOK) { 618 670 bithenge_expression_dec_ref(expr2); -
uspace/dist/src/bithenge/fat.bh
rc9797067 r0153c87 32 32 transform u32 = uint32le; 33 33 34 transform fat_dir_entry(disk) = struct { 35 .filename <- known_length(8); 36 .extension <- known_length(3); 37 .attrs <- u8; 38 .flags <- u8; 39 .ctime_fine <- u8; 40 .ctime <- u16; 41 .cdate <- u16; 42 .adate <- u16; 43 .permissions <- u16; 44 .mtime <- u16; 45 .mdate <- u16; 46 .start <- u16; 47 .size <- u32; 48 }; 49 50 transform fat_table(bits, num_clusters) = switch (bits) { 51 12: partial {repeat(num_clusters) { uint_le(12) }} <- bits_le; 52 16: partial {repeat(num_clusters) { u16 }}; 53 32: partial {repeat(num_clusters) { u32 }}; 54 }; 55 34 56 transform fat_super(disk) = struct { 35 57 .jump_instruction <- known_length(3); … … 63 85 }; 64 86 87 .first_root_sector <- (.num_reserved_sectors + .num_fats * .sectors_per_fat); 88 .first_data_sector <- (.first_root_sector + 89 (.num_root_entries * 32 + .bytes_per_sector - 1) // 90 .bytes_per_sector); 91 .num_clusters <- (2 + (.num_sectors - .first_data_sector) // .sectors_per_cluster); 92 .bits <- if (.num_clusters < 4085) { (12) } 93 else { if (.num_clusters < 65525) { (16) } else { (32) } }; 94 95 .fats <- partial(.num_reserved_sectors * .bytes_per_sector) { 96 repeat(.num_fats) { 97 fat_table(.bits, .num_clusters) <- 98 known_length(.sectors_per_fat * .bytes_per_sector) 99 } 100 } <- (disk); 101 102 .root <- partial(.first_root_sector * .bytes_per_sector) { 103 repeat(.num_root_entries) { fat_dir_entry(disk) } } <- (disk); 104 65 105 .boot_signature <- (disk[510,2]); # b"\x55\xaa"; TODO: what if .bytes_per_sector < 512? 66 106 };
Note:
See TracChangeset
for help on using the changeset viewer.