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.
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 88bd2ca..49f8c52 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -132,15 +132,16 @@
}
/*
- * 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 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 @@
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 @@
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 @@
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 @@
case ISN_STOREINDEX:
case ISN_STORENR:
case ISN_STOREOUTER:
+ case ISN_STORE_THIS:
case ISN_STORERANGE:
case ISN_STOREREG:
case ISN_STOREV: