diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-12-10 18:42:12 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-12-10 18:42:12 +0000 |
commit | 7ce7daf6cd6a7ed27eac060699026640b4b239a8 (patch) | |
tree | bb6ddd44c1e6133c82ce791d9568405723f251af /src/vim9instr.c | |
parent | 6c87bbb4e45515e70ac1728cabd1451063bf427d (diff) |
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/vim9instr.c')
-rw-r--r-- | src/vim9instr.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/vim9instr.c b/src/vim9instr.c index 88bd2ca42a..49f8c52126 100644 --- a/src/vim9instr.c +++ b/src/vim9instr.c @@ -132,15 +132,16 @@ generate_CONSTRUCT(cctx_T *cctx, class_T *cl) } /* - * Generate ISN_OBJ_MEMBER - access object member by indes. + * Generate ISN_GET_OBJ_MEMBER - access member of object at bottom of stack by + * index. */ int -generate_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type) +generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type) { RETURN_OK_IF_SKIP(cctx); // drop the object type - isn_T *isn = generate_instr_drop(cctx, ISN_OBJ_MEMBER, 1); + isn_T *isn = generate_instr_drop(cctx, ISN_GET_OBJ_MEMBER, 1); if (isn == NULL) return FAIL; @@ -149,6 +150,24 @@ generate_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type) } /* + * Generate ISN_STORE_THIS - store value in member of "this" object with member + * index "idx". + */ + int +generate_STORE_THIS(cctx_T *cctx, int idx) +{ + RETURN_OK_IF_SKIP(cctx); + + // drop the value type + isn_T *isn = generate_instr_drop(cctx, ISN_STORE_THIS, 1); + if (isn == NULL) + return FAIL; + + isn->isn_arg.number = idx; + return OK; +} + +/* * If type at "offset" isn't already VAR_STRING then generate ISN_2STRING. * But only for simple types. * When "tolerant" is TRUE convert most types to string, e.g. a List. @@ -2458,6 +2477,7 @@ delete_instr(isn_T *isn) case ISN_FINISH: case ISN_FOR: case ISN_GETITEM: + case ISN_GET_OBJ_MEMBER: case ISN_JUMP: case ISN_JUMP_IF_ARG_SET: case ISN_LISTAPPEND: @@ -2477,7 +2497,6 @@ delete_instr(isn_T *isn) case ISN_NEWDICT: case ISN_NEWLIST: case ISN_NEWPARTIAL: - case ISN_OBJ_MEMBER: case ISN_OPANY: case ISN_OPFLOAT: case ISN_OPNR: @@ -2495,8 +2514,8 @@ delete_instr(isn_T *isn) case ISN_REDIREND: case ISN_REDIRSTART: case ISN_RETURN: - case ISN_RETURN_VOID: case ISN_RETURN_OBJECT: + case ISN_RETURN_VOID: case ISN_SHUFFLE: case ISN_SLICE: case ISN_SOURCE: @@ -2504,6 +2523,7 @@ delete_instr(isn_T *isn) case ISN_STOREINDEX: case ISN_STORENR: case ISN_STOREOUTER: + case ISN_STORE_THIS: case ISN_STORERANGE: case ISN_STOREREG: case ISN_STOREV: |