summaryrefslogtreecommitdiff
path: root/src/vim9execute.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-12-10 18:42:12 +0000
committerBram Moolenaar <Bram@vim.org>2022-12-10 18:42:12 +0000
commit7ce7daf6cd6a7ed27eac060699026640b4b239a8 (patch)
treebb6ddd44c1e6133c82ce791d9568405723f251af /src/vim9execute.c
parent6c87bbb4e45515e70ac1728cabd1451063bf427d (diff)
downloadvim-git-7ce7daf6cd6a7ed27eac060699026640b4b239a8.tar.gz
patch 9.0.1045: in a class object members cannot be initializedv9.0.1045
Problem: In a class object members cannot be initialized. Solution: Support initializing object members. Make "dissassemble" work on an object method.
Diffstat (limited to 'src/vim9execute.c')
-rw-r--r--src/vim9execute.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 96983bbdc..6a6ec41e1 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -3009,7 +3009,7 @@ exec_instructions(ectx_T *ectx)
iptr = &ectx->ec_instr[ectx->ec_iidx++];
switch (iptr->isn_type)
{
- // Constructor, new() method.
+ // Constructor, first instruction in a new() method.
case ISN_CONSTRUCT:
// "this" is always the local variable at index zero
tv = STACK_TV_VAR(0);
@@ -5114,7 +5114,7 @@ exec_instructions(ectx_T *ectx)
}
break;
- case ISN_OBJ_MEMBER:
+ case ISN_GET_OBJ_MEMBER:
{
tv = STACK_TV_BOT(-1);
if (tv->v_type != VAR_OBJECT)
@@ -5143,6 +5143,18 @@ exec_instructions(ectx_T *ectx)
}
break;
+ case ISN_STORE_THIS:
+ {
+ int idx = iptr->isn_arg.number;
+ object_T *obj = STACK_TV_VAR(0)->vval.v_object;
+ // the members are located right after the object struct
+ typval_T *mtv = ((typval_T *)(obj + 1)) + idx;
+ clear_tv(mtv);
+ *mtv = *STACK_TV_BOT(-1);
+ --ectx->ec_stack.ga_len;
+ }
+ break;
+
case ISN_CLEARDICT:
dict_stack_drop();
break;
@@ -6805,7 +6817,9 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
case ISN_MEMBER: smsg("%s%4d MEMBER", pfx, current); break;
case ISN_STRINGMEMBER: smsg("%s%4d MEMBER %s", pfx, current,
iptr->isn_arg.string); break;
- case ISN_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d", pfx, current,
+ case ISN_GET_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d", pfx, current,
+ (int)iptr->isn_arg.number); break;
+ case ISN_STORE_THIS: smsg("%s%4d STORE_THIS %d", pfx, current,
(int)iptr->isn_arg.number); break;
case ISN_CLEARDICT: smsg("%s%4d CLEARDICT", pfx, current); break;
case ISN_USEDICT: smsg("%s%4d USEDICT", pfx, current); break;