Mercurial > vim
comparison src/vim9compile.c @ 22655:eabe2c1444ea v8.2.1876
patch 8.2.1876: Vim9: argument types are not checked at compile time
Commit: https://github.com/vim/vim/commit/94738d8fab09c5563e1512f1695e047c715ad274
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 21 14:25:07 2020 +0200
patch 8.2.1876: Vim9: argument types are not checked at compile time
Problem: Vim9: argument types for builtin functions are not checked at
compile time.
Solution: Add an argument type checking mechanism. Implement type checks for
one function.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 21 Oct 2020 14:30:04 +0200 |
parents | 5bd53bf63836 |
children | c6b17787a38f |
comparison
equal
deleted
inserted
replaced
22654:ce95914cd5f2 | 22655:eabe2c1444ea |
---|---|
1458 generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call) | 1458 generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call) |
1459 { | 1459 { |
1460 isn_T *isn; | 1460 isn_T *isn; |
1461 garray_T *stack = &cctx->ctx_type_stack; | 1461 garray_T *stack = &cctx->ctx_type_stack; |
1462 int argoff; | 1462 int argoff; |
1463 type_T *argtypes[MAX_FUNC_ARGS]; | 1463 type_T **argtypes; |
1464 int i; | |
1465 | 1464 |
1466 RETURN_OK_IF_SKIP(cctx); | 1465 RETURN_OK_IF_SKIP(cctx); |
1467 argoff = check_internal_func(func_idx, argcount); | 1466 argoff = check_internal_func(func_idx, argcount); |
1468 if (argoff < 0) | 1467 if (argoff < 0) |
1469 return FAIL; | 1468 return FAIL; |
1474 return FAIL; | 1473 return FAIL; |
1475 isn->isn_arg.shuffle.shfl_item = argcount; | 1474 isn->isn_arg.shuffle.shfl_item = argcount; |
1476 isn->isn_arg.shuffle.shfl_up = argoff - 1; | 1475 isn->isn_arg.shuffle.shfl_up = argoff - 1; |
1477 } | 1476 } |
1478 | 1477 |
1478 // Check the types of the arguments. | |
1479 argtypes = ((type_T **)stack->ga_data) + stack->ga_len - argcount; | |
1480 if (argcount > 0 && internal_func_check_arg_types( | |
1481 *argtypes, func_idx, argcount) == FAIL) | |
1482 return FAIL; | |
1483 | |
1479 if ((isn = generate_instr(cctx, ISN_BCALL)) == NULL) | 1484 if ((isn = generate_instr(cctx, ISN_BCALL)) == NULL) |
1480 return FAIL; | 1485 return FAIL; |
1481 isn->isn_arg.bfunc.cbf_idx = func_idx; | 1486 isn->isn_arg.bfunc.cbf_idx = func_idx; |
1482 isn->isn_arg.bfunc.cbf_argcount = argcount; | 1487 isn->isn_arg.bfunc.cbf_argcount = argcount; |
1483 | 1488 |
1484 for (i = 0; i < argcount; ++i) | 1489 // Drop the argument types and push the return type. |
1485 argtypes[i] = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i]; | 1490 stack->ga_len -= argcount; |
1486 | |
1487 stack->ga_len -= argcount; // drop the arguments | |
1488 if (ga_grow(stack, 1) == FAIL) | 1491 if (ga_grow(stack, 1) == FAIL) |
1489 return FAIL; | 1492 return FAIL; |
1490 ((type_T **)stack->ga_data)[stack->ga_len] = | 1493 ((type_T **)stack->ga_data)[stack->ga_len] = |
1491 internal_func_ret_type(func_idx, argcount, argtypes); | 1494 internal_func_ret_type(func_idx, argcount, argtypes); |
1492 ++stack->ga_len; // add return value | 1495 ++stack->ga_len; |
1493 | 1496 |
1494 return OK; | 1497 return OK; |
1495 } | 1498 } |
1496 | 1499 |
1497 /* | 1500 /* |