2020-01-26 15:56:19 +01:00
|
|
|
/* vi:set ts=8 sts=4 sw=4 noet:
|
|
|
|
*
|
|
|
|
* VIM - Vi IMproved by Bram Moolenaar
|
|
|
|
*
|
|
|
|
* Do ":help uganda" in Vim to read copying and usage conditions.
|
|
|
|
* Do ":help credits" in Vim to see a list of people who contributed.
|
|
|
|
* See README.txt for an overview of the Vim source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vim9.h: types and globals used for Vim9 script.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ISN_EXEC, // execute Ex command line isn_arg.string
|
2020-04-25 20:02:55 +02:00
|
|
|
ISN_EXECCONCAT, // execute Ex command from isn_arg.number items on stack
|
2020-02-26 18:23:43 +01:00
|
|
|
ISN_ECHO, // echo isn_arg.echo.echo_count items on top of stack
|
|
|
|
ISN_EXECUTE, // execute Ex commands isn_arg.number items on top of stack
|
2020-04-23 22:16:53 +02:00
|
|
|
ISN_ECHOMSG, // echo Ex commands isn_arg.number items on top of stack
|
|
|
|
ISN_ECHOERR, // echo Ex commands isn_arg.number items on top of stack
|
2020-01-26 15:56:19 +01:00
|
|
|
|
|
|
|
// get and set variables
|
|
|
|
ISN_LOAD, // push local variable isn_arg.number
|
|
|
|
ISN_LOADV, // push v: variable isn_arg.number
|
|
|
|
ISN_LOADG, // push g: variable isn_arg.string
|
2020-04-19 14:32:17 +02:00
|
|
|
ISN_LOADB, // push b: variable isn_arg.string
|
|
|
|
ISN_LOADW, // push w: variable isn_arg.string
|
|
|
|
ISN_LOADT, // push t: variable isn_arg.string
|
2020-02-02 22:24:04 +01:00
|
|
|
ISN_LOADS, // push s: variable isn_arg.loadstore
|
2020-05-01 19:29:08 +02:00
|
|
|
ISN_LOADOUTER, // push variable from outer scope isn_arg.number
|
2020-02-02 22:24:04 +01:00
|
|
|
ISN_LOADSCRIPT, // push script-local variable isn_arg.script.
|
2020-01-26 15:56:19 +01:00
|
|
|
ISN_LOADOPT, // push option isn_arg.string
|
|
|
|
ISN_LOADENV, // push environment variable isn_arg.string
|
|
|
|
ISN_LOADREG, // push register isn_arg.number
|
|
|
|
|
|
|
|
ISN_STORE, // pop into local variable isn_arg.number
|
2020-02-02 22:24:04 +01:00
|
|
|
ISN_STOREV, // pop into v: variable isn_arg.number
|
2020-01-26 15:56:19 +01:00
|
|
|
ISN_STOREG, // pop into global variable isn_arg.string
|
2020-04-19 14:32:17 +02:00
|
|
|
ISN_STOREB, // pop into buffer-local variable isn_arg.string
|
|
|
|
ISN_STOREW, // pop into window-local variable isn_arg.string
|
|
|
|
ISN_STORET, // pop into tab-local variable isn_arg.string
|
2020-04-05 17:08:17 +02:00
|
|
|
ISN_STORES, // pop into script variable isn_arg.loadstore
|
2020-05-06 21:06:30 +02:00
|
|
|
ISN_STOREOUTER, // pop variable into outer scope isn_arg.number
|
2020-04-05 17:08:17 +02:00
|
|
|
ISN_STORESCRIPT, // pop into script variable isn_arg.script
|
2020-05-06 21:06:30 +02:00
|
|
|
ISN_STOREOPT, // pop into option isn_arg.string
|
2020-02-02 22:24:04 +01:00
|
|
|
ISN_STOREENV, // pop into environment variable isn_arg.string
|
|
|
|
ISN_STOREREG, // pop into register isn_arg.number
|
2020-01-26 15:56:19 +01:00
|
|
|
// ISN_STOREOTHER, // pop into other script variable isn_arg.other.
|
|
|
|
|
2020-03-04 22:20:26 +01:00
|
|
|
ISN_STORENR, // store number into local variable isn_arg.storenr.stnr_idx
|
2020-05-10 19:10:31 +02:00
|
|
|
ISN_STORELIST, // store into list, value/index/varable on stack
|
|
|
|
ISN_STOREDICT, // store into dictionary, value/index/variable on stack
|
2020-01-26 15:56:19 +01:00
|
|
|
|
2020-04-19 16:28:59 +02:00
|
|
|
ISN_UNLET, // unlet variable isn_arg.unlet.ul_name
|
2020-04-19 18:27:26 +02:00
|
|
|
ISN_UNLETENV, // unlet environment variable isn_arg.unlet.ul_name
|
2020-04-19 16:28:59 +02:00
|
|
|
|
2020-01-26 15:56:19 +01:00
|
|
|
// constants
|
2020-02-29 23:23:47 +01:00
|
|
|
ISN_PUSHNR, // push number isn_arg.number
|
|
|
|
ISN_PUSHBOOL, // push bool value isn_arg.number
|
|
|
|
ISN_PUSHSPEC, // push special value isn_arg.number
|
|
|
|
ISN_PUSHF, // push float isn_arg.fnumber
|
|
|
|
ISN_PUSHS, // push string isn_arg.string
|
|
|
|
ISN_PUSHBLOB, // push blob isn_arg.blob
|
|
|
|
ISN_PUSHFUNC, // push func isn_arg.string
|
|
|
|
ISN_PUSHCHANNEL, // push channel isn_arg.channel
|
|
|
|
ISN_PUSHJOB, // push channel isn_arg.job
|
|
|
|
ISN_NEWLIST, // push list from stack items, size is isn_arg.number
|
|
|
|
ISN_NEWDICT, // push dict from stack items, size is isn_arg.number
|
2020-01-26 15:56:19 +01:00
|
|
|
|
|
|
|
// function call
|
|
|
|
ISN_BCALL, // call builtin function isn_arg.bfunc
|
|
|
|
ISN_DCALL, // call def function isn_arg.dfunc
|
|
|
|
ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc
|
|
|
|
ISN_PCALL, // call partial, use isn_arg.pfunc
|
2020-03-31 23:13:10 +02:00
|
|
|
ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set
|
2020-01-26 15:56:19 +01:00
|
|
|
ISN_RETURN, // return, result is on top of stack
|
2020-05-02 17:52:42 +02:00
|
|
|
ISN_FUNCREF, // push a function ref to dfunc isn_arg.funcref
|
2020-01-26 15:56:19 +01:00
|
|
|
|
|
|
|
// expression operations
|
|
|
|
ISN_JUMP, // jump if condition is matched isn_arg.jump
|
|
|
|
|
|
|
|
// loop
|
|
|
|
ISN_FOR, // get next item from a list, uses isn_arg.forloop
|
|
|
|
|
|
|
|
ISN_TRY, // add entry to ec_trystack, uses isn_arg.try
|
|
|
|
ISN_THROW, // pop value of stack, store in v:exception
|
|
|
|
ISN_PUSHEXC, // push v:exception
|
|
|
|
ISN_CATCH, // drop v:exception
|
|
|
|
ISN_ENDTRY, // take entry off from ec_trystack
|
|
|
|
|
|
|
|
// moreexpression operations
|
|
|
|
ISN_ADDLIST,
|
|
|
|
ISN_ADDBLOB,
|
|
|
|
|
|
|
|
// operation with two arguments; isn_arg.op.op_type is exptype_T
|
|
|
|
ISN_OPNR,
|
|
|
|
ISN_OPFLOAT,
|
|
|
|
ISN_OPANY,
|
|
|
|
|
|
|
|
// comparative operations; isn_arg.op.op_type is exptype_T, op_ic used
|
|
|
|
ISN_COMPAREBOOL,
|
|
|
|
ISN_COMPARESPECIAL,
|
|
|
|
ISN_COMPARENR,
|
|
|
|
ISN_COMPAREFLOAT,
|
|
|
|
ISN_COMPARESTRING,
|
|
|
|
ISN_COMPAREBLOB,
|
|
|
|
ISN_COMPARELIST,
|
|
|
|
ISN_COMPAREDICT,
|
|
|
|
ISN_COMPAREFUNC,
|
|
|
|
ISN_COMPAREANY,
|
|
|
|
|
|
|
|
// expression operations
|
|
|
|
ISN_CONCAT,
|
|
|
|
ISN_INDEX, // [expr] list index
|
2020-06-14 23:05:10 +02:00
|
|
|
ISN_GETITEM, // push list item, isn_arg.number is the index
|
2020-05-10 19:10:31 +02:00
|
|
|
ISN_MEMBER, // dict[member]
|
|
|
|
ISN_STRINGMEMBER, // dict.member using isn_arg.string
|
2020-01-26 15:56:19 +01:00
|
|
|
ISN_2BOOL, // convert value to bool, invert if isn_arg.number != 0
|
|
|
|
ISN_2STRING, // convert value to string at isn_arg.number on stack
|
|
|
|
ISN_NEGATENR, // apply "-" to number
|
|
|
|
|
|
|
|
ISN_CHECKNR, // check value can be used as a number
|
|
|
|
ISN_CHECKTYPE, // check value type is isn_arg.type.tc_type
|
|
|
|
|
|
|
|
ISN_DROP // pop stack and discard value
|
|
|
|
} isntype_T;
|
|
|
|
|
|
|
|
|
|
|
|
// arguments to ISN_BCALL
|
|
|
|
typedef struct {
|
|
|
|
int cbf_idx; // index in "global_functions"
|
|
|
|
int cbf_argcount; // number of arguments on top of stack
|
|
|
|
} cbfunc_T;
|
|
|
|
|
|
|
|
// arguments to ISN_DCALL
|
|
|
|
typedef struct {
|
|
|
|
int cdf_idx; // index in "def_functions" for ISN_DCALL
|
|
|
|
int cdf_argcount; // number of arguments on top of stack
|
|
|
|
} cdfunc_T;
|
|
|
|
|
|
|
|
// arguments to ISN_PCALL
|
|
|
|
typedef struct {
|
|
|
|
int cpf_top; // when TRUE partial is above the arguments
|
|
|
|
int cpf_argcount; // number of arguments on top of stack
|
|
|
|
} cpfunc_T;
|
|
|
|
|
|
|
|
// arguments to ISN_UCALL and ISN_XCALL
|
|
|
|
typedef struct {
|
|
|
|
char_u *cuf_name;
|
|
|
|
int cuf_argcount; // number of arguments on top of stack
|
|
|
|
} cufunc_T;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
JUMP_ALWAYS,
|
|
|
|
JUMP_IF_FALSE, // pop and jump if false
|
|
|
|
JUMP_AND_KEEP_IF_TRUE, // jump if top of stack is true, drop if not
|
|
|
|
JUMP_AND_KEEP_IF_FALSE, // jump if top of stack is false, drop if not
|
|
|
|
} jumpwhen_T;
|
|
|
|
|
|
|
|
// arguments to ISN_JUMP
|
|
|
|
typedef struct {
|
|
|
|
jumpwhen_T jump_when;
|
|
|
|
int jump_where; // position to jump to
|
|
|
|
} jump_T;
|
|
|
|
|
|
|
|
// arguments to ISN_FOR
|
|
|
|
typedef struct {
|
|
|
|
int for_idx; // loop variable index
|
|
|
|
int for_end; // position to jump to after done
|
|
|
|
} forloop_T;
|
|
|
|
|
|
|
|
// arguments to ISN_TRY
|
|
|
|
typedef struct {
|
|
|
|
int try_catch; // position to jump to on throw
|
|
|
|
int try_finally; // position to jump to for return
|
|
|
|
} try_T;
|
|
|
|
|
|
|
|
// arguments to ISN_ECHO
|
|
|
|
typedef struct {
|
|
|
|
int echo_with_white; // :echo instead of :echon
|
|
|
|
int echo_count; // number of expressions
|
|
|
|
} echo_T;
|
|
|
|
|
|
|
|
// arguments to ISN_OPNR, ISN_OPFLOAT, etc.
|
|
|
|
typedef struct {
|
|
|
|
exptype_T op_type;
|
|
|
|
int op_ic; // TRUE with '#', FALSE with '?', else MAYBE
|
|
|
|
} opexpr_T;
|
|
|
|
|
|
|
|
// arguments to ISN_CHECKTYPE
|
|
|
|
typedef struct {
|
|
|
|
vartype_T ct_type;
|
|
|
|
int ct_off; // offset in stack, -1 is bottom
|
|
|
|
} checktype_T;
|
|
|
|
|
|
|
|
// arguments to ISN_STORENR
|
|
|
|
typedef struct {
|
2020-03-04 22:20:26 +01:00
|
|
|
int stnr_idx;
|
|
|
|
varnumber_T stnr_val;
|
2020-01-26 15:56:19 +01:00
|
|
|
} storenr_T;
|
|
|
|
|
|
|
|
// arguments to ISN_STOREOPT
|
|
|
|
typedef struct {
|
|
|
|
char_u *so_name;
|
|
|
|
int so_flags;
|
|
|
|
} storeopt_T;
|
|
|
|
|
2020-02-02 22:24:04 +01:00
|
|
|
// arguments to ISN_LOADS and ISN_STORES
|
2020-01-26 15:56:19 +01:00
|
|
|
typedef struct {
|
2020-04-05 17:08:17 +02:00
|
|
|
char_u *ls_name; // variable name (with s: for ISN_STORES)
|
2020-01-26 15:56:19 +01:00
|
|
|
int ls_sid; // script ID
|
2020-02-02 22:24:04 +01:00
|
|
|
} loadstore_T;
|
2020-01-26 15:56:19 +01:00
|
|
|
|
2020-02-02 22:24:04 +01:00
|
|
|
// arguments to ISN_LOADSCRIPT and ISN_STORESCRIPT
|
2020-01-26 15:56:19 +01:00
|
|
|
typedef struct {
|
|
|
|
int script_sid; // script ID
|
|
|
|
int script_idx; // index in sn_var_vals
|
|
|
|
} script_T;
|
|
|
|
|
2020-04-19 16:28:59 +02:00
|
|
|
// arguments to ISN_UNLET
|
|
|
|
typedef struct {
|
|
|
|
char_u *ul_name; // variable name with g:, w:, etc.
|
|
|
|
int ul_forceit; // forceit flag
|
|
|
|
} unlet_T;
|
|
|
|
|
2020-05-02 17:52:42 +02:00
|
|
|
// arguments to ISN_FUNCREF
|
|
|
|
typedef struct {
|
|
|
|
int fr_func; // function index
|
|
|
|
int fr_var_idx; // variable to store partial
|
|
|
|
} funcref_T;
|
|
|
|
|
2020-01-26 15:56:19 +01:00
|
|
|
/*
|
|
|
|
* Instruction
|
|
|
|
*/
|
2020-03-20 18:39:46 +01:00
|
|
|
struct isn_S {
|
2020-01-26 15:56:19 +01:00
|
|
|
isntype_T isn_type;
|
|
|
|
int isn_lnum;
|
|
|
|
union {
|
|
|
|
char_u *string;
|
|
|
|
varnumber_T number;
|
|
|
|
blob_T *blob;
|
|
|
|
#ifdef FEAT_FLOAT
|
|
|
|
float_T fnumber;
|
|
|
|
#endif
|
2020-02-29 23:23:47 +01:00
|
|
|
channel_T *channel;
|
|
|
|
job_T *job;
|
2020-03-01 15:36:42 +01:00
|
|
|
partial_T *partial;
|
2020-01-26 15:56:19 +01:00
|
|
|
jump_T jump;
|
|
|
|
forloop_T forloop;
|
|
|
|
try_T try;
|
|
|
|
cbfunc_T bfunc;
|
|
|
|
cdfunc_T dfunc;
|
|
|
|
cpfunc_T pfunc;
|
|
|
|
cufunc_T ufunc;
|
|
|
|
echo_T echo;
|
|
|
|
opexpr_T op;
|
|
|
|
checktype_T type;
|
|
|
|
storenr_T storenr;
|
|
|
|
storeopt_T storeopt;
|
2020-02-02 22:24:04 +01:00
|
|
|
loadstore_T loadstore;
|
2020-01-26 15:56:19 +01:00
|
|
|
script_T script;
|
2020-04-19 16:28:59 +02:00
|
|
|
unlet_T unlet;
|
2020-05-02 17:52:42 +02:00
|
|
|
funcref_T funcref;
|
2020-01-26 15:56:19 +01:00
|
|
|
} isn_arg;
|
2020-03-20 18:39:46 +01:00
|
|
|
};
|
2020-01-26 15:56:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Info about a function defined with :def. Used in "def_functions".
|
|
|
|
*/
|
|
|
|
struct dfunc_S {
|
|
|
|
ufunc_T *df_ufunc; // struct containing most stuff
|
|
|
|
int df_idx; // index in def_functions
|
|
|
|
int df_deleted; // if TRUE function was deleted
|
|
|
|
|
|
|
|
garray_T df_def_args_isn; // default argument instructions
|
|
|
|
isn_T *df_instr; // function body to be executed
|
|
|
|
int df_instr_count;
|
|
|
|
|
|
|
|
int df_varcount; // number of local variables
|
2020-05-02 17:52:42 +02:00
|
|
|
int df_closure_count; // number of closures created
|
2020-01-26 15:56:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Number of entries used by stack frame for a function call.
|
2020-05-02 17:52:42 +02:00
|
|
|
// - function index
|
|
|
|
// - instruction index
|
|
|
|
// - previous frame index
|
2020-01-26 15:56:19 +01:00
|
|
|
#define STACK_FRAME_SIZE 3
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEFINE_VIM9_GLOBALS
|
|
|
|
// Functions defined with :def are stored in this growarray.
|
|
|
|
// They are never removed, so that they can be found by index.
|
|
|
|
// Deleted functions have the df_deleted flag set.
|
2020-03-31 23:32:31 +02:00
|
|
|
garray_T def_functions = {0, 0, sizeof(dfunc_T), 50, NULL};
|
2020-01-26 15:56:19 +01:00
|
|
|
#else
|
|
|
|
extern garray_T def_functions;
|
|
|
|
#endif
|
|
|
|
|