Mercurial > vim
diff src/structs.h @ 31396:307f68a41b03 v9.0.1031
patch 9.0.1031: Vim9 class is not implemented yet
Commit: https://github.com/vim/vim/commit/00b28d6c23d8e662cab27e461825777c0a2e387a
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 8 15:32:33 2022 +0000
patch 9.0.1031: Vim9 class is not implemented yet
Problem: Vim9 class is not implemented yet.
Solution: Add very basic class support.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Dec 2022 16:45:03 +0100 |
parents | ab4b3710f437 |
children | 7d22228e4979 |
line wrap: on
line diff
--- a/src/structs.h +++ b/src/structs.h @@ -1406,6 +1406,9 @@ typedef struct { typedef struct isn_S isn_T; // instruction typedef struct dfunc_S dfunc_T; // :def function +typedef struct type_S type_T; +typedef struct ufunc_S ufunc_T; + typedef struct jobvar_S job_T; typedef struct readq_S readq_T; typedef struct writeq_S writeq_T; @@ -1415,6 +1418,8 @@ typedef struct channel_S channel_T; typedef struct cctx_S cctx_T; typedef struct ectx_S ectx_T; typedef struct instr_S instr_T; +typedef struct class_S class_T; +typedef struct object_S object_T; typedef enum { @@ -1434,16 +1439,18 @@ typedef enum VAR_JOB, // "v_job" is used VAR_CHANNEL, // "v_channel" is used VAR_INSTR, // "v_instr" is used + VAR_CLASS, // "v_class" is used + VAR_OBJECT, // "v_object" is used } vartype_T; // A type specification. -typedef struct type_S type_T; struct type_S { vartype_T tt_type; int8_T tt_argcount; // for func, incl. vararg, -1 for unknown int8_T tt_min_argcount; // number of non-optional arguments char_u tt_flags; // TTFLAG_ values type_T *tt_member; // for list, dict, func return type + // for class: class_T type_T **tt_args; // func argument types, allocated }; @@ -1452,6 +1459,38 @@ typedef struct { type_T *type_decl; // declared type or equal to type_current } type2_T; +/* + * Entry for an object member variable. + */ +typedef struct { + char_u *om_name; // allocated + type_T *om_type; +} objmember_T; + +// "class_T": used for v_class of typval of VAR_CLASS +struct class_S +{ + char_u *class_name; // allocated + int class_refcount; + + int class_obj_member_count; + objmember_T *class_obj_members; // allocated + + int class_obj_method_count; + ufunc_T **class_obj_methods; // allocated + ufunc_T *class_new_func; // new() function that was created + + garray_T class_type_list; // used for type pointers + type_T class_type; +}; + +// Used for v_object of typval of VAR_OBJECT. +// The member variables follow in an array of typval_T. +struct object_S { + class_T *obj_class; // class this object is created for + int obj_refcount; +}; + #define TTFLAG_VARARGS 0x01 // func args ends with "..." #define TTFLAG_BOOL_OK 0x02 // can be converted to bool #define TTFLAG_STATIC 0x04 // one of the static types, e.g. t_any @@ -1467,17 +1506,19 @@ typedef struct union { varnumber_T v_number; // number value - float_T v_float; // floating number value - char_u *v_string; // string value (can be NULL!) - list_T *v_list; // list value (can be NULL!) - dict_T *v_dict; // dict value (can be NULL!) + float_T v_float; // floating point number value + char_u *v_string; // string value (can be NULL) + list_T *v_list; // list value (can be NULL) + dict_T *v_dict; // dict value (can be NULL) partial_T *v_partial; // closure: function with args #ifdef FEAT_JOB_CHANNEL - job_T *v_job; // job value (can be NULL!) - channel_T *v_channel; // channel value (can be NULL!) + job_T *v_job; // job value (can be NULL) + channel_T *v_channel; // channel value (can be NULL) #endif - blob_T *v_blob; // blob value (can be NULL!) + blob_T *v_blob; // blob value (can be NULL) instr_T *v_instr; // instructions to execute + class_T *v_class; // class value (can be NULL) + object_T *v_object; // object value (can be NULL) } vval; } typval_T; @@ -1663,7 +1704,7 @@ typedef enum { * Structure to hold info for a user function. * When adding a field check copy_lambda_to_global_func(). */ -typedef struct +struct ufunc_S { int uf_varargs; // variable nr of arguments (old style) int uf_flags; // FC_ flags @@ -1671,6 +1712,9 @@ typedef struct int uf_cleared; // func_clear() was already called def_status_T uf_def_status; // UF_NOT_COMPILED, UF_TO_BE_COMPILED, etc. int uf_dfunc_idx; // only valid if uf_def_status is UF_COMPILED + + class_T *uf_class; // for object method and constructor + garray_T uf_args; // arguments, including optional arguments garray_T uf_def_args; // default argument expressions int uf_args_visible; // normally uf_args.ga_len, less when @@ -1731,7 +1775,7 @@ typedef struct char_u uf_name[4]; // name of function (actual size equals name); // can start with <SNR>123_ (<SNR> is K_SPECIAL // KS_EXTRA KE_SNR) -} ufunc_T; +}; // flags used in uf_flags #define FC_ABORT 0x01 // abort function on error @@ -1750,6 +1794,9 @@ typedef struct // copy_lambda_to_global_func() #define FC_LAMBDA 0x2000 // one line "return {expr}" +#define FC_OBJECT 010000 // object method +#define FC_NEW 030000 // constructor (also an object method) + #define MAX_FUNC_ARGS 20 // maximum number of function arguments #define VAR_SHORT_LEN 20 // short variable name length #define FIXVAR_CNT 12 // number of fixed variables