comparison 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
comparison
equal deleted inserted replaced
31395:88027ff41075 31396:307f68a41b03
1404 } callback_T; 1404 } callback_T;
1405 1405
1406 typedef struct isn_S isn_T; // instruction 1406 typedef struct isn_S isn_T; // instruction
1407 typedef struct dfunc_S dfunc_T; // :def function 1407 typedef struct dfunc_S dfunc_T; // :def function
1408 1408
1409 typedef struct type_S type_T;
1410 typedef struct ufunc_S ufunc_T;
1411
1409 typedef struct jobvar_S job_T; 1412 typedef struct jobvar_S job_T;
1410 typedef struct readq_S readq_T; 1413 typedef struct readq_S readq_T;
1411 typedef struct writeq_S writeq_T; 1414 typedef struct writeq_S writeq_T;
1412 typedef struct jsonq_S jsonq_T; 1415 typedef struct jsonq_S jsonq_T;
1413 typedef struct cbq_S cbq_T; 1416 typedef struct cbq_S cbq_T;
1414 typedef struct channel_S channel_T; 1417 typedef struct channel_S channel_T;
1415 typedef struct cctx_S cctx_T; 1418 typedef struct cctx_S cctx_T;
1416 typedef struct ectx_S ectx_T; 1419 typedef struct ectx_S ectx_T;
1417 typedef struct instr_S instr_T; 1420 typedef struct instr_S instr_T;
1421 typedef struct class_S class_T;
1422 typedef struct object_S object_T;
1418 1423
1419 typedef enum 1424 typedef enum
1420 { 1425 {
1421 VAR_UNKNOWN = 0, // not set, any type or "void" allowed 1426 VAR_UNKNOWN = 0, // not set, any type or "void" allowed
1422 VAR_ANY, // used for "any" type 1427 VAR_ANY, // used for "any" type
1432 VAR_LIST, // "v_list" is used 1437 VAR_LIST, // "v_list" is used
1433 VAR_DICT, // "v_dict" is used 1438 VAR_DICT, // "v_dict" is used
1434 VAR_JOB, // "v_job" is used 1439 VAR_JOB, // "v_job" is used
1435 VAR_CHANNEL, // "v_channel" is used 1440 VAR_CHANNEL, // "v_channel" is used
1436 VAR_INSTR, // "v_instr" is used 1441 VAR_INSTR, // "v_instr" is used
1442 VAR_CLASS, // "v_class" is used
1443 VAR_OBJECT, // "v_object" is used
1437 } vartype_T; 1444 } vartype_T;
1438 1445
1439 // A type specification. 1446 // A type specification.
1440 typedef struct type_S type_T;
1441 struct type_S { 1447 struct type_S {
1442 vartype_T tt_type; 1448 vartype_T tt_type;
1443 int8_T tt_argcount; // for func, incl. vararg, -1 for unknown 1449 int8_T tt_argcount; // for func, incl. vararg, -1 for unknown
1444 int8_T tt_min_argcount; // number of non-optional arguments 1450 int8_T tt_min_argcount; // number of non-optional arguments
1445 char_u tt_flags; // TTFLAG_ values 1451 char_u tt_flags; // TTFLAG_ values
1446 type_T *tt_member; // for list, dict, func return type 1452 type_T *tt_member; // for list, dict, func return type
1453 // for class: class_T
1447 type_T **tt_args; // func argument types, allocated 1454 type_T **tt_args; // func argument types, allocated
1448 }; 1455 };
1449 1456
1450 typedef struct { 1457 typedef struct {
1451 type_T *type_curr; // current type, value type 1458 type_T *type_curr; // current type, value type
1452 type_T *type_decl; // declared type or equal to type_current 1459 type_T *type_decl; // declared type or equal to type_current
1453 } type2_T; 1460 } type2_T;
1461
1462 /*
1463 * Entry for an object member variable.
1464 */
1465 typedef struct {
1466 char_u *om_name; // allocated
1467 type_T *om_type;
1468 } objmember_T;
1469
1470 // "class_T": used for v_class of typval of VAR_CLASS
1471 struct class_S
1472 {
1473 char_u *class_name; // allocated
1474 int class_refcount;
1475
1476 int class_obj_member_count;
1477 objmember_T *class_obj_members; // allocated
1478
1479 int class_obj_method_count;
1480 ufunc_T **class_obj_methods; // allocated
1481 ufunc_T *class_new_func; // new() function that was created
1482
1483 garray_T class_type_list; // used for type pointers
1484 type_T class_type;
1485 };
1486
1487 // Used for v_object of typval of VAR_OBJECT.
1488 // The member variables follow in an array of typval_T.
1489 struct object_S {
1490 class_T *obj_class; // class this object is created for
1491 int obj_refcount;
1492 };
1454 1493
1455 #define TTFLAG_VARARGS 0x01 // func args ends with "..." 1494 #define TTFLAG_VARARGS 0x01 // func args ends with "..."
1456 #define TTFLAG_BOOL_OK 0x02 // can be converted to bool 1495 #define TTFLAG_BOOL_OK 0x02 // can be converted to bool
1457 #define TTFLAG_STATIC 0x04 // one of the static types, e.g. t_any 1496 #define TTFLAG_STATIC 0x04 // one of the static types, e.g. t_any
1458 #define TTFLAG_CONST 0x08 // cannot be changed 1497 #define TTFLAG_CONST 0x08 // cannot be changed
1465 vartype_T v_type; 1504 vartype_T v_type;
1466 char v_lock; // see below: VAR_LOCKED, VAR_FIXED 1505 char v_lock; // see below: VAR_LOCKED, VAR_FIXED
1467 union 1506 union
1468 { 1507 {
1469 varnumber_T v_number; // number value 1508 varnumber_T v_number; // number value
1470 float_T v_float; // floating number value 1509 float_T v_float; // floating point number value
1471 char_u *v_string; // string value (can be NULL!) 1510 char_u *v_string; // string value (can be NULL)
1472 list_T *v_list; // list value (can be NULL!) 1511 list_T *v_list; // list value (can be NULL)
1473 dict_T *v_dict; // dict value (can be NULL!) 1512 dict_T *v_dict; // dict value (can be NULL)
1474 partial_T *v_partial; // closure: function with args 1513 partial_T *v_partial; // closure: function with args
1475 #ifdef FEAT_JOB_CHANNEL 1514 #ifdef FEAT_JOB_CHANNEL
1476 job_T *v_job; // job value (can be NULL!) 1515 job_T *v_job; // job value (can be NULL)
1477 channel_T *v_channel; // channel value (can be NULL!) 1516 channel_T *v_channel; // channel value (can be NULL)
1478 #endif 1517 #endif
1479 blob_T *v_blob; // blob value (can be NULL!) 1518 blob_T *v_blob; // blob value (can be NULL)
1480 instr_T *v_instr; // instructions to execute 1519 instr_T *v_instr; // instructions to execute
1520 class_T *v_class; // class value (can be NULL)
1521 object_T *v_object; // object value (can be NULL)
1481 } vval; 1522 } vval;
1482 } typval_T; 1523 } typval_T;
1483 1524
1484 // Values for "dv_scope". 1525 // Values for "dv_scope".
1485 #define VAR_SCOPE 1 // a:, v:, s:, etc. scope dictionaries 1526 #define VAR_SCOPE 1 // a:, v:, s:, etc. scope dictionaries
1661 1702
1662 /* 1703 /*
1663 * Structure to hold info for a user function. 1704 * Structure to hold info for a user function.
1664 * When adding a field check copy_lambda_to_global_func(). 1705 * When adding a field check copy_lambda_to_global_func().
1665 */ 1706 */
1666 typedef struct 1707 struct ufunc_S
1667 { 1708 {
1668 int uf_varargs; // variable nr of arguments (old style) 1709 int uf_varargs; // variable nr of arguments (old style)
1669 int uf_flags; // FC_ flags 1710 int uf_flags; // FC_ flags
1670 int uf_calls; // nr of active calls 1711 int uf_calls; // nr of active calls
1671 int uf_cleared; // func_clear() was already called 1712 int uf_cleared; // func_clear() was already called
1672 def_status_T uf_def_status; // UF_NOT_COMPILED, UF_TO_BE_COMPILED, etc. 1713 def_status_T uf_def_status; // UF_NOT_COMPILED, UF_TO_BE_COMPILED, etc.
1673 int uf_dfunc_idx; // only valid if uf_def_status is UF_COMPILED 1714 int uf_dfunc_idx; // only valid if uf_def_status is UF_COMPILED
1715
1716 class_T *uf_class; // for object method and constructor
1717
1674 garray_T uf_args; // arguments, including optional arguments 1718 garray_T uf_args; // arguments, including optional arguments
1675 garray_T uf_def_args; // default argument expressions 1719 garray_T uf_def_args; // default argument expressions
1676 int uf_args_visible; // normally uf_args.ga_len, less when 1720 int uf_args_visible; // normally uf_args.ga_len, less when
1677 // compiling default argument expression. 1721 // compiling default argument expression.
1678 1722
1729 char_u *uf_name_exp; // if "uf_name[]" starts with SNR the name with 1773 char_u *uf_name_exp; // if "uf_name[]" starts with SNR the name with
1730 // "<SNR>" as a string, otherwise NULL 1774 // "<SNR>" as a string, otherwise NULL
1731 char_u uf_name[4]; // name of function (actual size equals name); 1775 char_u uf_name[4]; // name of function (actual size equals name);
1732 // can start with <SNR>123_ (<SNR> is K_SPECIAL 1776 // can start with <SNR>123_ (<SNR> is K_SPECIAL
1733 // KS_EXTRA KE_SNR) 1777 // KS_EXTRA KE_SNR)
1734 } ufunc_T; 1778 };
1735 1779
1736 // flags used in uf_flags 1780 // flags used in uf_flags
1737 #define FC_ABORT 0x01 // abort function on error 1781 #define FC_ABORT 0x01 // abort function on error
1738 #define FC_RANGE 0x02 // function accepts range 1782 #define FC_RANGE 0x02 // function accepts range
1739 #define FC_DICT 0x04 // Dict function, uses "self" 1783 #define FC_DICT 0x04 // Dict function, uses "self"
1747 #define FC_VIM9 0x400 // defined in vim9 script file 1791 #define FC_VIM9 0x400 // defined in vim9 script file
1748 #define FC_CFUNC 0x800 // defined as Lua C func 1792 #define FC_CFUNC 0x800 // defined as Lua C func
1749 #define FC_COPY 0x1000 // copy of another function by 1793 #define FC_COPY 0x1000 // copy of another function by
1750 // copy_lambda_to_global_func() 1794 // copy_lambda_to_global_func()
1751 #define FC_LAMBDA 0x2000 // one line "return {expr}" 1795 #define FC_LAMBDA 0x2000 // one line "return {expr}"
1796
1797 #define FC_OBJECT 010000 // object method
1798 #define FC_NEW 030000 // constructor (also an object method)
1752 1799
1753 #define MAX_FUNC_ARGS 20 // maximum number of function arguments 1800 #define MAX_FUNC_ARGS 20 // maximum number of function arguments
1754 #define VAR_SHORT_LEN 20 // short variable name length 1801 #define VAR_SHORT_LEN 20 // short variable name length
1755 #define FIXVAR_CNT 12 // number of fixed variables 1802 #define FIXVAR_CNT 12 // number of fixed variables
1756 1803