robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40688 from justinmk/fixci757800bc64

master
24.3 KiB662 linesraw
1#include <assert.h>
2#include <stdbool.h>
3#include <stddef.h>
4#include <stdint.h>
5#include <stdlib.h>
6#include <string.h>
7
8#include "klib/kvec.h"
9#include "nvim/api/keysets_defs.h"
10#include "nvim/api/private/converter.h"
11#include "nvim/api/private/defs.h"
12#include "nvim/api/private/helpers.h"
13#include "nvim/api/private/validate.h"
14#include "nvim/api/vimscript.h"
15#include "nvim/ascii_defs.h"
16#include "nvim/buffer_defs.h"
17#include "nvim/eval.h"
18#include "nvim/eval/typval.h"
19#include "nvim/eval/typval_defs.h"
20#include "nvim/eval/userfunc.h"
21#include "nvim/ex_docmd.h"
22#include "nvim/garray.h"
23#include "nvim/garray_defs.h"
24#include "nvim/globals.h"
25#include "nvim/memory.h"
26#include "nvim/memory_defs.h"
27#include "nvim/runtime.h"
28#include "nvim/vim_defs.h"
29#include "nvim/viml/parser/expressions.h"
30#include "nvim/viml/parser/parser.h"
31#include "nvim/viml/parser/parser_defs.h"
32
33#include "api/vimscript.c.generated.h"
34
35/// Executes Vimscript (multiline block of Ex commands), like anonymous
36/// |:source|.
37///
38/// Unlike |nvim_command()| this function supports heredocs, script-scope (s:),
39/// etc.
40///
41/// On execution error: fails with Vimscript error, updates v:errmsg.
42///
43/// @see |execute()|
44/// @see |nvim_command()|
45/// @see |nvim_cmd()|
46///
47/// @param src      Vimscript code
48/// @param opts  Optional parameters.
49///           - output: (boolean, default false) Whether to capture and return
50///                     all (non-error, non-shell |:!|) output.
51/// @param[out] err Error details (Vim error), if any
52/// @return Dict containing information about execution, with these keys:
53///       - output: (string|nil) Output if `opts.output` is true.
54Dict nvim_exec2(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *err)
55  FUNC_API_SINCE(11) FUNC_API_RET_ALLOC
56{
57  Dict result = ARRAY_DICT_INIT;
58
59  String output = exec_impl(channel_id, src, opts, err);
60  if (ERROR_SET(err)) {
61    return result;
62  }
63
64  if (opts->output) {
65    PUT(result, "output", STRING_OBJ(output));
66  }
67
68  return result;
69}
70
71String exec_impl(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *err)
72{
73  const int save_msg_silent = msg_silent;
74  const bool save_redir_off = redir_off;
75  garray_T *const save_capture_ga = capture_ga;
76  const int save_msg_col = msg_col;
77  garray_T capture_local;
78  if (opts->output) {
79    ga_init(&capture_local, 1, 80);
80    capture_ga = &capture_local;
81  }
82
83  TRY_WRAP(err, {
84    if (opts->output) {
85      msg_silent++;
86      redir_off = false;
87      msg_col = 0;  // prevent leading spaces
88    }
89
90    const sctx_T save_current_sctx = api_set_sctx(channel_id);
91
92    do_source_str(src.data, "nvim_exec2()");
93    if (opts->output) {
94      capture_ga = save_capture_ga;
95      msg_silent = save_msg_silent;
96      redir_off = save_redir_off;
97      // Put msg_col back where it was, since nothing should have been written.
98      msg_col = save_msg_col;
99    }
100
101    current_sctx = save_current_sctx;
102  });
103
104  if (ERROR_SET(err)) {
105    goto theend;
106  }
107
108  if (opts->output && capture_local.ga_len > 1) {
109    String s = (String){
110      .data = capture_local.ga_data,
111      .size = (size_t)capture_local.ga_len,
112    };
113    // redir usually (except :echon) prepends a newline.
114    if (s.data[0] == '\n') {
115      memmove(s.data, s.data + 1, s.size - 1);
116      s.data[s.size - 1] = NUL;
117      s.size = s.size - 1;
118    }
119    return s;  // Caller will free the memory.
120  }
121theend:
122  if (opts->output) {
123    ga_clear(&capture_local);
124  }
125  return (String)STRING_INIT;
126}
127
128/// Executes an Ex command.
129///
130/// On execution error: fails with Vimscript error, updates v:errmsg.
131///
132/// Prefer |nvim_cmd()| or |nvim_exec2()| instead. To modify an Ex command in a structured way
133/// before executing it, modify the result of |nvim_parse_cmd()| then pass it to |nvim_cmd()|.
134///
135/// @param cmd  Ex command string
136/// @param[out] err Error details (Vim error), if any
137void nvim_command(String cmd, Error *err)
138  FUNC_API_SINCE(1)
139{
140  TRY_WRAP(err, {
141    do_cmdline_cmd(cmd.data);
142  });
143}
144
145/// Evaluates a Vimscript |expression|. Dicts and Lists are recursively expanded.
146///
147/// On execution error: fails with Vimscript error, updates v:errmsg.
148///
149/// @param expr     Vimscript expression string
150/// @param[out] err Error details, if any
151/// @return         Evaluation result or expanded object
152Object nvim_eval(String expr, Arena *arena, Error *err)
153  FUNC_API_SINCE(1)
154{
155  static int recursive = 0;  // recursion depth
156  Object rv = OBJECT_INIT;
157
158  // Initialize `force_abort`  and `suppress_errthrow` at the top level.
159  if (!recursive) {
160    force_abort = false;
161    suppress_errthrow = false;
162    did_throw = false;
163    // `did_emsg` is set by emsg(), which cancels execution.
164    did_emsg = false;
165  }
166
167  recursive++;
168
169  typval_T rettv;
170  int ok;
171
172  TRY_WRAP(err, {
173    ok = eval0(expr.data, &rettv, NULL, &EVALARG_EVALUATE);
174    clear_evalarg(&EVALARG_EVALUATE, NULL);
175  });
176
177  if (!ERROR_SET(err)) {
178    if (ok == FAIL) {
179      // Should never happen, try_end() (in TRY_WRAP) should get the error. #8371
180      api_set_error(err, kErrorTypeException,
181                    "Failed to evaluate expression: '%.*s'", 256, expr.data);
182    } else {
183      rv = vim_to_object(&rettv, arena, false);
184    }
185  }
186
187  tv_clear(&rettv);
188  recursive--;
189
190  return rv;
191}
192
193/// Calls a Vimscript function.
194///
195/// @param fn Function name
196/// @param args Function arguments
197/// @param self `self` dict, or NULL for non-dict functions
198/// @param[out] err Error details, if any
199/// @return Result of the function call
200static Object _call_function(uint64_t channel_id, String fn, Array args, dict_T *self, Arena *arena,
201                             Error *err)
202{
203  static int recursive = 0;  // recursion depth
204  Object rv = OBJECT_INIT;
205
206  if (args.size > MAX_FUNC_ARGS) {
207    api_set_error(err, kErrorTypeValidation,
208                  "Function called with too many arguments");
209    return rv;
210  }
211
212  // Convert the arguments in args from Object to typval_T values
213  typval_T vim_args[MAX_FUNC_ARGS + 1];
214  size_t i = 0;  // also used for freeing the variables
215  for (; i < args.size; i++) {
216    object_to_vim(args.items[i], &vim_args[i], err);
217  }
218
219  // Initialize `force_abort`  and `suppress_errthrow` at the top level.
220  if (!recursive) {
221    force_abort = false;
222    suppress_errthrow = false;
223    did_throw = false;
224    // `did_emsg` is set by emsg(), which cancels execution.
225    did_emsg = false;
226  }
227  recursive++;
228
229  typval_T rettv;
230  funcexe_T funcexe = FUNCEXE_INIT;
231  funcexe.fe_firstline = curwin->w_cursor.lnum;
232  funcexe.fe_lastline = curwin->w_cursor.lnum;
233  funcexe.fe_evaluate = true;
234  funcexe.fe_selfdict = self;
235
236  TRY_WRAP(err, {
237    const sctx_T save_current_sctx = api_set_sctx(channel_id);
238    // call_func() retval is deceptive, ignore it.  Instead TRY_WRAP sets `msg_list` to capture
239    // abort-causing non-exception errors.
240    (void)call_func(fn.data, (int)fn.size, &rettv, (int)args.size, vim_args, &funcexe);
241    current_sctx = save_current_sctx;
242  });
243
244  if (!ERROR_SET(err)) {
245    rv = vim_to_object(&rettv, arena, false);
246  }
247
248  tv_clear(&rettv);
249  recursive--;
250
251  while (i > 0) {
252    tv_clear(&vim_args[--i]);
253  }
254
255  return rv;
256}
257
258/// Calls a Vimscript function with the given arguments.
259///
260/// On execution error: fails with Vimscript error, updates v:errmsg.
261///
262/// @param fn       Function to call
263/// @param args     Function arguments packed in an Array
264/// @param[out] err Error details, if any
265/// @return Result of the function call
266Object nvim_call_function(uint64_t channel_id, String fn, Array args, Arena *arena, Error *err)
267  FUNC_API_SINCE(1)
268{
269  return _call_function(channel_id, fn, args, NULL, arena, err);
270}
271
272/// Calls a Vimscript |Dictionary-function| with the given arguments.
273///
274/// On execution error: fails with Vimscript error, updates v:errmsg.
275///
276/// @param dict Dict, or String evaluating to a Vimscript |self| dict
277/// @param fn Name of the function defined on the Vimscript dict
278/// @param args Function arguments packed in an Array
279/// @param[out] err Error details, if any
280/// @return Result of the function call
281Object nvim_call_dict_function(uint64_t channel_id, Object dict, String fn, Array args,
282                               Arena *arena, Error *err)
283  FUNC_API_SINCE(4)
284{
285  Object rv = OBJECT_INIT;
286
287  typval_T rettv;
288  bool mustfree = false;
289  switch (dict.type) {
290  case kObjectTypeString: {
291    int eval_ret;
292    TRY_WRAP(err, {
293        eval_ret = eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE);
294        clear_evalarg(&EVALARG_EVALUATE, NULL);
295      });
296    if (ERROR_SET(err)) {
297      return rv;
298    }
299    if (eval_ret != OK) {
300      abort();  // Should not happen.
301    }
302    // Evaluation of the string arg created a new dict or increased the
303    // refcount of a dict. Not necessary for a RPC dict.
304    mustfree = true;
305    break;
306  }
307  case kObjectTypeDict:
308    object_to_vim(dict, &rettv, err);
309    break;
310  default:
311    VALIDATE_EXP(false, "dict argument", "String or Dict", NULL, {
312      return rv;
313    });
314  }
315  dict_T *self_dict = rettv.vval.v_dict;
316  if (rettv.v_type != VAR_DICT || !self_dict) {
317    api_set_error(err, kErrorTypeValidation, "dict not found");
318    goto end;
319  }
320
321  if (fn.data && fn.size > 0 && dict.type != kObjectTypeDict) {
322    dictitem_T *const di = tv_dict_find(self_dict, fn.data, (ptrdiff_t)fn.size);
323    VALIDATE(di != NULL, "Not found: %s", fn.data, {
324      goto end;
325    });
326    if (di->di_tv.v_type == VAR_PARTIAL) {
327      api_set_error(err, kErrorTypeValidation,
328                    "partial function not supported");
329      goto end;
330    }
331    VALIDATE((di->di_tv.v_type == VAR_FUNC), "Not a function: %s", fn.data, {
332      goto end;
333    });
334    fn = (String) {
335      .data = di->di_tv.vval.v_string,
336      .size = strlen(di->di_tv.vval.v_string),
337    };
338  }
339
340  VALIDATE((fn.data && fn.size >= 1), "Invalid function name: %s", "(empty)", {
341    goto end;
342  });
343
344  rv = _call_function(channel_id, fn, args, self_dict, arena, err);
345end:
346  if (mustfree) {
347    tv_clear(&rettv);
348  }
349
350  return rv;
351}
352
353typedef struct {
354  ExprASTNode **node_p;
355  Object *ret_node_p;
356} ExprASTConvStackItem;
357
358typedef kvec_withinit_t(ExprASTConvStackItem, 16) ExprASTConvStack;
359
360/// Parse a Vimscript expression.
361///
362/// @param[in]  expr  Expression to parse. Always treated as a single line.
363/// @param[in]  flags Flags:
364///                    - "E" if EOC tokens are not allowed (determines whether
365///                      they will stop parsing process or be recognized as an
366///                      operator/space, though also yielding an error).
367///                    - "l" when needing to start parsing with lvalues for
368///                      ":let" or ":for".
369///                    - "m" if multiple expressions in a row are allowed (only
370///                      the first one will be parsed),
371///                    - Common flag sets:
372///                      - "E" to parse like for `"<C-r>="`.
373///                      - "lm" to parse for ":let".
374///                      - "m" to parse like for `":echo"`.
375///                      - empty string for ":call".
376/// @param[in]  hl  If true, return value will also include "highlight"
377///                        key containing array of 4-tuples (arrays) (Integer,
378///                        Integer, Integer, String), where first three numbers
379///                        define the highlighted region and represent line,
380///                        starting column and ending column (latter exclusive:
381///                        one should highlight region [start_col, end_col)).
382///
383/// @return
384///      - AST: top-level dict with these keys:
385///        - "error": Dict with error, present only if parser saw some
386///                 error. Contains the following keys:
387///          - "message": String, error message in printf format, translated.
388///                       Must contain exactly one `%.*s`.
389///          - "arg": String, error message argument.
390///        - "len": Amount of bytes successfully parsed. With flags equal to ""
391///                 that should be equal to the length of expr string.
392///                 ("Successfully parsed" here means "participated in AST
393///                  creation", not "till the first error".)
394///        - "ast": AST, either nil or a dict with these keys:
395///          - "type": node type, one of the value names from ExprASTNodeType
396///                    stringified without "kExprNode" prefix.
397///          - "start": a pair `[line, column]` describing where node is "started"
398///                     where "line" is always 0 (will not be 0 if you will be
399///                     using this API on e.g. ":let", but that is not
400///                     present yet). Both elements are Integers.
401///          - "len": “length” of the node. This and "start" are there for
402///                   debugging purposes primary (debugging parser and providing
403///                   debug information).
404///          - "children": a list of nodes described in top/"ast". There always
405///                        is zero, one or two children, key will not be present
406///                        if node has no children. Maximum number of children
407///                        may be found in node_maxchildren array.
408///      - Local values (present only for certain nodes):
409///        - "scope": a single Integer, specifies scope for "Option" and
410///                   "PlainIdentifier" nodes. For "Option" it is one of
411///                   ExprOptScope values, for "PlainIdentifier" it is one of
412///                   ExprVarScope values.
413///        - "ident": identifier (without scope, if any), present for "Option",
414///                   "PlainIdentifier", "PlainKey" and "Environment" nodes.
415///        - "name": Integer, register name (one character) or -1. Only present
416///                for "Register" nodes.
417///        - "cmp_type": String, comparison type, one of the value names from
418///                      ExprComparisonType, stringified without "kExprCmp"
419///                      prefix. Only present for "Comparison" nodes.
420///        - "ccs_strategy": String, case comparison strategy, one of the
421///                          value names from ExprCaseCompareStrategy,
422///                          stringified without "kCCStrategy" prefix. Only
423///                          present for "Comparison" nodes.
424///        - "augmentation": String, augmentation type for "Assignment" nodes.
425///                          Is either an empty string, "Add", "Subtract" or
426///                          "Concat" for "=", "+=", "-=" or ".=" respectively.
427///        - "invert": Boolean, true if result of comparison needs to be
428///                    inverted. Only present for "Comparison" nodes.
429///        - "ivalue": Integer, integer value for "Integer" nodes.
430///        - "fvalue": Float, floating-point value for "Float" nodes.
431///        - "svalue": String, value for "SingleQuotedString" and
432///                    "DoubleQuotedString" nodes.
433/// @param[out] err Error details, if any
434Dict nvim_parse_expression(String expr, String flags, Boolean hl, Arena *arena, Error *err)
435  FUNC_API_SINCE(4) FUNC_API_FAST
436{
437  int pflags = 0;
438  for (size_t i = 0; i < flags.size; i++) {
439    switch (flags.data[i]) {
440    case 'm':
441      pflags |= kExprFlagsMulti; break;
442    case 'E':
443      pflags |= kExprFlagsDisallowEOC; break;
444    case 'l':
445      pflags |= kExprFlagsParseLet; break;
446    case NUL:
447      api_set_error(err, kErrorTypeValidation, "Invalid flag: '\\0' (%u)",
448                    (unsigned)flags.data[i]);
449      return (Dict)ARRAY_DICT_INIT;
450    default:
451      api_set_error(err, kErrorTypeValidation, "Invalid flag: '%c' (%u)",
452                    flags.data[i], (unsigned)flags.data[i]);
453      return (Dict)ARRAY_DICT_INIT;
454    }
455  }
456  ParserLine parser_lines[] = {
457    {
458      .data = expr.data,
459      .size = expr.size,
460      .allocated = false,
461    },
462    { NULL, 0, false },
463  };
464  ParserLine *plines_p = parser_lines;
465  ParserHighlight colors;
466  kvi_init(colors);
467  ParserHighlight *const colors_p = (hl ? &colors : NULL);
468  ParserState pstate;
469  viml_parser_init(&pstate, parser_simple_get_line, &plines_p, colors_p);
470  ExprAST east = viml_pexpr_parse(&pstate, pflags);
471
472  const size_t ret_size = (2  // "ast", "len"
473                           + (size_t)(east.err.msg != NULL)  // "error"
474                           + (size_t)hl  // "highlight"
475                           + 0);
476
477  Dict ret = arena_dict(arena, ret_size);
478  PUT_C(ret, "len", INTEGER_OBJ((Integer)(pstate.pos.line == 1
479                                          ? parser_lines[0].size
480                                          : pstate.pos.col)));
481  if (east.err.msg != NULL) {
482    Dict err_dict = arena_dict(arena, 2);
483    PUT_C(err_dict, "message", CSTR_TO_ARENA_OBJ(arena, east.err.msg));
484    PUT_C(err_dict, "arg", CBUF_TO_ARENA_OBJ(arena, east.err.arg, (size_t)east.err.arg_len));
485    PUT_C(ret, "error", DICT_OBJ(err_dict));
486  }
487  if (hl) {
488    Array hl_arr = arena_array(arena, kv_size(colors));
489    for (size_t i = 0; i < kv_size(colors); i++) {
490      const ParserHighlightChunk chunk = kv_A(colors, i);
491      Array chunk_arr = arena_array(arena, 4);
492      ADD_C(chunk_arr, INTEGER_OBJ((Integer)chunk.start.line));
493      ADD_C(chunk_arr, INTEGER_OBJ((Integer)chunk.start.col));
494      ADD_C(chunk_arr, INTEGER_OBJ((Integer)chunk.end_col));
495      ADD_C(chunk_arr, CSTR_AS_OBJ(chunk.group));
496
497      ADD_C(hl_arr, ARRAY_OBJ(chunk_arr));
498    }
499    PUT_C(ret, "highlight", ARRAY_OBJ(hl_arr));
500  }
501  kvi_destroy(colors);
502
503  // Walk over the AST, freeing nodes in process.
504  ExprASTConvStack ast_conv_stack;
505  kvi_init(ast_conv_stack);
506  Object ast = NIL;
507  kvi_push(ast_conv_stack, ((ExprASTConvStackItem) {
508    .node_p = &east.root,
509    .ret_node_p = &ast,
510  }));
511  while (kv_size(ast_conv_stack)) {
512    ExprASTConvStackItem cur_item = kv_last(ast_conv_stack);
513    ExprASTNode *const node = *cur_item.node_p;
514    if (node == NULL) {
515      assert(kv_size(ast_conv_stack) == 1);
516      kv_drop(ast_conv_stack, 1);
517    } else {
518      if (cur_item.ret_node_p->type == kObjectTypeNil) {
519        size_t items_size = (size_t)(3  // "type", "start" and "len"  // NOLINT(bugprone-misplaced-widening-cast)
520                                     + (node->children != NULL)  // "children"
521                                     + (node->type == kExprNodeOption
522                                        || node->type == kExprNodePlainIdentifier)  // "scope"
523                                     + (node->type == kExprNodeOption
524                                        || node->type == kExprNodePlainIdentifier
525                                        || node->type == kExprNodePlainKey
526                                        || node->type == kExprNodeEnvironment)  // "ident"
527                                     + (node->type == kExprNodeRegister)  // "name"
528                                     + (3  // "cmp_type", "ccs_strategy", "invert"
529                                        * (node->type == kExprNodeComparison))
530                                     + (node->type == kExprNodeInteger)  // "ivalue"
531                                     + (node->type == kExprNodeFloat)  // "fvalue"
532                                     + (node->type == kExprNodeDoubleQuotedString
533                                        || node->type == kExprNodeSingleQuotedString)  // "svalue"
534                                     + (node->type == kExprNodeAssignment)  // "augmentation"
535                                     + 0);
536        Dict ret_node = arena_dict(arena, items_size);
537        *cur_item.ret_node_p = DICT_OBJ(ret_node);
538      }
539      Dict *ret_node = &cur_item.ret_node_p->data.dict;
540      if (node->children != NULL) {
541        const size_t num_children = 1 + (node->children->next != NULL);
542        Array children_array = arena_array(arena, num_children);
543        for (size_t i = 0; i < num_children; i++) {
544          ADD_C(children_array, NIL);
545        }
546        PUT_C(*ret_node, "children", ARRAY_OBJ(children_array));
547        kvi_push(ast_conv_stack, ((ExprASTConvStackItem) {
548          .node_p = &node->children,
549          .ret_node_p = &children_array.items[0],
550        }));
551      } else if (node->next != NULL) {
552        // ret_node_p + 1 is valid: we're in a children_array (root node never
553        // has "next"). kv_size > 1 confirms we're not at root.
554        assert(kv_size(ast_conv_stack) > 1);
555        kvi_push(ast_conv_stack, ((ExprASTConvStackItem) {
556          .node_p = &node->next,
557          .ret_node_p = cur_item.ret_node_p + 1,
558        }));
559      } else {
560        kv_drop(ast_conv_stack, 1);
561        PUT_C(*ret_node, "type", CSTR_AS_OBJ(east_node_type_tab[node->type]));
562        Array start_array = arena_array(arena, 2);
563        ADD_C(start_array, INTEGER_OBJ((Integer)node->start.line));
564        ADD_C(start_array, INTEGER_OBJ((Integer)node->start.col));
565        PUT_C(*ret_node, "start", ARRAY_OBJ(start_array));
566
567        PUT_C(*ret_node, "len", INTEGER_OBJ((Integer)node->len));
568        switch (node->type) {
569        case kExprNodeDoubleQuotedString:
570        case kExprNodeSingleQuotedString: {
571          Object str = CBUF_TO_ARENA_OBJ(arena, node->data.str.value, node->data.str.size);
572          PUT_C(*ret_node, "svalue", str);
573          xfree(node->data.str.value);
574          break;
575        }
576        case kExprNodeOption:
577          PUT_C(*ret_node, "scope", INTEGER_OBJ(node->data.opt.scope));
578          PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.opt.ident,
579                                                      node->data.opt.ident_len));
580          break;
581        case kExprNodePlainIdentifier:
582          PUT_C(*ret_node, "scope", INTEGER_OBJ(node->data.var.scope));
583          PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.var.ident,
584                                                      node->data.var.ident_len));
585          break;
586        case kExprNodePlainKey:
587          PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.var.ident,
588                                                      node->data.var.ident_len));
589          break;
590        case kExprNodeEnvironment:
591          PUT_C(*ret_node, "ident", CBUF_TO_ARENA_OBJ(arena, node->data.env.ident,
592                                                      node->data.env.ident_len));
593          break;
594        case kExprNodeRegister:
595          PUT_C(*ret_node, "name", INTEGER_OBJ(node->data.reg.name));
596          break;
597        case kExprNodeComparison:
598          PUT_C(*ret_node, "cmp_type", CSTR_AS_OBJ(eltkn_cmp_type_tab[node->data.cmp.type]));
599          PUT_C(*ret_node, "ccs_strategy", CSTR_AS_OBJ(ccs_tab[node->data.cmp.ccs]));
600          PUT_C(*ret_node, "invert", BOOLEAN_OBJ(node->data.cmp.inv));
601          break;
602        case kExprNodeFloat:
603          PUT_C(*ret_node, "fvalue", FLOAT_OBJ(node->data.flt.value));
604          break;
605        case kExprNodeInteger:
606          PUT_C(*ret_node, "ivalue", INTEGER_OBJ((Integer)(node->data.num.value > API_INTEGER_MAX
607                                                           ? API_INTEGER_MAX
608                                                           : (Integer)node->data.num.value)));
609          break;
610        case kExprNodeAssignment: {
611          const ExprAssignmentType asgn_type = node->data.ass.type;
612          String str = (asgn_type == kExprAsgnPlain
613                        ? (String)STRING_INIT : cstr_as_string(expr_asgn_type_tab[asgn_type]));
614          PUT_C(*ret_node, "augmentation", STRING_OBJ(str));
615          break;
616        }
617        case kExprNodeMissing:
618        case kExprNodeOpMissing:
619        case kExprNodeTernary:
620        case kExprNodeTernaryValue:
621        case kExprNodeSubscript:
622        case kExprNodeListLiteral:
623        case kExprNodeUnaryPlus:
624        case kExprNodeBinaryPlus:
625        case kExprNodeNested:
626        case kExprNodeCall:
627        case kExprNodeComplexIdentifier:
628        case kExprNodeUnknownFigure:
629        case kExprNodeLambda:
630        case kExprNodeDictLiteral:
631        case kExprNodeCurlyBracesIdentifier:
632        case kExprNodeComma:
633        case kExprNodeColon:
634        case kExprNodeArrow:
635        case kExprNodeConcat:
636        case kExprNodeConcatOrSubscript:
637        case kExprNodeOr:
638        case kExprNodeAnd:
639        case kExprNodeUnaryMinus:
640        case kExprNodeBinaryMinus:
641        case kExprNodeNot:
642        case kExprNodeMultiplication:
643        case kExprNodeDivision:
644        case kExprNodeMod:
645          break;
646        }
647        assert(cur_item.ret_node_p->data.dict.size == cur_item.ret_node_p->data.dict.capacity);
648        xfree(*cur_item.node_p);
649        *cur_item.node_p = NULL;
650      }
651    }
652  }
653  kvi_destroy(ast_conv_stack);
654  PUT_C(ret, "ast", ast);
655
656  assert(ret.size == ret.capacity);
657  // Should be a no-op actually, leaving it in case non-nodes will need to be
658  // freed later.
659  viml_pexpr_free_ast(east);
660  viml_parser_destroy(&pstate);
661  return ret;
662}