vim-patch:8.1.1803: all builtin functions are global

Problem:    All builtin functions are global.
Solution:   Add the method call operator ->.  Implemented for a limited number
            of functions.
ac92e25a33

- Note that to *exactly* port hunk @@ -7376,18 +7444,19 from
  handle_subscript(), we need the :scriptversion patches (I have an open
  PR for those, but this patch works fine without them anyway).
- Port call_internal_func() from v7.4.2058.
- Adjust some error messages in tests, as they rely on the Blob patches.
- Add a modeline to test_method.vim.

Ignore the global_functions and base_method tables and prefer the
current GPerf implementation. Instead, add an extra base_arg field to
VimLFuncDef that holds the number of the argument to use as the base
(1-indexed, so that 0 may be used to refer to functions that cannot be
used as methods).

This also means we support using any argument as a base from the get-go,
rather than just the first (Vim includes this ability in future patches,
however).

To mark a function as usable as a method, use the "base" key as
described in eval.lua.
This commit is contained in:
Sean Dewar
2021-08-05 19:46:42 +01:00
parent 4042ae5a2b
commit e6be6c307a
10 changed files with 299 additions and 53 deletions

View File

@@ -1514,7 +1514,10 @@ call_func(
}
} else if (fp != NULL || !builtin_function((const char *)rfname, -1)) {
// User defined function.
if (fp == NULL) {
if (funcexe->basetv != NULL) {
// TODO(seandewar): support User function: base->Method()
fp = NULL;
} else if (fp == NULL) {
fp = find_func(rfname);
}
@@ -1560,20 +1563,13 @@ call_func(
error = ERROR_NONE;
}
}
} else if (funcexe->basetv != NULL) {
// Find the method name in the table, call its implementation.
error = call_internal_method(fname, argcount, argvars, rettv,
funcexe->basetv);
} else {
// Find the function name in the table, call its implementation.
const VimLFuncDef *const fdef = find_internal_func((const char *)fname);
if (fdef != NULL) {
if (argcount < fdef->min_argc) {
error = ERROR_TOOFEW;
} else if (argcount > fdef->max_argc) {
error = ERROR_TOOMANY;
} else {
argvars[argcount].v_type = VAR_UNKNOWN;
fdef->func(argvars, rettv, fdef->data);
error = ERROR_NONE;
}
}
error = call_internal_func(fname, argcount, argvars, rettv);
}
/*
* The function call (or "FuncUndefined" autocommand sequence) might
@@ -2937,7 +2933,7 @@ void ex_call(exarg_T *eap)
rettv.v_type = VAR_UNKNOWN; // tv_clear() uses this.
if (*startarg != '(') {
EMSG2(_("E107: Missing parentheses: %s"), eap->arg);
EMSG2(_(e_missingparen), eap->arg);
goto end;
}