comparison src/vim9compile.c @ 22637:4d4042683371 v8.2.1867

patch 8.2.1867: Vim9: argument to add() not checked for blob Commit: https://github.com/vim/vim/commit/80b0e5ea1132d1d7cf78c77bc14c686c836a0d25 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Oct 19 20:45:36 2020 +0200 patch 8.2.1867: Vim9: argument to add() not checked for blob Problem: Vim9: argument to add() not checked for blob. Solution: Add the BLOBAPPEND instruction.
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Oct 2020 21:00:04 +0200
parents 6589dae9696c
children 5bd53bf63836
comparison
equal deleted inserted replaced
22636:8e65b58ff15d 22637:4d4042683371
1512 expected = list_type->tt_member; 1512 expected = list_type->tt_member;
1513 if (need_type(item_type, expected, -1, cctx, FALSE, FALSE) == FAIL) 1513 if (need_type(item_type, expected, -1, cctx, FALSE, FALSE) == FAIL)
1514 return FAIL; 1514 return FAIL;
1515 1515
1516 if (generate_instr(cctx, ISN_LISTAPPEND) == NULL) 1516 if (generate_instr(cctx, ISN_LISTAPPEND) == NULL)
1517 return FAIL;
1518
1519 --stack->ga_len; // drop the argument
1520 return OK;
1521 }
1522
1523 /*
1524 * Generate an ISN_BLOBAPPEND instruction. Works like add().
1525 * Argument count is already checked.
1526 */
1527 static int
1528 generate_BLOBAPPEND(cctx_T *cctx)
1529 {
1530 garray_T *stack = &cctx->ctx_type_stack;
1531 type_T *item_type;
1532
1533 // Caller already checked that blob_type is a blob.
1534 item_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
1535 if (need_type(item_type, &t_number, -1, cctx, FALSE, FALSE) == FAIL)
1536 return FAIL;
1537
1538 if (generate_instr(cctx, ISN_BLOBAPPEND) == NULL)
1517 return FAIL; 1539 return FAIL;
1518 1540
1519 --stack->ga_len; // drop the argument 1541 --stack->ga_len; // drop the argument
1520 return OK; 1542 return OK;
1521 } 1543 }
2568 { 2590 {
2569 garray_T *stack = &cctx->ctx_type_stack; 2591 garray_T *stack = &cctx->ctx_type_stack;
2570 type_T *type = ((type_T **)stack->ga_data)[ 2592 type_T *type = ((type_T **)stack->ga_data)[
2571 stack->ga_len - 2]; 2593 stack->ga_len - 2];
2572 2594
2573 // TODO: also check for VAR_BLOB
2574 if (type->tt_type == VAR_LIST) 2595 if (type->tt_type == VAR_LIST)
2575 { 2596 {
2576 // inline "add(list, item)" so that the type can be checked 2597 // inline "add(list, item)" so that the type can be checked
2577 res = generate_LISTAPPEND(cctx); 2598 res = generate_LISTAPPEND(cctx);
2599 idx = -1;
2600 }
2601 else if (type->tt_type == VAR_BLOB)
2602 {
2603 // inline "add(blob, nr)" so that the type can be checked
2604 res = generate_BLOBAPPEND(cctx);
2578 idx = -1; 2605 idx = -1;
2579 } 2606 }
2580 } 2607 }
2581 2608
2582 if (idx >= 0) 2609 if (idx >= 0)
5419 break; 5446 break;
5420 case VAR_STRING: 5447 case VAR_STRING:
5421 generate_PUSHS(cctx, NULL); 5448 generate_PUSHS(cctx, NULL);
5422 break; 5449 break;
5423 case VAR_BLOB: 5450 case VAR_BLOB:
5424 generate_PUSHBLOB(cctx, NULL); 5451 generate_PUSHBLOB(cctx, blob_alloc());
5425 break; 5452 break;
5426 case VAR_FUNC: 5453 case VAR_FUNC:
5427 generate_PUSHFUNC(cctx, NULL, &t_func_void); 5454 generate_PUSHFUNC(cctx, NULL, &t_func_void);
5428 break; 5455 break;
5429 case VAR_LIST: 5456 case VAR_LIST:
7673 case ISN_ADDBLOB: 7700 case ISN_ADDBLOB:
7674 case ISN_ADDLIST: 7701 case ISN_ADDLIST:
7675 case ISN_ANYINDEX: 7702 case ISN_ANYINDEX:
7676 case ISN_ANYSLICE: 7703 case ISN_ANYSLICE:
7677 case ISN_BCALL: 7704 case ISN_BCALL:
7705 case ISN_BLOBAPPEND:
7678 case ISN_CATCH: 7706 case ISN_CATCH:
7679 case ISN_CHECKLEN: 7707 case ISN_CHECKLEN:
7680 case ISN_CHECKNR: 7708 case ISN_CHECKNR:
7681 case ISN_COMPAREANY: 7709 case ISN_COMPAREANY:
7682 case ISN_COMPAREBLOB: 7710 case ISN_COMPAREBLOB: