Mercurial > vim
comparison src/vim9execute.c @ 31424:e31fc75f6aff v9.0.1045
patch 9.0.1045: in a class object members cannot be initialized
Commit: https://github.com/vim/vim/commit/7ce7daf6cd6a7ed27eac060699026640b4b239a8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 10 18:42:12 2022 +0000
patch 9.0.1045: in a class object members cannot be initialized
Problem: In a class object members cannot be initialized.
Solution: Support initializing object members. Make "dissassemble" work on
an object method.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Dec 2022 19:45:04 +0100 |
parents | f088f1d97eee |
children | e572ff386670 |
comparison
equal
deleted
inserted
replaced
31423:66c85efdf4b0 | 31424:e31fc75f6aff |
---|---|
3007 * most efficient way. | 3007 * most efficient way. |
3008 */ | 3008 */ |
3009 iptr = &ectx->ec_instr[ectx->ec_iidx++]; | 3009 iptr = &ectx->ec_instr[ectx->ec_iidx++]; |
3010 switch (iptr->isn_type) | 3010 switch (iptr->isn_type) |
3011 { | 3011 { |
3012 // Constructor, new() method. | 3012 // Constructor, first instruction in a new() method. |
3013 case ISN_CONSTRUCT: | 3013 case ISN_CONSTRUCT: |
3014 // "this" is always the local variable at index zero | 3014 // "this" is always the local variable at index zero |
3015 tv = STACK_TV_VAR(0); | 3015 tv = STACK_TV_VAR(0); |
3016 tv->v_type = VAR_OBJECT; | 3016 tv->v_type = VAR_OBJECT; |
3017 tv->vval.v_object = alloc_clear( | 3017 tv->vval.v_object = alloc_clear( |
5112 | 5112 |
5113 copy_tv(&di->di_tv, tv); | 5113 copy_tv(&di->di_tv, tv); |
5114 } | 5114 } |
5115 break; | 5115 break; |
5116 | 5116 |
5117 case ISN_OBJ_MEMBER: | 5117 case ISN_GET_OBJ_MEMBER: |
5118 { | 5118 { |
5119 tv = STACK_TV_BOT(-1); | 5119 tv = STACK_TV_BOT(-1); |
5120 if (tv->v_type != VAR_OBJECT) | 5120 if (tv->v_type != VAR_OBJECT) |
5121 { | 5121 { |
5122 SOURCING_LNUM = iptr->isn_lnum; | 5122 SOURCING_LNUM = iptr->isn_lnum; |
5138 *tv = *mtv; | 5138 *tv = *mtv; |
5139 | 5139 |
5140 // Unreference the object after getting the member, it may | 5140 // Unreference the object after getting the member, it may |
5141 // be freed. | 5141 // be freed. |
5142 object_unref(obj); | 5142 object_unref(obj); |
5143 } | |
5144 break; | |
5145 | |
5146 case ISN_STORE_THIS: | |
5147 { | |
5148 int idx = iptr->isn_arg.number; | |
5149 object_T *obj = STACK_TV_VAR(0)->vval.v_object; | |
5150 // the members are located right after the object struct | |
5151 typval_T *mtv = ((typval_T *)(obj + 1)) + idx; | |
5152 clear_tv(mtv); | |
5153 *mtv = *STACK_TV_BOT(-1); | |
5154 --ectx->ec_stack.ga_len; | |
5143 } | 5155 } |
5144 break; | 5156 break; |
5145 | 5157 |
5146 case ISN_CLEARDICT: | 5158 case ISN_CLEARDICT: |
5147 dict_stack_drop(); | 5159 dict_stack_drop(); |
6803 iptr->isn_arg.getitem.gi_with_op ? | 6815 iptr->isn_arg.getitem.gi_with_op ? |
6804 " with op" : ""); break; | 6816 " with op" : ""); break; |
6805 case ISN_MEMBER: smsg("%s%4d MEMBER", pfx, current); break; | 6817 case ISN_MEMBER: smsg("%s%4d MEMBER", pfx, current); break; |
6806 case ISN_STRINGMEMBER: smsg("%s%4d MEMBER %s", pfx, current, | 6818 case ISN_STRINGMEMBER: smsg("%s%4d MEMBER %s", pfx, current, |
6807 iptr->isn_arg.string); break; | 6819 iptr->isn_arg.string); break; |
6808 case ISN_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d", pfx, current, | 6820 case ISN_GET_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d", pfx, current, |
6821 (int)iptr->isn_arg.number); break; | |
6822 case ISN_STORE_THIS: smsg("%s%4d STORE_THIS %d", pfx, current, | |
6809 (int)iptr->isn_arg.number); break; | 6823 (int)iptr->isn_arg.number); break; |
6810 case ISN_CLEARDICT: smsg("%s%4d CLEARDICT", pfx, current); break; | 6824 case ISN_CLEARDICT: smsg("%s%4d CLEARDICT", pfx, current); break; |
6811 case ISN_USEDICT: smsg("%s%4d USEDICT", pfx, current); break; | 6825 case ISN_USEDICT: smsg("%s%4d USEDICT", pfx, current); break; |
6812 | 6826 |
6813 case ISN_NEGATENR: smsg("%s%4d NEGATENR", pfx, current); break; | 6827 case ISN_NEGATENR: smsg("%s%4d NEGATENR", pfx, current); break; |