diff options
| author | Kenichi Handa | 2000-09-12 02:30:13 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2000-09-12 02:30:13 +0000 |
| commit | 54fa5bc13a7110099c180fa0e597359b93f485b3 (patch) | |
| tree | 295c395857b65fc3bc5a2e1649a30910f1229e26 /src | |
| parent | 63c36c3c74dd2dc30036fd23448b00212b794c9f (diff) | |
| download | emacs-54fa5bc13a7110099c180fa0e597359b93f485b3.tar.gz emacs-54fa5bc13a7110099c180fa0e597359b93f485b3.zip | |
Comment fixed.
(MAX_MAP_SET_LEVEL): Increased to 30.
(PUSH_MAPPING_STACK): Enclose with do-while block.
(POP_MAPPING_STACK): Likewise.
(stack_idx_of_map_multiple): New variable.
(CCL_CALL_FOR_MAP_INSTRUCTION): New macro.
(ccl_driver) <CCL_IterateMultipleMap>: If the content is a symbol,
call the corresponding CCL program by
CCL_CALL_FOR_MAP_INSTRUCTION.
(ccl_driver) <CCL_MapSingle>: Likewise.
(ccl_driver) <CCL_MapMultiple>: Rewritten to fix many bugs, deal
with the case where looking up process reaches to the end of
map-set, and call CCL programs as the above change.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ccl.c | 322 |
1 files changed, 222 insertions, 100 deletions
| @@ -537,7 +537,10 @@ Lisp_Object Vccl_program_table; | |||
| 537 | At first, VAL0 is set to reg[rrr], and it is translated by the | 537 | At first, VAL0 is set to reg[rrr], and it is translated by the |
| 538 | first map to VAL1. Then, VAL1 is translated by the next map to | 538 | first map to VAL1. Then, VAL1 is translated by the next map to |
| 539 | VAL2. This mapping is iterated until the last map is used. The | 539 | VAL2. This mapping is iterated until the last map is used. The |
| 540 | result of the mapping is the last value of VAL?. | 540 | result of the mapping is the last value of VAL?. When the mapping |
| 541 | process reached to the end of the map set, it moves to the next | ||
| 542 | map set. If the next does not exit, the mapping process terminates, | ||
| 543 | and regard the last value as a result. | ||
| 541 | 544 | ||
| 542 | But, when VALm is mapped to VALn and VALn is not a number, the | 545 | But, when VALm is mapped to VALn and VALn is not a number, the |
| 543 | mapping proceed as below: | 546 | mapping proceed as below: |
| @@ -548,8 +551,12 @@ Lisp_Object Vccl_program_table; | |||
| 548 | In VALn is t, VALm is reverted to reg[rrr] and the mapping of VALm | 551 | In VALn is t, VALm is reverted to reg[rrr] and the mapping of VALm |
| 549 | proceed to the next map. | 552 | proceed to the next map. |
| 550 | 553 | ||
| 551 | If VALn is lambda, the whole mapping process terminates, and VALm | 554 | If VALn is lambda, move to the next map set like reaching to the |
| 552 | is the result of this mapping. | 555 | end of the current map set. |
| 556 | |||
| 557 | If VALn is a symbol, call the CCL program refered by it. | ||
| 558 | Then, use reg[rrr] as a mapped value except for -1, -2 and -3. | ||
| 559 | Such special values are regarded as nil, t, and lambda respectively. | ||
| 553 | 560 | ||
| 554 | Each map is a Lisp vector of the following format (a) or (b): | 561 | Each map is a Lisp vector of the following format (a) or (b): |
| 555 | (a)......[STARTPOINT VAL1 VAL2 ...] | 562 | (a)......[STARTPOINT VAL1 VAL2 ...] |
| @@ -577,7 +584,7 @@ Lisp_Object Vccl_program_table; | |||
| 577 | N:SEPARATOR_z (< 0) | 584 | N:SEPARATOR_z (< 0) |
| 578 | */ | 585 | */ |
| 579 | 586 | ||
| 580 | #define MAX_MAP_SET_LEVEL 20 | 587 | #define MAX_MAP_SET_LEVEL 30 |
| 581 | 588 | ||
| 582 | typedef struct | 589 | typedef struct |
| 583 | { | 590 | { |
| @@ -588,19 +595,44 @@ typedef struct | |||
| 588 | static tr_stack mapping_stack[MAX_MAP_SET_LEVEL]; | 595 | static tr_stack mapping_stack[MAX_MAP_SET_LEVEL]; |
| 589 | static tr_stack *mapping_stack_pointer; | 596 | static tr_stack *mapping_stack_pointer; |
| 590 | 597 | ||
| 591 | #define PUSH_MAPPING_STACK(restlen, orig) \ | 598 | /* If this variable is non-zero, it indicates the stack_idx |
| 592 | { \ | 599 | of immediately called by CCL_MapMultiple. */ |
| 593 | mapping_stack_pointer->rest_length = (restlen); \ | 600 | static int stack_idx_of_map_multiple = 0; |
| 594 | mapping_stack_pointer->orig_val = (orig); \ | ||
| 595 | mapping_stack_pointer++; \ | ||
| 596 | } | ||
| 597 | 601 | ||
| 598 | #define POP_MAPPING_STACK(restlen, orig) \ | 602 | #define PUSH_MAPPING_STACK(restlen, orig) \ |
| 599 | { \ | 603 | do { \ |
| 600 | mapping_stack_pointer--; \ | 604 | mapping_stack_pointer->rest_length = (restlen); \ |
| 601 | (restlen) = mapping_stack_pointer->rest_length; \ | 605 | mapping_stack_pointer->orig_val = (orig); \ |
| 602 | (orig) = mapping_stack_pointer->orig_val; \ | 606 | mapping_stack_pointer++; \ |
| 603 | } \ | 607 | } while (0) |
| 608 | |||
| 609 | #define POP_MAPPING_STACK(restlen, orig) \ | ||
| 610 | do { \ | ||
| 611 | mapping_stack_pointer--; \ | ||
| 612 | (restlen) = mapping_stack_pointer->rest_length; \ | ||
| 613 | (orig) = mapping_stack_pointer->orig_val; \ | ||
| 614 | } while (0) | ||
| 615 | |||
| 616 | #define CCL_CALL_FOR_MAP_INSTRUCTION(symbol, ret_ic) \ | ||
| 617 | do { \ | ||
| 618 | struct ccl_program called_ccl; \ | ||
| 619 | if (stack_idx >= 256 \ | ||
| 620 | || (setup_ccl_program (&called_ccl, (symbol)) != 0)) \ | ||
| 621 | { \ | ||
| 622 | if (stack_idx > 0) \ | ||
| 623 | { \ | ||
| 624 | ccl_prog = ccl_prog_stack_struct[0].ccl_prog; \ | ||
| 625 | ic = ccl_prog_stack_struct[0].ic; \ | ||
| 626 | } \ | ||
| 627 | CCL_INVALID_CMD; \ | ||
| 628 | } \ | ||
| 629 | ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \ | ||
| 630 | ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \ | ||
| 631 | stack_idx++; \ | ||
| 632 | ccl_prog = called_ccl.prog; \ | ||
| 633 | ic = CCL_HEADER_MAIN; \ | ||
| 634 | goto ccl_repeat; \ | ||
| 635 | } while (0) | ||
| 604 | 636 | ||
| 605 | #define CCL_MapSingle 0x12 /* Map by single code conversion map | 637 | #define CCL_MapSingle 0x12 /* Map by single code conversion map |
| 606 | 1:ExtendedCOMMNDXXXRRRrrrXXXXX | 638 | 1:ExtendedCOMMNDXXXRRRrrrXXXXX |
| @@ -808,6 +840,9 @@ ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed) | |||
| 808 | if (ccl->buf_magnification ==0) /* We can't produce any bytes. */ | 840 | if (ccl->buf_magnification ==0) /* We can't produce any bytes. */ |
| 809 | dst = NULL; | 841 | dst = NULL; |
| 810 | 842 | ||
| 843 | /* Set mapping stack pointer. */ | ||
| 844 | mapping_stack_pointer = mapping_stack; | ||
| 845 | |||
| 811 | #ifdef CCL_DEBUG | 846 | #ifdef CCL_DEBUG |
| 812 | ccl_backtrace_idx = 0; | 847 | ccl_backtrace_idx = 0; |
| 813 | #endif | 848 | #endif |
| @@ -1371,6 +1406,10 @@ ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed) | |||
| 1371 | reg[rrr] = XUINT (value); | 1406 | reg[rrr] = XUINT (value); |
| 1372 | break; | 1407 | break; |
| 1373 | } | 1408 | } |
| 1409 | else if (SYMBOLP (content)) | ||
| 1410 | CCL_CALL_FOR_MAP_INSTRUCTION (content, fin_ic); | ||
| 1411 | else | ||
| 1412 | CCL_INVALID_CMD; | ||
| 1374 | } | 1413 | } |
| 1375 | if (i == j) | 1414 | if (i == j) |
| 1376 | reg[RRR] = -1; | 1415 | reg[RRR] = -1; |
| @@ -1383,10 +1422,27 @@ ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed) | |||
| 1383 | Lisp_Object map, content, attrib, value; | 1422 | Lisp_Object map, content, attrib, value; |
| 1384 | int point, size, map_vector_size; | 1423 | int point, size, map_vector_size; |
| 1385 | int map_set_rest_length, fin_ic; | 1424 | int map_set_rest_length, fin_ic; |
| 1425 | int current_ic = this_ic; | ||
| 1426 | |||
| 1427 | /* inhibit recursive call on MapMultiple. */ | ||
| 1428 | if (stack_idx_of_map_multiple > 0) | ||
| 1429 | { | ||
| 1430 | if (stack_idx_of_map_multiple <= stack_idx) | ||
| 1431 | { | ||
| 1432 | stack_idx_of_map_multiple = 0; | ||
| 1433 | mapping_stack_pointer = mapping_stack; | ||
| 1434 | CCL_INVALID_CMD; | ||
| 1435 | } | ||
| 1436 | } | ||
| 1437 | else | ||
| 1438 | mapping_stack_pointer = mapping_stack; | ||
| 1439 | stack_idx_of_map_multiple = 0; | ||
| 1386 | 1440 | ||
| 1387 | map_set_rest_length = | 1441 | map_set_rest_length = |
| 1388 | XINT (ccl_prog[ic++]); /* number of maps and separators. */ | 1442 | XINT (ccl_prog[ic++]); /* number of maps and separators. */ |
| 1389 | fin_ic = ic + map_set_rest_length; | 1443 | fin_ic = ic + map_set_rest_length; |
| 1444 | op = reg[rrr]; | ||
| 1445 | |||
| 1390 | if ((map_set_rest_length > reg[RRR]) && (reg[RRR] >= 0)) | 1446 | if ((map_set_rest_length > reg[RRR]) && (reg[RRR] >= 0)) |
| 1391 | { | 1447 | { |
| 1392 | ic += reg[RRR]; | 1448 | ic += reg[RRR]; |
| @@ -1397,101 +1453,165 @@ ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed) | |||
| 1397 | { | 1453 | { |
| 1398 | ic = fin_ic; | 1454 | ic = fin_ic; |
| 1399 | reg[RRR] = -1; | 1455 | reg[RRR] = -1; |
| 1456 | mapping_stack_pointer = mapping_stack; | ||
| 1400 | break; | 1457 | break; |
| 1401 | } | 1458 | } |
| 1402 | mapping_stack_pointer = mapping_stack; | ||
| 1403 | op = reg[rrr]; | ||
| 1404 | PUSH_MAPPING_STACK (0, op); | ||
| 1405 | reg[RRR] = -1; | ||
| 1406 | map_vector_size = XVECTOR (Vcode_conversion_map_vector)->size; | ||
| 1407 | for (;map_set_rest_length > 0;i++, map_set_rest_length--) | ||
| 1408 | { | ||
| 1409 | point = XINT(ccl_prog[ic++]); | ||
| 1410 | if (point < 0) | ||
| 1411 | { | ||
| 1412 | point = -point; | ||
| 1413 | if (mapping_stack_pointer | ||
| 1414 | >= &mapping_stack[MAX_MAP_SET_LEVEL]) | ||
| 1415 | { | ||
| 1416 | CCL_INVALID_CMD; | ||
| 1417 | } | ||
| 1418 | PUSH_MAPPING_STACK (map_set_rest_length - point, | ||
| 1419 | reg[rrr]); | ||
| 1420 | map_set_rest_length = point + 1; | ||
| 1421 | reg[rrr] = op; | ||
| 1422 | continue; | ||
| 1423 | } | ||
| 1424 | |||
| 1425 | if (point >= map_vector_size) continue; | ||
| 1426 | map = (XVECTOR (Vcode_conversion_map_vector) | ||
| 1427 | ->contents[point]); | ||
| 1428 | |||
| 1429 | /* Check map varidity. */ | ||
| 1430 | if (!CONSP (map)) continue; | ||
| 1431 | map = XCDR (map); | ||
| 1432 | if (!VECTORP (map)) continue; | ||
| 1433 | size = XVECTOR (map)->size; | ||
| 1434 | if (size <= 1) continue; | ||
| 1435 | |||
| 1436 | content = XVECTOR (map)->contents[0]; | ||
| 1437 | 1459 | ||
| 1438 | /* check map type, | 1460 | if (mapping_stack_pointer <= (mapping_stack + 1)) |
| 1439 | [STARTPOINT VAL1 VAL2 ...] or | 1461 | { |
| 1440 | [t ELEMENT STARTPOINT ENDPOINT] */ | 1462 | /* Set up initial state. */ |
| 1441 | if (NUMBERP (content)) | 1463 | mapping_stack_pointer = mapping_stack; |
| 1442 | { | 1464 | PUSH_MAPPING_STACK (0, op); |
| 1443 | point = XUINT (content); | 1465 | reg[RRR] = -1; |
| 1444 | point = op - point + 1; | 1466 | } |
| 1445 | if (!((point >= 1) && (point < size))) continue; | 1467 | else |
| 1446 | content = XVECTOR (map)->contents[point]; | 1468 | { |
| 1447 | } | 1469 | /* Recover after calling other ccl program. */ |
| 1448 | else if (EQ (content, Qt)) | 1470 | int orig_op; |
| 1449 | { | ||
| 1450 | if (size != 4) continue; | ||
| 1451 | if ((op >= XUINT (XVECTOR (map)->contents[2])) && | ||
| 1452 | (op < XUINT (XVECTOR (map)->contents[3]))) | ||
| 1453 | content = XVECTOR (map)->contents[1]; | ||
| 1454 | else | ||
| 1455 | continue; | ||
| 1456 | } | ||
| 1457 | else | ||
| 1458 | continue; | ||
| 1459 | 1471 | ||
| 1460 | if (NILP (content)) | 1472 | POP_MAPPING_STACK (map_set_rest_length, orig_op); |
| 1461 | continue; | 1473 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); |
| 1462 | else if (NUMBERP (content)) | 1474 | switch (op) |
| 1463 | { | ||
| 1464 | op = XINT (content); | ||
| 1465 | reg[RRR] = i; | ||
| 1466 | i += map_set_rest_length; | ||
| 1467 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); | ||
| 1468 | } | ||
| 1469 | else if (CONSP (content)) | ||
| 1470 | { | ||
| 1471 | attrib = XCAR (content); | ||
| 1472 | value = XCDR (content); | ||
| 1473 | if (!NUMBERP (attrib) || !NUMBERP (value)) | ||
| 1474 | continue; | ||
| 1475 | reg[RRR] = i; | ||
| 1476 | op = XUINT (value); | ||
| 1477 | i += map_set_rest_length; | ||
| 1478 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); | ||
| 1479 | } | ||
| 1480 | else if (EQ (content, Qt)) | ||
| 1481 | { | 1475 | { |
| 1482 | reg[RRR] = i; | 1476 | case -1: |
| 1477 | /* Regard it as Qnil. */ | ||
| 1478 | op = orig_op; | ||
| 1479 | i++; | ||
| 1480 | ic++; | ||
| 1481 | map_set_rest_length--; | ||
| 1482 | break; | ||
| 1483 | case -2: | ||
| 1484 | /* Regard it as Qt. */ | ||
| 1483 | op = reg[rrr]; | 1485 | op = reg[rrr]; |
| 1486 | i++; | ||
| 1487 | ic++; | ||
| 1488 | map_set_rest_length--; | ||
| 1489 | break; | ||
| 1490 | case -3: | ||
| 1491 | /* Regard it as Qlambda. */ | ||
| 1492 | op = orig_op; | ||
| 1493 | i += map_set_rest_length; | ||
| 1494 | ic += map_set_rest_length; | ||
| 1495 | map_set_rest_length = 0; | ||
| 1496 | break; | ||
| 1497 | default: | ||
| 1498 | /* Regard it as normal mapping. */ | ||
| 1484 | i += map_set_rest_length; | 1499 | i += map_set_rest_length; |
| 1500 | ic += map_set_rest_length; | ||
| 1485 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); | 1501 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); |
| 1486 | } | ||
| 1487 | else if (EQ (content, Qlambda)) | ||
| 1488 | { | ||
| 1489 | reg[RRR] = i; | ||
| 1490 | break; | 1502 | break; |
| 1491 | } | 1503 | } |
| 1492 | else | ||
| 1493 | CCL_INVALID_CMD; | ||
| 1494 | } | 1504 | } |
| 1505 | map_vector_size = XVECTOR (Vcode_conversion_map_vector)->size; | ||
| 1506 | |||
| 1507 | do { | ||
| 1508 | for (;map_set_rest_length > 0;i++, ic++, map_set_rest_length--) | ||
| 1509 | { | ||
| 1510 | point = XINT(ccl_prog[ic]); | ||
| 1511 | if (point < 0) | ||
| 1512 | { | ||
| 1513 | /* +1 is for including separator. */ | ||
| 1514 | point = -point + 1; | ||
| 1515 | if (mapping_stack_pointer | ||
| 1516 | >= &mapping_stack[MAX_MAP_SET_LEVEL]) | ||
| 1517 | CCL_INVALID_CMD; | ||
| 1518 | PUSH_MAPPING_STACK (map_set_rest_length - point, | ||
| 1519 | reg[rrr]); | ||
| 1520 | map_set_rest_length = point; | ||
| 1521 | reg[rrr] = op; | ||
| 1522 | continue; | ||
| 1523 | } | ||
| 1524 | |||
| 1525 | if (point >= map_vector_size) continue; | ||
| 1526 | map = (XVECTOR (Vcode_conversion_map_vector) | ||
| 1527 | ->contents[point]); | ||
| 1528 | |||
| 1529 | /* Check map varidity. */ | ||
| 1530 | if (!CONSP (map)) continue; | ||
| 1531 | map = XCDR (map); | ||
| 1532 | if (!VECTORP (map)) continue; | ||
| 1533 | size = XVECTOR (map)->size; | ||
| 1534 | if (size <= 1) continue; | ||
| 1535 | |||
| 1536 | content = XVECTOR (map)->contents[0]; | ||
| 1537 | |||
| 1538 | /* check map type, | ||
| 1539 | [STARTPOINT VAL1 VAL2 ...] or | ||
| 1540 | [t ELEMENT STARTPOINT ENDPOINT] */ | ||
| 1541 | if (NUMBERP (content)) | ||
| 1542 | { | ||
| 1543 | point = XUINT (content); | ||
| 1544 | point = op - point + 1; | ||
| 1545 | if (!((point >= 1) && (point < size))) continue; | ||
| 1546 | content = XVECTOR (map)->contents[point]; | ||
| 1547 | } | ||
| 1548 | else if (EQ (content, Qt)) | ||
| 1549 | { | ||
| 1550 | if (size != 4) continue; | ||
| 1551 | if ((op >= XUINT (XVECTOR (map)->contents[2])) && | ||
| 1552 | (op < XUINT (XVECTOR (map)->contents[3]))) | ||
| 1553 | content = XVECTOR (map)->contents[1]; | ||
| 1554 | else | ||
| 1555 | continue; | ||
| 1556 | } | ||
| 1557 | else | ||
| 1558 | continue; | ||
| 1559 | |||
| 1560 | if (NILP (content)) | ||
| 1561 | continue; | ||
| 1562 | |||
| 1563 | reg[RRR] = i; | ||
| 1564 | if (NUMBERP (content)) | ||
| 1565 | { | ||
| 1566 | op = XINT (content); | ||
| 1567 | i += map_set_rest_length - 1; | ||
| 1568 | ic += map_set_rest_length - 1; | ||
| 1569 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); | ||
| 1570 | map_set_rest_length++; | ||
| 1571 | } | ||
| 1572 | else if (CONSP (content)) | ||
| 1573 | { | ||
| 1574 | attrib = XCAR (content); | ||
| 1575 | value = XCDR (content); | ||
| 1576 | if (!NUMBERP (attrib) || !NUMBERP (value)) | ||
| 1577 | continue; | ||
| 1578 | op = XUINT (value); | ||
| 1579 | i += map_set_rest_length - 1; | ||
| 1580 | ic += map_set_rest_length - 1; | ||
| 1581 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); | ||
| 1582 | map_set_rest_length++; | ||
| 1583 | } | ||
| 1584 | else if (EQ (content, Qt)) | ||
| 1585 | { | ||
| 1586 | op = reg[rrr]; | ||
| 1587 | } | ||
| 1588 | else if (EQ (content, Qlambda)) | ||
| 1589 | { | ||
| 1590 | i += map_set_rest_length; | ||
| 1591 | ic += map_set_rest_length; | ||
| 1592 | break; | ||
| 1593 | } | ||
| 1594 | else if (SYMBOLP (content)) | ||
| 1595 | { | ||
| 1596 | if (mapping_stack_pointer | ||
| 1597 | >= &mapping_stack[MAX_MAP_SET_LEVEL]) | ||
| 1598 | CCL_INVALID_CMD; | ||
| 1599 | PUSH_MAPPING_STACK (map_set_rest_length, reg[rrr]); | ||
| 1600 | PUSH_MAPPING_STACK (map_set_rest_length, op); | ||
| 1601 | stack_idx_of_map_multiple = stack_idx + 1; | ||
| 1602 | CCL_CALL_FOR_MAP_INSTRUCTION (content, current_ic); | ||
| 1603 | } | ||
| 1604 | else | ||
| 1605 | CCL_INVALID_CMD; | ||
| 1606 | } | ||
| 1607 | if (mapping_stack_pointer <= (mapping_stack + 1)) | ||
| 1608 | break; | ||
| 1609 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); | ||
| 1610 | i += map_set_rest_length; | ||
| 1611 | ic += map_set_rest_length; | ||
| 1612 | POP_MAPPING_STACK (map_set_rest_length, reg[rrr]); | ||
| 1613 | } while (1); | ||
| 1614 | |||
| 1495 | ic = fin_ic; | 1615 | ic = fin_ic; |
| 1496 | } | 1616 | } |
| 1497 | reg[rrr] = op; | 1617 | reg[rrr] = op; |
| @@ -1545,6 +1665,8 @@ ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed) | |||
| 1545 | reg[rrr] = XUINT(value); | 1665 | reg[rrr] = XUINT(value); |
| 1546 | break; | 1666 | break; |
| 1547 | } | 1667 | } |
| 1668 | else if (SYMBOLP (content)) | ||
| 1669 | CCL_CALL_FOR_MAP_INSTRUCTION (content, ic); | ||
| 1548 | else | 1670 | else |
| 1549 | reg[RRR] = -1; | 1671 | reg[RRR] = -1; |
| 1550 | } | 1672 | } |