diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-05-09 22:50:08 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-05-09 22:50:08 +0200 |
commit | 09689a02840be40fa7bb10b1921fb5bc5b2908f1 (patch) | |
tree | 4aced60f6702ce56232c9ee70bf977234e054c39 /src/scriptfile.c | |
parent | 396f3138ca83ce844679143861f544070683d479 (diff) | |
download | vim-git-09689a02840be40fa7bb10b1921fb5bc5b2908f1.tar.gz |
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 scriptv8.2.0725
Problem: Vim9: cannot call a function declared later in Vim9 script.
Solution: Make two passes through the script file.
Diffstat (limited to 'src/scriptfile.c')
-rw-r--r-- | src/scriptfile.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/scriptfile.c b/src/scriptfile.c index 155ab14bb..ba74a8aec 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -998,6 +998,8 @@ struct source_cookie int error; // TRUE if LF found after CR-LF #endif #ifdef FEAT_EVAL + garray_T lines_ga; // lines read in previous pass + int use_lines_ga; // next line to get from "lines_ga" linenr_T breakpoint; // next line with breakpoint or zero char_u *fname; // name of sourced file int dbg_tick; // debug_tick when breakpoint was set @@ -1017,6 +1019,24 @@ source_breakpoint(void *cookie) } /* + * Get the grow array to store script lines in. + */ + garray_T * +source_get_line_ga(void *cookie) +{ + return &((struct source_cookie *)cookie)->lines_ga; +} + +/* + * Set the index to start reading from the grow array with script lines. + */ + void +source_use_line_ga(void *cookie) +{ + ((struct source_cookie *)cookie)->use_lines_ga = 0; +} + +/* * Return the address holding the debug tick for a source cookie. */ int * @@ -1235,6 +1255,9 @@ do_source( cookie.finished = FALSE; #ifdef FEAT_EVAL + ga_init2(&cookie.lines_ga, sizeof(char_u *), 200); + cookie.use_lines_ga = -1; + // Check if this script has a breakpoint. cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); cookie.fname = fname_exp; @@ -1447,6 +1470,9 @@ almosttheend: vim_free(cookie.nextline); vim_free(firstline); convert_setup(&cookie.conv, NULL, NULL); +#ifdef FEAT_EVAL + ga_clear_strings(&cookie.lines_ga); +#endif if (trigger_source_post) apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf); @@ -1702,6 +1728,31 @@ getsourceline(int c UNUSED, void *cookie, int indent UNUSED, int do_concat) // one now. if (sp->finished) line = NULL; +#ifdef FEAT_EVAL + else if (sp->use_lines_ga >= 0) + { + // Get a line that was read in ex_vim9script(). + for (;;) + { + if (sp->use_lines_ga >= sp->lines_ga.ga_len) + { + line = NULL; + break; + } + else + { + line = ((char_u **)(sp->lines_ga.ga_data))[sp->use_lines_ga]; + ((char_u **)(sp->lines_ga.ga_data))[sp->use_lines_ga] = NULL; + ++sp->use_lines_ga; + if (line != NULL) + break; + // Skip NULL lines, they are equivalent to blank lines. + ++sp->sourcing_lnum; + } + } + SOURCING_LNUM = sp->sourcing_lnum + 1; + } +#endif else if (sp->nextline == NULL) line = get_one_sourceline(sp); else |