Mercurial > vim
comparison src/vim9compile.c @ 20532:cb4831fa7e25 v8.2.0820
patch 8.2.0820: Vim9: function type isn't set until compiled
Commit: https://github.com/vim/vim/commit/6ff71d8b7fbdf667a2f119a2487302e240961816
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 24 23:45:24 2020 +0200
patch 8.2.0820: Vim9: function type isn't set until compiled
Problem: Vim9: function type isn't set until compiled.
Solution: Set function type early.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 25 May 2020 00:00:04 +0200 |
parents | 489cb75c76b6 |
children | ae758aa4ee5e |
comparison
equal
deleted
inserted
replaced
20531:6eb8347bcf1a | 20532:cb4831fa7e25 |
---|---|
6761 dfunc->df_closure_count = cctx.ctx_closure_count; | 6761 dfunc->df_closure_count = cctx.ctx_closure_count; |
6762 if (cctx.ctx_outer_used) | 6762 if (cctx.ctx_outer_used) |
6763 ufunc->uf_flags |= FC_CLOSURE; | 6763 ufunc->uf_flags |= FC_CLOSURE; |
6764 } | 6764 } |
6765 | 6765 |
6766 { | |
6767 int varargs = ufunc->uf_va_name != NULL; | |
6768 int argcount = ufunc->uf_args.ga_len; | |
6769 | |
6770 // Create a type for the function, with the return type and any | |
6771 // argument types. | |
6772 // A vararg is included in uf_args.ga_len but not in uf_arg_types. | |
6773 // The type is included in "tt_args". | |
6774 if (argcount > 0 || varargs) | |
6775 { | |
6776 ufunc->uf_func_type = alloc_func_type(ufunc->uf_ret_type, | |
6777 argcount, &ufunc->uf_type_list); | |
6778 // Add argument types to the function type. | |
6779 if (func_type_add_arg_types(ufunc->uf_func_type, | |
6780 argcount + varargs, | |
6781 &ufunc->uf_type_list) == FAIL) | |
6782 { | |
6783 ret = FAIL; | |
6784 goto erret; | |
6785 } | |
6786 ufunc->uf_func_type->tt_argcount = argcount + varargs; | |
6787 ufunc->uf_func_type->tt_min_argcount = | |
6788 argcount - ufunc->uf_def_args.ga_len; | |
6789 if (ufunc->uf_arg_types == NULL) | |
6790 { | |
6791 int i; | |
6792 | |
6793 // lambda does not have argument types. | |
6794 for (i = 0; i < argcount; ++i) | |
6795 ufunc->uf_func_type->tt_args[i] = &t_any; | |
6796 } | |
6797 else | |
6798 mch_memmove(ufunc->uf_func_type->tt_args, | |
6799 ufunc->uf_arg_types, sizeof(type_T *) * argcount); | |
6800 if (varargs) | |
6801 { | |
6802 ufunc->uf_func_type->tt_args[argcount] = | |
6803 ufunc->uf_va_type == NULL ? &t_any : ufunc->uf_va_type; | |
6804 ufunc->uf_func_type->tt_flags = TTFLAG_VARARGS; | |
6805 } | |
6806 } | |
6807 else | |
6808 // No arguments, can use a predefined type. | |
6809 ufunc->uf_func_type = get_func_type(ufunc->uf_ret_type, | |
6810 argcount, &ufunc->uf_type_list); | |
6811 | |
6812 } | |
6813 | |
6814 ret = OK; | 6766 ret = OK; |
6815 | 6767 |
6816 erret: | 6768 erret: |
6817 if (ret == FAIL) | 6769 if (ret == FAIL) |
6818 { | 6770 { |
6844 free_imported(&cctx); | 6796 free_imported(&cctx); |
6845 free_locals(&cctx); | 6797 free_locals(&cctx); |
6846 ga_clear(&cctx.ctx_type_stack); | 6798 ga_clear(&cctx.ctx_type_stack); |
6847 return ret; | 6799 return ret; |
6848 } | 6800 } |
6801 | |
6802 void | |
6803 set_function_type(ufunc_T *ufunc) | |
6804 { | |
6805 int varargs = ufunc->uf_va_name != NULL; | |
6806 int argcount = ufunc->uf_args.ga_len; | |
6807 | |
6808 // Create a type for the function, with the return type and any | |
6809 // argument types. | |
6810 // A vararg is included in uf_args.ga_len but not in uf_arg_types. | |
6811 // The type is included in "tt_args". | |
6812 if (argcount > 0 || varargs) | |
6813 { | |
6814 ufunc->uf_func_type = alloc_func_type(ufunc->uf_ret_type, | |
6815 argcount, &ufunc->uf_type_list); | |
6816 // Add argument types to the function type. | |
6817 if (func_type_add_arg_types(ufunc->uf_func_type, | |
6818 argcount + varargs, | |
6819 &ufunc->uf_type_list) == FAIL) | |
6820 return; | |
6821 ufunc->uf_func_type->tt_argcount = argcount + varargs; | |
6822 ufunc->uf_func_type->tt_min_argcount = | |
6823 argcount - ufunc->uf_def_args.ga_len; | |
6824 if (ufunc->uf_arg_types == NULL) | |
6825 { | |
6826 int i; | |
6827 | |
6828 // lambda does not have argument types. | |
6829 for (i = 0; i < argcount; ++i) | |
6830 ufunc->uf_func_type->tt_args[i] = &t_any; | |
6831 } | |
6832 else | |
6833 mch_memmove(ufunc->uf_func_type->tt_args, | |
6834 ufunc->uf_arg_types, sizeof(type_T *) * argcount); | |
6835 if (varargs) | |
6836 { | |
6837 ufunc->uf_func_type->tt_args[argcount] = | |
6838 ufunc->uf_va_type == NULL ? &t_any : ufunc->uf_va_type; | |
6839 ufunc->uf_func_type->tt_flags = TTFLAG_VARARGS; | |
6840 } | |
6841 } | |
6842 else | |
6843 // No arguments, can use a predefined type. | |
6844 ufunc->uf_func_type = get_func_type(ufunc->uf_ret_type, | |
6845 argcount, &ufunc->uf_type_list); | |
6846 } | |
6847 | |
6849 | 6848 |
6850 /* | 6849 /* |
6851 * Delete an instruction, free what it contains. | 6850 * Delete an instruction, free what it contains. |
6852 */ | 6851 */ |
6853 void | 6852 void |