2016-06-18 03:06:50 -07:00
|
|
|
mpack = require('mpack')
|
|
|
|
|
2016-01-01 02:17:22 -07:00
|
|
|
local nvimsrcdir = arg[1]
|
|
|
|
local autodir = arg[2]
|
2016-06-18 03:06:50 -07:00
|
|
|
local metadata_file = arg[3]
|
2016-06-19 07:41:08 -07:00
|
|
|
local funcs_file = arg[4]
|
2016-01-01 02:17:22 -07:00
|
|
|
|
|
|
|
if nvimsrcdir == '--help' then
|
|
|
|
print([[
|
|
|
|
Usage:
|
|
|
|
lua geneval.lua src/nvim build/src/nvim/auto
|
|
|
|
|
|
|
|
Will generate build/src/nvim/auto/funcs.generated.h with definition of functions
|
|
|
|
static const array.
|
|
|
|
]])
|
|
|
|
os.exit(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
package.path = nvimsrcdir .. '/?.lua;' .. package.path
|
|
|
|
|
|
|
|
local funcsfname = autodir .. '/funcs.generated.h'
|
2016-01-01 04:37:20 -07:00
|
|
|
|
2016-06-19 07:41:08 -07:00
|
|
|
local gperfpipe = io.open(funcsfname .. '.gperf', 'wb')
|
2016-01-01 02:17:22 -07:00
|
|
|
|
2016-06-18 03:06:50 -07:00
|
|
|
local funcs = require('eval').funcs
|
|
|
|
local metadata = mpack.unpack(io.open(arg[3], 'rb'):read("*all"))
|
|
|
|
for i,fun in ipairs(metadata) do
|
2016-06-20 05:40:57 -07:00
|
|
|
if not fun.noeval then
|
2016-06-28 12:45:19 -07:00
|
|
|
funcs[fun.name] = {
|
2016-06-20 05:40:57 -07:00
|
|
|
args=#fun.parameters,
|
|
|
|
func='api_wrapper',
|
|
|
|
data='&handle_'..fun.name,
|
|
|
|
}
|
|
|
|
end
|
2016-06-18 03:06:50 -07:00
|
|
|
end
|
|
|
|
|
2016-06-19 07:41:08 -07:00
|
|
|
local funcsdata = io.open(funcs_file, 'w')
|
|
|
|
funcsdata:write(mpack.pack(funcs))
|
|
|
|
funcsdata:close()
|
|
|
|
|
|
|
|
gperfpipe:write([[
|
|
|
|
%language=ANSI-C
|
|
|
|
%global-table
|
2017-04-24 03:39:48 -07:00
|
|
|
%readonly-tables
|
2016-06-19 07:41:08 -07:00
|
|
|
%define initializer-suffix ,0,0,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;
|
|
|
|
%%
|
|
|
|
]])
|
2016-01-01 02:17:22 -07:00
|
|
|
|
2016-06-18 03:06:50 -07:00
|
|
|
for name, def in pairs(funcs) do
|
2016-01-01 04:37:20 -07:00
|
|
|
args = def.args or 0
|
|
|
|
if type(args) == 'number' then
|
|
|
|
args = {args, args}
|
|
|
|
elseif #args == 1 then
|
|
|
|
args[2] = 'MAX_FUNC_ARGS'
|
2016-01-01 02:17:22 -07:00
|
|
|
end
|
2016-01-01 04:37:20 -07:00
|
|
|
func = def.func or ('f_' .. name)
|
2016-06-18 03:06:50 -07:00
|
|
|
data = def.data or "NULL"
|
2016-06-19 07:41:08 -07:00
|
|
|
gperfpipe:write(('%s, %s, %s, &%s, (FunPtr)%s\n')
|
|
|
|
:format(name, args[1], args[2], func, data))
|
2016-01-01 02:17:22 -07:00
|
|
|
end
|
2016-06-19 07:41:08 -07:00
|
|
|
gperfpipe:close()
|