forked from aniani/vim
patch 9.1.0148: Vim9: can't call internal methods with objects
Problem: Vim9: can't call internal methods with objects Solution: Add support for empty(), len() and string() function calls for objects (Yegappan Lakshmanan) closes: #14129 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
2157035637
commit
d3eae7bc11
@@ -1013,6 +1013,32 @@ failret:
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compile a builtin method call of an object (e.g. string(), len(), empty(),
|
||||
* etc.) if the class implements it.
|
||||
*/
|
||||
static int
|
||||
compile_builtin_method_call(cctx_T *cctx, class_builtin_T builtin_method)
|
||||
{
|
||||
type_T *type = get_decl_type_on_stack(cctx, 0);
|
||||
int res = FAIL;
|
||||
|
||||
// If the built in function is invoked on an object and the class
|
||||
// implements the corresponding built in method, then invoke the object
|
||||
// method.
|
||||
if (type->tt_type == VAR_OBJECT)
|
||||
{
|
||||
int method_idx;
|
||||
ufunc_T *uf = class_get_builtin_method(type->tt_class, builtin_method,
|
||||
&method_idx);
|
||||
if (uf != NULL)
|
||||
res = generate_CALL(cctx, uf, type->tt_class, method_idx, 0);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Compile a function call: name(arg1, arg2)
|
||||
* "arg" points to "name", "arg + varlen" to the "(".
|
||||
@@ -1170,6 +1196,20 @@ compile_call(
|
||||
idx = -1;
|
||||
}
|
||||
|
||||
class_builtin_T builtin_method = CLASS_BUILTIN_INVALID;
|
||||
if (STRCMP(name, "string") == 0)
|
||||
builtin_method = CLASS_BUILTIN_STRING;
|
||||
else if (STRCMP(name, "empty") == 0)
|
||||
builtin_method = CLASS_BUILTIN_EMPTY;
|
||||
else if (STRCMP(name, "len") == 0)
|
||||
builtin_method = CLASS_BUILTIN_LEN;
|
||||
if (builtin_method != CLASS_BUILTIN_INVALID)
|
||||
{
|
||||
res = compile_builtin_method_call(cctx, builtin_method);
|
||||
if (res == OK)
|
||||
idx = -1;
|
||||
}
|
||||
|
||||
if (idx >= 0)
|
||||
res = generate_BCALL(cctx, idx, argcount, argcount_init == 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user