Skip to content

Commit 672776d

Browse files
ichizokbrammool
authored andcommitted
patch 8.2.4270: generating nv_cmdidxs.h requires building Vim twice
Problem: Generating nv_cmdidxs.h requires building Vim twice. Solution: Move the table into a separate file and use a separate executable to extract the command characters. (Ozaki Kiichi, closes #9669)
1 parent 48a6048 commit 672776d

File tree

14 files changed

+443
-418
lines changed

14 files changed

+443
-418
lines changed

Filelist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ SRC_ALL = \
114114
src/netbeans.c \
115115
src/normal.c \
116116
src/nv_cmdidxs.h \
117+
src/nv_cmds.h \
117118
src/ops.c \
118119
src/option.c \
119120
src/option.h \
@@ -444,6 +445,7 @@ SRC_UNIX = \
444445
src/configure \
445446
src/configure.ac \
446447
src/create_cmdidxs.vim \
448+
src/create_nvcmdidxs.c \
447449
src/create_nvcmdidxs.vim \
448450
src/gui_at_fs.c \
449451
src/gui_at_sb.c \

runtime/doc/builtin.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ inputrestore() Number restore typeahead
292292
inputsave() Number save and clear typeahead
293293
inputsecret({prompt} [, {text}]) String like input() but hiding the text
294294
insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
295-
internal_get_nv_cmdchar({idx}) Number command character at this index
296295
interrupt() none interrupt script execution
297296
invert({expr}) Number bitwise invert
298297
isdirectory({directory}) Number |TRUE| if {directory} is a directory
@@ -4618,11 +4617,6 @@ insert({object}, {item} [, {idx}]) *insert()*
46184617

46194618
Can also be used as a |method|: >
46204619
mylist->insert(item)
4621-
<
4622-
*internal_get_nv_cmdchar()*
4623-
internal_get_nv_cmdchar({idx})
4624-
Return the normal/visual mode command character at the
4625-
specified index. To be used only during the Vim build process.
46264620
46274621
interrupt() *interrupt()*
46284622
Interrupt script execution. It works more or less like the

runtime/doc/usr_41.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ Testing: *test-functions*
11101110
assert_nobeep() assert that a command does not cause a beep
11111111
assert_fails() assert that a command fails
11121112
assert_report() report a test failure
1113-
internal_get_nv_cmdchar() normal/visual command character at an index
11141113
test_alloc_fail() make memory allocation fail
11151114
test_autochdir() enable 'autochdir' during startup
11161115
test_override() test with Vim internal overrides

src/Make_cyg_ming.mak

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,17 +1145,17 @@ endif
11451145
# If this fails because you don't have Vim yet, first build and install Vim
11461146
# without changes.
11471147
cmdidxs: ex_cmds.h
1148-
vim --clean -X --not-a-term -u create_cmdidxs.vim
1148+
vim --clean -N -X --not-a-term -u create_cmdidxs.vim -c quit
11491149

11501150
# Run vim script to generate the normal/visual mode command lookup table.
11511151
# This only needs to be run when a new normal/visual mode command has been
11521152
# added. If this fails because you don't have Vim yet:
1153-
# - change nv_cmds[] in normal.c to add the new normal/visual mode command.
1154-
# - build Vim
1155-
# - run "make nvcmdidxs" using the new Vim to generate nv_cmdidxs.h
1156-
# - rebuild Vim to use the newly generated nv_cmdidxs.h file.
1157-
nvcmdidxs: normal.c
1158-
./$(TARGET) --clean -X --not-a-term -u create_nvcmdidxs.vim
1153+
# - change nv_cmds[] in nv_cmds.h to add the new normal/visual mode command.
1154+
# - run "make nvcmdidxs" to generate nv_cmdidxs.h
1155+
nvcmdidxs: nv_cmds.h
1156+
$(CC) $(CFLAGS) -o create_nvcmdidxs.exe create_nvcmdidxs.c $(LIB)
1157+
vim --clean -N -X --not-a-term -u create_nvcmdidxs.vim -c quit
1158+
-$(DEL) create_nvcmdidxs.exe
11591159

11601160
###########################################################################
11611161
INCL = vim.h alloc.h ascii.h ex_cmds.h feature.h errors.h globals.h \
@@ -1219,7 +1219,7 @@ $(OUTDIR)/hardcopy.o: hardcopy.c $(INCL) version.h
12191219

12201220
$(OUTDIR)/misc1.o: misc1.c $(INCL) version.h
12211221

1222-
$(OUTDIR)/normal.o: normal.c $(INCL) nv_cmdidxs.h
1222+
$(OUTDIR)/normal.o: normal.c $(INCL) nv_cmdidxs.h nv_cmds.h
12231223

12241224
$(OUTDIR)/netbeans.o: netbeans.c $(INCL) version.h
12251225

src/Make_mvc.mak

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,17 +1444,17 @@ clean: testclean
14441444
# If this fails because you don't have Vim yet, first build and install Vim
14451445
# without changes.
14461446
cmdidxs: ex_cmds.h
1447-
vim --clean -X --not-a-term -u create_cmdidxs.vim
1447+
vim --clean -N -X --not-a-term -u create_cmdidxs.vim -c quit
14481448

14491449
# Run vim script to generate the normal/visual mode command lookup table.
14501450
# This only needs to be run when a new normal/visual mode command has been
14511451
# added. If this fails because you don't have Vim yet:
1452-
# - change nv_cmds[] in normal.c to add the new normal/visual mode command.
1453-
# - build Vim
1454-
# - run "make nvcmdidxs" using the new Vim to generate nv_cmdidxs.h
1455-
# - rebuild Vim to use the newly generated nv_cmdidxs.h file.
1456-
nvcmdidxs: normal.c
1457-
.\$(VIM) --clean -X --not-a-term -u create_nvcmdidxs.vim
1452+
# - change nv_cmds[] in nv_cmds.h to add the new normal/visual mode command.
1453+
# - run "make nvcmdidxs" to generate nv_cmdidxs.h
1454+
nvcmdidxs: nv_cmds.h
1455+
$(CC) /nologo -I. -Iproto -DNDEBUG create_nvcmdidxs.c -link -subsystem:$(SUBSYSTEM_TOOLS)
1456+
vim --clean -N -X --not-a-term -u create_nvcmdidxs.vim -c quit
1457+
-del create_nvcmdidxs.exe
14581458

14591459
test:
14601460
cd testdir
@@ -1719,7 +1719,7 @@ $(OUTDIR)/netbeans.obj: $(OUTDIR) netbeans.c $(NBDEBUG_SRC) $(INCL) version.h
17191719

17201720
$(OUTDIR)/channel.obj: $(OUTDIR) channel.c $(INCL)
17211721

1722-
$(OUTDIR)/normal.obj: $(OUTDIR) normal.c $(INCL) nv_cmdidxs.h
1722+
$(OUTDIR)/normal.obj: $(OUTDIR) normal.c $(INCL) nv_cmdidxs.h nv_cmds.h
17231723

17241724
$(OUTDIR)/option.obj: $(OUTDIR) option.c $(INCL) optiondefs.h
17251725

src/Make_vms.mms

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ mbyte.obj : mbyte.c vim.h [.auto]config.h feature.h os_unix.h \
977977
normal.obj : normal.c vim.h [.auto]config.h feature.h os_unix.h \
978978
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h \
979979
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
980-
errors.h globals.h nv_cmdidxs.h
980+
errors.h globals.h nv_cmdidxs.h nv_cmds.h
981981
ops.obj : ops.c vim.h [.auto]config.h feature.h os_unix.h \
982982
ascii.h keymap.h termdefs.h macros.h structs.h regexp.h gui.h beval.h \
983983
[.proto]gui_beval.pro option.h ex_cmds.h proto.h errors.h globals.h

src/Makefile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,19 +2141,21 @@ autoconf:
21412141
# This only needs to be run when a command name has been added or changed.
21422142
# If this fails because you don't have Vim yet, first build and install Vim
21432143
# without changes.
2144+
# This requires a "vim" executable with the +eval feature.
21442145
cmdidxs: ex_cmds.h
2145-
vim --clean -X --not-a-term -u create_cmdidxs.vim
2146+
vim --clean -N -X --not-a-term -u create_cmdidxs.vim -c quit
21462147

21472148
# Run vim script to generate the normal/visual mode command lookup table.
21482149
# This only needs to be run when a new normal/visual mode command has been
2149-
# added. If this fails because you don't have Vim yet:
2150-
# - change nv_cmds[] in normal.c to add the new normal/visual mode command.
2151-
# - build Vim
2152-
# - run "make nvcmdidxs" using the new Vim to generate nv_cmdidxs.h
2153-
# - rebuild Vim to use the newly generated nv_cmdidxs.h file.
2154-
nvcmdidxs: normal.c
2155-
./$(VIMTARGET) --clean -X --not-a-term -u create_nvcmdidxs.vim
2156-
2150+
# added.
2151+
# This requires a "vim" executable with the +eval feature.
2152+
# If this fails because you don't have Vim yet:
2153+
# - change nv_cmds[] in nv_cmds.h to add the new normal/visual mode command.
2154+
# - run "make nvcmdidxs" to generate nv_cmdidxs.h
2155+
nvcmdidxs: auto/config.mk nv_cmds.h
2156+
$(CC) -I$(srcdir) $(ALL_CFLAGS) create_nvcmdidxs.c -o create_nvcmdidxs
2157+
vim --clean -N -X --not-a-term -u create_nvcmdidxs.vim -c quit
2158+
-rm -f create_nvcmdidxs
21572159

21582160
# The normal command to compile a .c file to its .o file.
21592161
# Without or with ALL_CFLAGS.
@@ -4012,7 +4014,7 @@ objects/move.o: move.c vim.h protodef.h auto/config.h feature.h os_unix.h \
40124014
objects/normal.o: normal.c vim.h protodef.h auto/config.h feature.h os_unix.h \
40134015
auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
40144016
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
4015-
proto.h globals.h errors.h nv_cmdidxs.h
4017+
proto.h globals.h errors.h nv_cmdidxs.h nv_cmds.h
40164018
objects/ops.o: ops.c vim.h protodef.h auto/config.h feature.h os_unix.h \
40174019
auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
40184020
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \

src/create_nvcmdidxs.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* vi:set ts=8 sts=4 sw=4 noet:
2+
*
3+
* VIM - Vi IMproved by Bram Moolenaar et al.
4+
*
5+
* Do ":help uganda" in Vim to read copying and usage conditions.
6+
* Do ":help credits" in Vim to see a list of people who contributed.
7+
* See README.txt for an overview of the Vim source code.
8+
*/
9+
10+
/*
11+
* create_nvcmdidxs.c: helper program for `make nvcmdidxs`
12+
*
13+
* This outputs the list of command characters from the nv_cmds table in
14+
* decimal form, one per line.
15+
*/
16+
17+
#include "vim.h"
18+
19+
// Declare nv_cmds[].
20+
#include "nv_cmds.h"
21+
22+
#include <stdio.h>
23+
24+
int main(void)
25+
{
26+
size_t i;
27+
28+
for (i = 0; i < NV_CMDS_SIZE; i++)
29+
{
30+
int cmdchar = nv_cmds[i];
31+
32+
// Special keys are negative, use the negated value for sorting.
33+
if (cmdchar < 0)
34+
cmdchar = -cmdchar;
35+
printf("%d\n", cmdchar);
36+
}
37+
return 0;
38+
}

src/create_nvcmdidxs.vim

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,60 @@
1-
vim9script
2-
3-
# This script generates the table nv_cmd_idx[] which contains the index in
4-
# nv_cmds[] table (normal.c) for each of the command character supported in
5-
# normal/visual mode.
6-
# This is used to speed up the command lookup in nv_cmds[].
7-
#
8-
# Script should be run using "make nvcmdidxs", every time the nv_cmds[] table
9-
# in src/normal.c changes.
10-
11-
def Create_nvcmdidxs_table()
12-
var nv_cmdtbl: list<dict<number>> = []
13-
14-
# Generate the table of normal/visual mode command characters and their
15-
# corresponding index.
16-
var idx: number = 0
17-
var ch: number
18-
while true
19-
ch = internal_get_nv_cmdchar(idx)
20-
if ch == -1
21-
break
22-
endif
23-
add(nv_cmdtbl, {idx: idx, cmdchar: ch})
24-
idx += 1
25-
endwhile
26-
27-
# sort the table by the command character
28-
sort(nv_cmdtbl, (a, b) => a.cmdchar - b.cmdchar)
29-
30-
# Compute the highest index upto which the command character can be directly
31-
# used as an index.
32-
var nv_max_linear: number = 0
33-
for i in range(nv_cmdtbl->len())
34-
if i != nv_cmdtbl[i].cmdchar
35-
nv_max_linear = i - 1
36-
break
37-
endif
38-
endfor
39-
40-
# Generate a header file with the table
41-
var output: list<string> =<< trim END
42-
/*
43-
* Automatically generated code by the create_nvcmdidxs.vim script.
44-
*
45-
* Table giving the index in nv_cmds[] to lookup based on
46-
* the command character.
47-
*/
48-
49-
// nv_cmd_idx[<normal mode command character>] => nv_cmds[] index
50-
static const unsigned short nv_cmd_idx[] =
51-
{
52-
END
53-
54-
# Add each command character in comment and the corresponding index
55-
var tbl: list<string> = mapnew(nv_cmdtbl, (k, v) =>
56-
' /* ' .. printf('%5d', v.cmdchar) .. ' */ ' ..
57-
printf('%3d', v.idx) .. ','
58-
)
59-
output += tbl
60-
61-
output += [ '};', '',
62-
'// The highest index for which',
63-
'// nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char]']
64-
output += ['static const int nv_max_linear = ' .. nv_max_linear .. ';']
65-
66-
writefile(output, "nv_cmdidxs.h")
67-
enddef
68-
69-
Create_nvcmdidxs_table()
1+
" This script generates the table nv_cmd_idx[] which contains the index in
2+
" nv_cmds[] table (normal.c) for each of the command character supported in
3+
" normal/visual mode.
4+
" This is used to speed up the command lookup in nv_cmds[].
5+
"
6+
" Script should be run using "make nvcmdidxs", every time the nv_cmds[] table
7+
" in src/nv_cmds.h changes.
8+
"
9+
" This is written in legacy Vim script so that it can be run by a slightly
10+
" older Vim version.
11+
12+
" Generate the table of normal/visual mode command characters and their
13+
" corresponding index.
14+
let cmd = 'create_nvcmdidxs'
15+
if has('unix')
16+
let cmd = './' .. cmd
17+
endif
18+
let nv_cmdtbl = systemlist(cmd)->map({i, ch -> {'idx': i, 'cmdchar': ch}})
19+
20+
" sort the table by the command character
21+
call sort(nv_cmdtbl, {a, b -> a.cmdchar - b.cmdchar})
22+
23+
" Compute the highest index upto which the command character can be directly
24+
" used as an index.
25+
let nv_max_linear = 0
26+
for i in range(nv_cmdtbl->len())
27+
if i != nv_cmdtbl[i].cmdchar
28+
let nv_max_linear = i - 1
29+
break
30+
endif
31+
endfor
32+
33+
" Generate a header file with the table
34+
let output =<< trim END
35+
/*
36+
* Automatically generated code by the create_nvcmdidxs.vim script.
37+
*
38+
* Table giving the index in nv_cmds[] to lookup based on
39+
* the command character.
40+
*/
41+
42+
// nv_cmd_idx[<normal mode command character>] => nv_cmds[] index
43+
static const unsigned short nv_cmd_idx[] =
44+
{
45+
END
46+
47+
" Add each command character in comment and the corresponding index
48+
let output += nv_cmdtbl->map({_, v ->
49+
\ printf(' /* %5d */ %3d,', v.cmdchar, v.idx)})
50+
51+
let output += ['};', '',
52+
\ '// The highest index for which',
53+
\ '// nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char]']
54+
55+
let output += ['static const int nv_max_linear = ' .. nv_max_linear .. ';']
56+
57+
call writefile(output, "nv_cmdidxs.h")
7058
quit
7159

72-
# vim: shiftwidth=2 sts=2 expandtab
60+
" vim: shiftwidth=2 sts=2 expandtab

src/evalfunc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,6 @@ static funcentry_T global_functions[] =
17351735
ret_string, f_inputsecret},
17361736
{"insert", 2, 3, FEARG_1, arg23_insert,
17371737
ret_first_arg, f_insert},
1738-
{"internal_get_nv_cmdchar", 1, 1, FEARG_1, arg1_number,
1739-
ret_number, f_internal_get_nv_cmdchar},
17401738
{"interrupt", 0, 0, 0, NULL,
17411739
ret_void, f_interrupt},
17421740
{"invert", 1, 1, FEARG_1, arg1_number,

0 commit comments

Comments
 (0)