aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2022-07-18 19:37:18 +0000
committerJosh Rahm <rahm@google.com>2022-07-18 19:37:18 +0000
commit308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (patch)
tree35fe43e01755e0f312650667004487a44d6b7941 /src/nvim/generators
parent96a00c7c588b2f38a2424aeeb4ea3581d370bf2d (diff)
parente8c94697bcbe23a5c7b07c292b90a6b70aadfa87 (diff)
downloadrneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.gz
rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.bz2
rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.zip
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'src/nvim/generators')
-rw-r--r--src/nvim/generators/c_grammar.lua1
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua43
-rwxr-xr-x[-rw-r--r--]src/nvim/generators/gen_api_ui_events.lua99
-rw-r--r--src/nvim/generators/gen_char_blob.lua20
-rw-r--r--src/nvim/generators/gen_eval.lua45
-rw-r--r--src/nvim/generators/gen_ex_cmds.lua15
-rw-r--r--src/nvim/generators/gen_keysets.lua3
-rw-r--r--src/nvim/generators/hashy.lua24
8 files changed, 179 insertions, 71 deletions
diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua
index f35817c466..70a7be86b5 100644
--- a/src/nvim/generators/c_grammar.lua
+++ b/src/nvim/generators/c_grammar.lua
@@ -49,6 +49,7 @@ local c_proto = Ct(
(fill * Cg((P('FUNC_API_REMOTE_IMPL') * Cc(true)), 'remote_impl') ^ -1) *
(fill * Cg((P('FUNC_API_BRIDGE_IMPL') * Cc(true)), 'bridge_impl') ^ -1) *
(fill * Cg((P('FUNC_API_COMPOSITOR_IMPL') * Cc(true)), 'compositor_impl') ^ -1) *
+ (fill * Cg((P('FUNC_API_CLIENT_IMPL') * Cc(true)), 'client_impl') ^ -1) *
fill * P(';')
)
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index c6dd25154b..4cf282770d 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -16,6 +16,10 @@ local functions = {}
local nvimdir = arg[1]
package.path = nvimdir .. '/?.lua;' .. package.path
+_G.vim = loadfile(nvimdir..'/../../runtime/lua/vim/shared.lua')()
+
+local hashy = require'generators.hashy'
+
-- names of all headers relative to the source root (for inclusion in the
-- generated file)
local headers = {}
@@ -208,8 +212,8 @@ for i = 1, #functions do
output:write('Object handle_'..fn.name..'(uint64_t channel_id, Array args, Error *error)')
output:write('\n{')
- output:write('\n#if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL')
- output:write('\n logmsg(DEBUG_LOG_LEVEL, "RPC: ", NULL, -1, true, "ch %" PRIu64 ": invoke '
+ output:write('\n#if MIN_LOG_LEVEL <= LOGLVL_DBG')
+ output:write('\n logmsg(LOGLVL_DBG, "RPC: ", NULL, -1, true, "ch %" PRIu64 ": invoke '
..fn.name..'", channel_id);')
output:write('\n#endif')
output:write('\n Object ret = NIL;')
@@ -288,7 +292,7 @@ for i = 1, #functions do
if fn.check_textlock then
output:write('\n if (textlock != 0) {')
- output:write('\n api_set_error(error, kErrorTypeException, "%s", e_secure);')
+ output:write('\n api_set_error(error, kErrorTypeException, "%s", e_textlock);')
output:write('\n goto cleanup;')
output:write('\n }\n')
end
@@ -339,24 +343,27 @@ for i = 1, #functions do
end
end
--- Generate a function that initializes method names with handler functions
-output:write([[
-void msgpack_rpc_init_method_table(void)
-{
-]])
-
-for i = 1, #functions do
- local fn = functions[i]
+local remote_fns = {}
+for _,fn in ipairs(functions) do
if fn.remote then
- output:write(' msgpack_rpc_add_method_handler('..
- '(String) {.data = "'..fn.name..'", '..
- '.size = sizeof("'..fn.name..'") - 1}, '..
- '(MsgpackRpcRequestHandler) {.fn = handle_'.. (fn.impl_name or fn.name)..
- ', .fast = '..tostring(fn.fast)..'});\n')
+ remote_fns[fn.name] = fn
end
end
+remote_fns.redraw = {impl_name="ui_client_redraw", fast=true}
+
+local hashorder, hashfun = hashy.hashy_hash("msgpack_rpc_get_handler_for", vim.tbl_keys(remote_fns), function (idx)
+ return "method_handlers["..idx.."].name"
+end)
+
+output:write("static const MsgpackRpcRequestHandler method_handlers[] = {\n")
+for _, name in ipairs(hashorder) do
+ local fn = remote_fns[name]
+ output:write(' { .name = "'..name..'", .fn = handle_'.. (fn.impl_name or fn.name)..
+ ', .fast = '..tostring(fn.fast)..'},\n')
+end
+output:write("};\n\n")
+output:write(hashfun)
-output:write('\n}\n\n')
output:close()
local mpack_output = io.open(mpack_outputf, 'wb')
@@ -428,7 +435,7 @@ local function process_function(fn)
if fn.check_textlock then
write_shifted_output(output, [[
if (textlock != 0) {
- api_set_error(&err, kErrorTypeException, "%s", e_secure);
+ api_set_error(&err, kErrorTypeException, "%s", e_textlock);
goto exit_0;
}
]])
diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua
index 3cb117d8b5..93bbaab74c 100644..100755
--- a/src/nvim/generators/gen_api_ui_events.lua
+++ b/src/nvim/generators/gen_api_ui_events.lua
@@ -3,17 +3,21 @@ local mpack = require('mpack')
local nvimdir = arg[1]
package.path = nvimdir .. '/?.lua;' .. package.path
-assert(#arg == 7)
+assert(#arg == 8)
local input = io.open(arg[2], 'rb')
local proto_output = io.open(arg[3], 'wb')
local call_output = io.open(arg[4], 'wb')
local remote_output = io.open(arg[5], 'wb')
local bridge_output = io.open(arg[6], 'wb')
local metadata_output = io.open(arg[7], 'wb')
+local client_output = io.open(arg[8], 'wb')
local c_grammar = require('generators.c_grammar')
local events = c_grammar.grammar:match(input:read('*all'))
+_G.vim = loadfile(nvimdir..'/../../runtime/lua/vim/shared.lua')()
+local hashy = require'generators.hashy'
+
local function write_signature(output, ev, prefix, notype)
output:write('('..prefix)
if prefix == "" and #ev.parameters == 0 then
@@ -32,24 +36,62 @@ local function write_signature(output, ev, prefix, notype)
output:write(')')
end
-local function write_arglist(output, ev, need_copy)
- output:write(' Array args = ARRAY_DICT_INIT;\n')
+local function write_arglist(output, ev)
for j = 1, #ev.parameters do
local param = ev.parameters[j]
local kind = string.upper(param[1])
- local do_copy = need_copy and (kind == "ARRAY" or kind == "DICTIONARY" or kind == "STRING" or kind == "OBJECT")
- output:write(' ADD(args, ')
- if do_copy then
- output:write('copy_object(')
- end
+ output:write(' ADD_C(args, ')
output:write(kind..'_OBJ('..param[2]..')')
- if do_copy then
- output:write(')')
- end
output:write(');\n')
end
end
+local function call_ui_event_method(output, ev)
+ output:write('void ui_client_event_'..ev.name..'(Array args)\n{\n')
+
+ local hlattrs_args_count = 0
+ if #ev.parameters > 0 then
+ output:write(' if (args.size < '..(#ev.parameters))
+ for j = 1, #ev.parameters do
+ local kind = ev.parameters[j][1]
+ if kind ~= "Object" then
+ if kind == 'HlAttrs' then kind = 'Dictionary' end
+ output:write('\n || args.items['..(j-1)..'].type != kObjectType'..kind..'')
+ end
+ end
+ output:write(') {\n')
+ output:write(' ELOG("Error handling ui event \''..ev.name..'\'");\n')
+ output:write(' return;\n')
+ output:write(' }\n')
+ end
+
+ for j = 1, #ev.parameters do
+ local param = ev.parameters[j]
+ local kind = param[1]
+ output:write(' '..kind..' arg_'..j..' = ')
+ if kind == 'HlAttrs' then
+ -- The first HlAttrs argument is rgb_attrs and second is cterm_attrs
+ output:write('ui_client_dict2hlattrs(args.items['..(j-1)..'].data.dictionary, '..(hlattrs_args_count == 0 and 'true' or 'false')..');\n')
+ hlattrs_args_count = hlattrs_args_count + 1
+ elseif kind == 'Object' then
+ output:write('args.items['..(j-1)..'];\n')
+ else
+ output:write('args.items['..(j-1)..'].data.'..string.lower(kind)..';\n')
+ end
+ end
+
+ output:write(' ui_call_'..ev.name..'(')
+ for j = 1, #ev.parameters do
+ output:write('arg_'..j)
+ if j ~= #ev.parameters then
+ output:write(', ')
+ end
+ end
+ output:write(');\n')
+
+ output:write('}\n\n')
+end
+
for i = 1, #events do
local ev = events[i]
assert(ev.return_type == 'void')
@@ -69,7 +111,9 @@ for i = 1, #events do
remote_output:write('static void remote_ui_'..ev.name)
write_signature(remote_output, ev, 'UI *ui')
remote_output:write('\n{\n')
- write_arglist(remote_output, ev, true)
+ remote_output:write(' UIData *data = ui->data;\n')
+ remote_output:write(' Array args = data->call_buf;\n')
+ write_arglist(remote_output, ev)
remote_output:write(' push_call(ui, "'..ev.name..'", args);\n')
remote_output:write('}\n\n')
end
@@ -136,9 +180,10 @@ for i = 1, #events do
write_signature(call_output, ev, '')
call_output:write('\n{\n')
if ev.remote_only then
- write_arglist(call_output, ev, false)
+ call_output:write(' Array args = call_buf;\n')
+ write_arglist(call_output, ev)
call_output:write(' UI_LOG('..ev.name..');\n')
- call_output:write(' ui_event("'..ev.name..'", args);\n')
+ call_output:write(' ui_call_event("'..ev.name..'", args);\n')
elseif ev.compositor_impl then
call_output:write(' UI_CALL')
write_signature(call_output, ev, '!ui->composed, '..ev.name..', ui', true)
@@ -160,12 +205,36 @@ for i = 1, #events do
call_output:write(";\n")
call_output:write("}\n\n")
end
+
+ if (not ev.remote_only) and (not ev.noexport) and (not ev.client_impl) then
+ call_ui_event_method(client_output, ev)
+ end
+end
+
+local client_events = {}
+for _,ev in ipairs(events) do
+ if (not ev.noexport) and ((not ev.remote_only) or ev.client_impl) then
+ client_events[ev.name] = ev
+ end
+end
+
+local hashorder, hashfun = hashy.hashy_hash("ui_client_handler", vim.tbl_keys(client_events), function (idx)
+ return "event_handlers["..idx.."].name"
+end)
+
+client_output:write("static const UIClientHandler event_handlers[] = {\n")
+
+for _, name in ipairs(hashorder) do
+ client_output:write(' { .name = "'..name..'", .fn = ui_client_event_'..name..'},\n')
end
+client_output:write('\n};\n\n')
+client_output:write(hashfun)
+
proto_output:close()
call_output:close()
remote_output:close()
-bridge_output:close()
+client_output:close()
-- don't expose internal attributes like "impl_name" in public metadata
local exported_attributes = {'name', 'parameters',
diff --git a/src/nvim/generators/gen_char_blob.lua b/src/nvim/generators/gen_char_blob.lua
index 3ec1ff2caf..11f6cbcc13 100644
--- a/src/nvim/generators/gen_char_blob.lua
+++ b/src/nvim/generators/gen_char_blob.lua
@@ -28,16 +28,19 @@ local target = io.open(target_file, 'w')
target:write('#include <stdint.h>\n\n')
+local index_items = {}
+
local warn_on_missing_compiler = true
-local varnames = {}
+local modnames = {}
for argi = 2, #arg, 2 do
local source_file = arg[argi]
- local varname = arg[argi + 1]
- if varnames[varname] then
- error(string.format("varname %q is already specified for file %q", varname, varnames[varname]))
+ local modname = arg[argi + 1]
+ if modnames[modname] then
+ error(string.format("modname %q is already specified for file %q", modname, modnames[modname]))
end
- varnames[varname] = source_file
+ modnames[modname] = source_file
+ local varname = string.gsub(modname,'%.','_dot_').."_module"
target:write(('static const uint8_t %s[] = {\n'):format(varname))
local output
@@ -78,6 +81,13 @@ for argi = 2, #arg, 2 do
end
target:write(' 0};\n')
+ if modname ~= "_" then
+ table.insert(index_items, ' { "'..modname..'", '..varname..', sizeof '..varname..' },\n\n')
+ end
end
+target:write('static ModuleDef builtin_modules[] = {\n')
+target:write(table.concat(index_items))
+target:write('};\n')
+
target:close()
diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua
index 945fa5099f..c72249161b 100644
--- a/src/nvim/generators/gen_eval.lua
+++ b/src/nvim/generators/gen_eval.lua
@@ -1,9 +1,12 @@
local mpack = require('mpack')
local nvimsrcdir = arg[1]
-local autodir = arg[2]
-local metadata_file = arg[3]
-local funcs_file = arg[4]
+local shared_file = arg[2]
+local autodir = arg[3]
+local metadata_file = arg[4]
+local funcs_file = arg[5]
+
+_G.vim = loadfile(shared_file)()
if nvimsrcdir == '--help' then
print([[
@@ -20,7 +23,9 @@ package.path = nvimsrcdir .. '/?.lua;' .. package.path
local funcsfname = autodir .. '/funcs.generated.h'
-local gperfpipe = io.open(funcsfname .. '.gperf', 'wb')
+local hashy = require'generators.hashy'
+
+local hashpipe = io.open(funcsfname, 'wb')
local funcs = require('eval').funcs
local metadata = mpack.unpack(io.open(metadata_file, 'rb'):read("*all"))
@@ -38,21 +43,15 @@ local funcsdata = io.open(funcs_file, 'w')
funcsdata:write(mpack.pack(funcs))
funcsdata:close()
-gperfpipe:write([[
-%language=ANSI-C
-%global-table
-%readonly-tables
-%define initializer-suffix ,0,0,BASE_NONE,NULL,NULL
-%define word-array-name functions
-%define hash-function-name hash_internal_func_gperf
-%define lookup-function-name find_internal_func_gperf
-%omit-struct-type
-%struct-type
-VimLFuncDef;
-%%
-]])
-for name, def in pairs(funcs) do
+local names = vim.tbl_keys(funcs)
+
+local neworder, hashfun = hashy.hashy_hash("find_internal_func", names, function (idx)
+ return "functions["..idx.."].name"
+end)
+hashpipe:write("static const EvalFuncDef functions[] = {\n")
+for _, name in ipairs(neworder) do
+ local def = funcs[name]
local args = def.args or 0
if type(args) == 'number' then
args = {args, args}
@@ -62,7 +61,11 @@ for name, def in pairs(funcs) do
local base = def.base or "BASE_NONE"
local func = def.func or ('f_' .. name)
local data = def.data or "NULL"
- gperfpipe:write(('%s, %s, %s, %s, &%s, (FunPtr)%s\n')
- :format(name, args[1], args[2], base, func, data))
+ local fast = def.fast and 'true' or 'false'
+ hashpipe:write((' { "%s", %s, %s, %s, %s, &%s, (FunPtr)%s },\n')
+ :format(name, args[1], args[2], base, fast, func, data))
end
-gperfpipe:close()
+hashpipe:write(' { NULL, 0, 0, BASE_NONE, false, NULL, NULL },\n')
+hashpipe:write("};\n\n")
+hashpipe:write(hashfun)
+hashpipe:close()
diff --git a/src/nvim/generators/gen_ex_cmds.lua b/src/nvim/generators/gen_ex_cmds.lua
index 844661adc3..255c415a4d 100644
--- a/src/nvim/generators/gen_ex_cmds.lua
+++ b/src/nvim/generators/gen_ex_cmds.lua
@@ -65,20 +65,31 @@ for _, cmd in ipairs(defs) do
assert(cmd.addr_type ~= 'ADDR_OTHER' and cmd.addr_type ~= 'ADDR_NONE',
string.format('ex_cmds.lua:%s: Missing misplaced DFLALL\n', cmd.command))
end
+ if bit.band(cmd.flags, flags.PREVIEW) == flags.PREVIEW then
+ assert(cmd.preview_func ~= nil,
+ string.format('ex_cmds.lua:%s: Missing preview_func\n', cmd.command))
+ end
local enumname = cmd.enum or ('CMD_' .. cmd.command)
local byte_cmd = cmd.command:sub(1, 1):byte()
if byte_a <= byte_cmd and byte_cmd <= byte_z then
table.insert(cmds, cmd.command)
end
+ local preview_func
+ if cmd.preview_func then
+ preview_func = string.format("(ex_preview_func_T)&%s", cmd.preview_func)
+ else
+ preview_func = "NULL"
+ end
enumfile:write(' ' .. enumname .. ',\n')
defsfile:write(string.format([[
[%s] = {
- .cmd_name = (char_u *) "%s",
+ .cmd_name = "%s",
.cmd_func = (ex_func_T)&%s,
+ .cmd_preview_func = %s,
.cmd_argt = %uL,
.cmd_addr_type = %s
},
-]], enumname, cmd.command, cmd.func, cmd.flags, cmd.addr_type))
+]], enumname, cmd.command, cmd.func, preview_func, cmd.flags, cmd.addr_type))
end
for i = #cmds, 1, -1 do
local cmd = cmds[i]
diff --git a/src/nvim/generators/gen_keysets.lua b/src/nvim/generators/gen_keysets.lua
index 01d8c1d357..633c5da184 100644
--- a/src/nvim/generators/gen_keysets.lua
+++ b/src/nvim/generators/gen_keysets.lua
@@ -27,7 +27,8 @@ local defspipe = io.open(defs_file, 'wb')
local keysets = require'api.keysets'
local keywords = {
- register = true,
+ register = true;
+ default = true;
}
local function sanitize(key)
diff --git a/src/nvim/generators/hashy.lua b/src/nvim/generators/hashy.lua
index fac24c810a..b10bafb9f9 100644
--- a/src/nvim/generators/hashy.lua
+++ b/src/nvim/generators/hashy.lua
@@ -77,7 +77,7 @@ function M.switcher(put, tab, maxlen, worst_buck_size)
put "break;\n"
end
put " default: break;\n"
- put " }\n "
+ put " }\n "
else
local startidx = #neworder
table.insert(neworder, posbuck[keys[1]][1])
@@ -85,7 +85,7 @@ function M.switcher(put, tab, maxlen, worst_buck_size)
put("low = "..startidx.."; ")
if bucky then put("high = "..endidx.."; ") end
end
- put " break;\n"
+ put "break;\n"
end
end
put " default: break;\n"
@@ -105,17 +105,23 @@ function M.hashy_hash(name, strings, access)
end
local neworder = M.switcher(put, len_pos_buckets, maxlen, worst_buck_size)
if worst_buck_size > 1 then
- error [[ not implemented yet ]] -- TODO(bfredl)
+ put ([[
+ for (int i = low; i < high; i++) {
+ if (!memcmp(str, ]]..access("i")..[[, len)) {
+ return i;
+ }
+ }
+ return -1;
+]])
else
- put [[
- if (low < 0) {
+ put ([[
+ if (low < 0 || memcmp(str, ]]..access("low")..[[, len)) {
return -1;
}
- ]]
- put("if(memcmp(str, "..access("low")..", len)) {\n return -1;\n }\n")
- put " return low;\n"
- put "}\n\n"
+ return low;
+]])
end
+ put "}\n\n"
return neworder, table.concat(stats)
end