comparison src/vim9compile.c @ 19564:06f29b6ea04a v8.2.0339

patch 8.2.0339: Vim9: function return type may depend on arguments Commit: https://github.com/vim/vim/commit/fbdd08ed9b1798885915c7f27c94786906d258e4 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 1 14:04:46 2020 +0100 patch 8.2.0339: Vim9: function return type may depend on arguments Problem: Vim9: function return type may depend on arguments. Solution: Instead of a fixed return type use a function to figure out the return type.
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 Mar 2020 14:15:04 +0100
parents 6b7719b8f9b9
children ec1eeb1b69e2
comparison
equal deleted inserted replaced
19563:5d3a4b28a95b 19564:06f29b6ea04a
990 static int 990 static int
991 generate_BCALL(cctx_T *cctx, int func_idx, int argcount) 991 generate_BCALL(cctx_T *cctx, int func_idx, int argcount)
992 { 992 {
993 isn_T *isn; 993 isn_T *isn;
994 garray_T *stack = &cctx->ctx_type_stack; 994 garray_T *stack = &cctx->ctx_type_stack;
995 type_T *argtypes[MAX_FUNC_ARGS];
996 int i;
995 997
996 if (check_internal_func(func_idx, argcount) == FAIL) 998 if (check_internal_func(func_idx, argcount) == FAIL)
997 return FAIL; 999 return FAIL;
998 1000
999 if ((isn = generate_instr(cctx, ISN_BCALL)) == NULL) 1001 if ((isn = generate_instr(cctx, ISN_BCALL)) == NULL)
1000 return FAIL; 1002 return FAIL;
1001 isn->isn_arg.bfunc.cbf_idx = func_idx; 1003 isn->isn_arg.bfunc.cbf_idx = func_idx;
1002 isn->isn_arg.bfunc.cbf_argcount = argcount; 1004 isn->isn_arg.bfunc.cbf_argcount = argcount;
1003 1005
1006 for (i = 0; i < argcount; ++i)
1007 argtypes[i] = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
1008
1004 stack->ga_len -= argcount; // drop the arguments 1009 stack->ga_len -= argcount; // drop the arguments
1005 if (ga_grow(stack, 1) == FAIL) 1010 if (ga_grow(stack, 1) == FAIL)
1006 return FAIL; 1011 return FAIL;
1007 ((type_T **)stack->ga_data)[stack->ga_len] = 1012 ((type_T **)stack->ga_data)[stack->ga_len] =
1008 internal_func_ret_type(func_idx, argcount); 1013 internal_func_ret_type(func_idx, argcount, argtypes);
1009 ++stack->ga_len; // add return value 1014 ++stack->ga_len; // add return value
1010 1015
1011 return OK; 1016 return OK;
1012 } 1017 }
1013 1018
1372 *arg += len; 1377 *arg += len;
1373 return &t_number; 1378 return &t_number;
1374 } 1379 }
1375 break; 1380 break;
1376 case 'p': 1381 case 'p':
1377 if (len == 4 && STRNCMP(*arg, "partial", len) == 0) 1382 if (len == 7 && STRNCMP(*arg, "partial", len) == 0)
1378 { 1383 {
1379 *arg += len; 1384 *arg += len;
1380 // TODO: arguments and return type 1385 // TODO: arguments and return type
1381 return &t_partial_any; 1386 return &t_partial_any;
1382 } 1387 }