local cat_lp = luatexbase.catcodetables['latex-package']
--------------------
-luatexja.base = {}
+local ltjb = {}
+luatexja.base = ltjb
local public_name = 'luatexja'
local public_version = 'alpha'
-luatexja.base.public_name = public_name
-luatexja.base.public_version = public_version
+ltjb.public_name = public_name
+ltjb.public_version = public_version
-------------------- Fully-expandable error messaging
end
return tex.print(unpack(lines))
end
-luatexja.base.mprint = mprint
+ltjb.mprint = mprint
-------------------- Handling of TeX values
do
s.shrink or 0, s.shrink_order or 0))
end
- luatexja.base.to_dimen = to_dimen
- luatexja.base.dump_skip = dump_skip
- luatexja.base.to_skip = to_skip
+ ltjb.to_dimen = to_dimen
+ ltjb.dump_skip = dump_skip
+ ltjb.to_skip = to_skip
end
-------------------- Virtual table for LaTeX counters
function mt_counter.__newindex(tbl, key, val)
tex.count['c@'..key] = val
end
- luatexja.base.counter = counter
+ ltjb.counter = counter
--! ixbase.length は tex.skip と全く同じなので不要.
end
end)
end
- luatexja.base.scan_brace = scan_brace
- luatexja.base.scan_number = scan_number
+ ltjb.scan_brace = scan_brace
+ ltjb.scan_number = scan_number
end
-------------------- TeX register allocation
return token.create(name)[2] - cmod_base_skip
end
- luatexja.base.const_number = const_number
- luatexja.base.count_number = count_number
- luatexja.base.attribute_number = attribute_number
- luatexja.base.dimen_number = dimen_number
- luatexja.base.skip_number = skip_number
-end
-
--------------------- mock of debug logger
-if not debug or debug == _G.debug then
- local function no_op() end
- debug = no_op
- package_debug = no_op
- show_term = no_op
- show_log = no_op
- function debug_logger()
- return no_op
- end
+ ltjb.const_number = const_number
+ ltjb.count_number = count_number
+ ltjb.attribute_number = attribute_number
+ ltjb.dimen_number = dimen_number
+ ltjb.skip_number = skip_number
end
-------------------- getting next token
cstemp = token.csname_name(token.get_next())
tex.sprint(cat_lp,'\\' .. s)
end
-luatexja.base.get_cs = get_cs
+ltjb.get_cs = get_cs
-------------------- common error message
do
end
return c
end
- luatexja.base.in_unicode = in_unicode
+ ltjb.in_unicode = in_unicode
end
-------------------- cache management
end
end
- luatexja.base.load_cache = load_cache
- luatexja.base.save_cache_luc = save_cache_luc
- luatexja.base.save_cache = save_cache
+ ltjb.load_cache = load_cache
+ ltjb.save_cache_luc = save_cache_luc
+ ltjb.save_cache = save_cache
end
-luatexja.base._error_set_break = _error_set_break
-luatexja.base._error_set_message = _error_set_message
-luatexja.base._error_show = _error_show
-luatexja.base._generic_warn_info = _generic_warn_info
-
-luatexja.base.package_error = package_error
-luatexja.base.package_warning = package_warning
-luatexja.base.package_warning_no_line = package_warning_no_line
-luatexja.base.package_info = package_info
-luatexja.base.package_info_no_line = package_info_no_line
-
-luatexja.base.generic_error = generic_error
-luatexja.base.generic_warning = generic_warning
-luatexja.base.generic_warning_no_line = generic_warning_no_line
-luatexja.base.generic_info = generic_info
-luatexja.base.generic_info_no_line = generic_info_no_line
-
-luatexja.base.ltj_warning_no_line = ltj_warning_no_line
-luatexja.base.ltj_error = ltj_error
-
-luatexja.base.debug = debug
-luatexja.base.package_debug = package_debug
-luatexja.base.debug_logger = debug_logger
-luatexja.base.show_term = show_term
-luatexja.base.show_log = show_log
+ltjb._error_set_break = _error_set_break
+ltjb._error_set_message = _error_set_message
+ltjb._error_show = _error_show
+ltjb._generic_warn_info = _generic_warn_info
+
+ltjb.package_error = package_error
+ltjb.package_warning = package_warning
+ltjb.package_warning_no_line = package_warning_no_line
+ltjb.package_info = package_info
+ltjb.package_info_no_line = package_info_no_line
+
+ltjb.generic_error = generic_error
+ltjb.generic_warning = generic_warning
+ltjb.generic_warning_no_line = generic_warning_no_line
+ltjb.generic_info = generic_info
+ltjb.generic_info_no_line = generic_info_no_line
+
+ltjb.ltj_warning_no_line = ltj_warning_no_line
+ltjb.ltj_error = ltj_error
+
+-------------------- mock of debug logger
+if not ltjb.out_debug then
+ local function no_op() end
+ ltjb.start_time_measure = no_op
+ ltjb.stop_time_measure = no_op
+ ltjb.out_debug = no_op
+ ltjb.package_debug = no_op
+ ltjb.debug_logger = function() return no_op end
+ ltjb.show_term = no_op
+ ltjb.show_log = no_op
+end
-------------------- all done
-- EOF
--
-- luatexja/debug.lua
--
-luatexbase.provides_module({
- name = 'luatexja.debug',
- date = '2011/05/14',
- description = '',
-})
-module('luatexja.debug', package.seeall)
-local err, warn, info, log = luatexbase.errwarinf(_NAME)
-
-local table = table
+local ltjdbg = {}
+luatexja.debug = ltjdbg
+local table, string = table, string
-------------------- pretty-print
return ret
end
-function table_tosource(t)
+local function table_tosource(t)
if not next(t) then return "{}" end
local res_n = "\127"..normal_serialize({t}).."\127"
local s, e, cap = res_n:find("\127{\n ({ .* }),\n}\127")
else return normal_serialize(t)
end
end
+ltjdbg.table_tosource = table_tosource
-function function_tosource(f)
+local function function_tosource(f)
local res = normal_serialize({f})
return res:sub(4, res:len() - 3)
end
+ltjdbg.function_tosource = function_tosource
--! 値 v をそれを表すソース文字列に変換する.
--! lualibs の table.serialize() の処理を利用している.
-function tosource(v)
+local function tosource(v)
local tv = type(v)
if tv == "function" then return function_tosource(v)
elseif tv == "table" then return table_tosource(v)
else return tostring(v)
end
end
+ltjdbg.tosource = tosource
local function coerce(f, v)
if f == "q" then return "s", tosource(v)
--! - %q は全ての型について tosource() に変換
--! - <%> の代わりに <`> も使える (TeX での使用のため)
--! - %d, %s 等でキャストを行う
-function pformat(fmt, ...)
+local function pformat(fmt, ...)
if type(fmt) == "string" then
return do_pformat(fmt, ...)
else
return tosource(fmt)
end
end
+ltjdbg.pformat = pformat
+
+-------------------- 所要時間合計
+require("socket")
+do
+ local gettime = socket.gettime
+ local time_stat = {}
+ local function start_time_measure(n)
+ if not time_stat[n] then
+ time_stat[n] = {1, -gettime()}
+ else
+ local t = time_stat[n]
+ t[1], t[2] = t[1]+1, t[2]-gettime()
+ end
+ end
+ local function stop_time_measure(n)
+ local t = time_stat[n]
+ t[2] = t[2] + gettime()
+ end
+
+ local function print_measure()
+ for i,v in pairs(time_stat) do
+ print (i, tostring(v[1]) .. ' times', tostring(v[2]) .. ' sec.')
+ end
+ end
+ if luatexja.base then
+ luatexja.base.start_time_measure = start_time_measure
+ luatexja.base.stop_time_measure = stop_time_measure
+ luatexbase.add_to_callback('stop_run', print_measure, 'luatexja.time_measure', 1)
+ luatexbase.add_to_callback('pre_linebreak_filter',
+ function(p)
+ start_time_measure('tex_linebreak'); return p
+ end,
+ 'measure_tex_linebreak', 20000)
+ end
+end
-------------------- debug logging
-
+do
local debug_show_term = true
local debug_show_log = true
--! デバッグログを端末に出力するか
-function show_term(v)
+local function show_term(v)
debug_show_term = v
end
+ltjdbg.show_term = show_term
--! デバッグログをログファイルに出力するか
function show_log(v)
debug_show_log = v
end
+ltjdbg.show_log = show_log
local function write_debug_log(s)
local target
end
--! デバッグログ出力. 引数は pformat() と同じ.
-function debug(...)
+local function out_debug(...)
if debug_show_term or debug_show_log then
write_debug_log("%DEBUG:"..pformat(...))
end
end
--! デバッグログ出力, パッケージ名付き.
-function package_debug(pkg, ...)
+local function package_debug(pkg, ...)
if debug_show_term or debug_show_log then
write_debug_log("%DEBUG("..pkg.."):"..pformat(...))
end
end
--! パッケージ名付きデバッグログ出力器を得る.
-function debug_logger(pkg)
+local function debug_logger(pkg)
return function(...) package_debug(pkg, ...) end
end
if luatexja.base then
- luatexja.base.debug = debug
+ luatexja.base.out_debug = out_debug
luatexja.base.package_debug = package_debug
luatexja.base.debug_logger = debug_logger
luatexja.base.show_term = show_term
luatexja.base.show_log = show_log
end
+end
-------------------- all done
-- EOF
local node_remove = Dnode.remove
local node_next = (Dnode ~= node) and Dnode.getnext or node.next
local traverse_id = Dnode.traverse_id
+local start_time_measure, stop_time_measure
+ = ltjb.start_time_measure, ltjb.stop_time_measure
local id_kern = node.id('kern')
local id_hlist = node.id('hlist')
end
end
luatexbase.add_to_callback('hpack_filter', set_dir_flag, 'ltj.set_dir_flag', 10000)
-
local function set_dir_flag_vbox(h, gc)
local w = to_direct(h)
ltjs.list_dir = get_dir_count()
if getid(w)==id_whatsit and getsubtype(w)==sid_user
and getfield(w, 'user_id')==wh_DIR then
ltjs.list_dir = getfield(w, 'value')
- --print('VB', gc, ltjs.list_dir)
- --luatexja.ext_show_node_list(h, ' > ', print)
return h
else
- --print('VB', gc, ltjs.list_dir)
- --luatexja.ext_show_node_list(h, ' > ', print)
return set_dir_flag(h, gc)
end
end
luatexbase.add_to_callback('vpack_filter', set_dir_flag_vbox, 'ltj.set_dir_flag', 1)
luatexbase.add_to_callback('post_linebreak_filter',
function (h)
+ stop_time_measure('tex_linebreak')
+ -- start 側は ltj-debug.lua に
local new_dir = ltjs.list_dir
for line in traverse_id(id_hlist, to_direct(h)) do
set_attr(line, attr_dir, new_dir)
local bh = getlist(b)
local dir
for x in traverse_id(id_whatsit, bh) do
- if getsubtype(bh)==sid_user and getfield(bh, 'user_id')==wh_DIR then
+ if getsubtype(x)==sid_user and getfield(x, 'user_id')==wh_DIR then
setfield(b, 'head', (node_remove(bh, x)))
dir = getfield(bh, 'value')
set_attr(b, attr_dir, dir)
end
luatexja.direction.clean_dir_whatsit = clean_dir_whatsit
make_dir_node = function (head, b, new_dir, origin)
+
-- head: list head, b: box
-- origin: コール元 (for debug)
-- return value: (new head), (next of b), (new b), (is_b_dir_node)
-- (new b): b か dir_node に被せられた b
- local old_dir
+ local old_dir = has_attr(b, attr_dir) or 0
local bh = getlist(b)
- for x in traverse_id(id_whatsit, bh) do
+ if old_dir ==0 then
if getsubtype(bh)==sid_user and getfield(bh, 'user_id')==wh_DIR then
- old_dir = getfield(bh, 'value')
- set_attr(b, attr_dir, old_dir)
- setfield(b, 'head', (node_remove(bh, x)))
- node_free(x); break
+ old_dir = getfield(bh, 'value')
+ set_attr(b, attr_dir, old_dir)
+ setfield(b, 'head', (node_remove(bh, bh)))
end
- end
- if not old_dir then
- old_dir = has_attr(b, attr_dir) or 0
- if old_dir ==0 then
- old_dir = ltjs.list_dir
- end
+ if old_dir ==0 then old_dir = ltjs.list_dir end
end
if old_dir==new_dir then
- set_attr(b, attr_icflag, PROCESSED)
return head, node_next(b), b, false
elseif -old_dir == new_dir then
return head, node_next(b), b, true
end
end
local function process_dir_node(head, gc)
+ start_time_measure('direction_vpack')
local h = to_direct(head)
local x, new_dir = h, ltjs.list_dir or dir_yoko
while x do
x = node_next(x)
end
end
+ stop_time_measure('direction_vpack')
return to_node(h)
end
luatexja.direction.make_dir_node = make_dir_node
luatexbase.add_to_callback('vpack_filter',
process_dir_node, 'ltj.dir_node', 10001)
+
end
-- luatexja/ltj-inputbuf.lua
--
+luatexja.load_module('base'); local ltjb = luatexja.base
luatexja.load_module('charrange'); local ltjc = luatexja.charrange
require("unicode")
--- the following function is modified from jafontspec.lua (by K. Maeda).
--- Instead of "%", we use U+FFFFF for suppressing spaces.
+--DEBUG require"socket"
+local time_line = 0
+local start_time_measure, stop_time_measure
+ = ltjb.start_time_measure, ltjb.stop_time_measure
local function add_comment(buffer)
+ start_time_measure('inputbuf')
local i = utflen(buffer)
while (i>0) and (getcatcode(utfbyte(buffer, i))==1
or getcatcode(utfbyte(buffer, i))==2) do
end
end
end
+ stop_time_measure('inputbuf')
return buffer
end
luatexbase.add_to_callback('process_input_buffer',
add_comment,'ltj.process_input_buffer')
+ luatexbase.add_to_callback('stop_run', function()
+ print(time_line)
+ end, 'adjust_icflag', 1)
+
--EOF
[id_hlist] = function(lp)
local op, flag
head, lp, op, flag = ltjd_make_dir_node(head, lp, list_dir, 'jfm hlist')
+ set_attr(op, attr_icflag, PROCESSED)
Np.first = Np.first or op; Np.last = op; Np.nuc = op;
Np.id = (flag or getfield(op, 'shift')~=0) and id_box_like or id_hlist
return true, lp
-- luatexja/ltj-pretreat.lua
--
+luatexja.load_module('base'); local ltjb = luatexja.base
luatexja.load_module('charrange'); local ltjc = luatexja.charrange
luatexja.load_module('stack'); local ltjs = luatexja.stack
luatexja.load_module('jfont'); local ltjf = luatexja.jfont
------------------------------------------------------------------------
local wt
do
+ local start_time_measure, stop_time_measure
+ = ltjb.start_time_measure, ltjb.stop_time_measure
local head
local is_dir_tate
local dir_frozen
end
local function suppress_hyphenate_ja (h)
+ start_time_measure('ltj_hyphenate')
local p = to_direct(h)
wt, head, dir_frozen = {}, p, false
ltjs.list_dir=ltjd.get_dir_count()
p = node_next(p)
end
head = to_node(head)
+ stop_time_measure('ltj_hyphenate'); start_time_measure('tex_hyphenate')
lang.hyphenate(head)
+ stop_time_measure('tex_hyphenate')
return head
end
end
+--load_module('debug')
+
load_module('charrange'); local ltjc = luatexja.charrange
load_module('jfont'); local ltjf = luatexja.jfont
load_module('inputbuf'); local ltji = luatexja.inputbuf
-- main process
do
+ local start_time_measure, stop_time_measure
+ = ltjb.start_time_measure, ltjb.stop_time_measure
local Dnode = node.direct or node
local nullfunc = function (n) return n end
local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
+ local time_jfm, time_width = 0,0
-- mode = true iff main_process is called from pre_linebreak_filter
local function main_process(head, mode, dir, gc)
tex.setattribute('global', attr_icflag, 0)
if gc == 'fin_row' then return head
else
local p = to_direct(head)
+ start_time_measure('jfmglue')
p = ltjj.main(p,mode)
+ stop_time_measure('jfmglue'); start_time_measure('setwidth')
if p then p = ltjw.set_ja_width(p, dir) end
+ stop_time_measure('setwidth')
return to_node(p)
end
end