@@ -258,16 +258,12 @@ local function resolve_replace(replace_map)
258258
259259 local function match_value (v )
260260 assert (v ~= nil )
261- if v == RECORD then
261+ if record_map [ v ] or is_sharedtable ( v ) then
262262 return
263263 end
264264
265265 local tv = type (v )
266266 local f = match [tv ]
267- if record_map [v ] or is_sharedtable (v ) then
268- return
269- end
270-
271267 if f then
272268 record_map [v ] = true
273269 f (v )
@@ -364,7 +360,7 @@ local function resolve_replace(replace_map)
364360 end
365361
366362 local level = info .level
367- local curco = info .curco or coroutine.running ()
363+ local curco = info .curco
368364 if not level then
369365 return
370366 end
@@ -390,7 +386,7 @@ local function resolve_replace(replace_map)
390386 end
391387
392388 local stack_values_tmp = {}
393- local function match_thread (co )
389+ local function match_thread (co , level )
394390 -- match stackvalues
395391 local n = stackvalues (co , stack_values_tmp )
396392 for i = 1 ,n do
@@ -399,40 +395,37 @@ local function resolve_replace(replace_map)
399395 match_value (v )
400396 end
401397
402- -- match callinfo
403- local level = 1
404- -- jump the fucntion from sharetable.update to top
405- local is_self = coroutine.running () == co
406- if is_self then
407- while true do
408- local info = getinfo (co , level , " uf" )
409- level = level + 1
410- if not info then
411- level = 1
412- break
413- elseif info .func == sharetable .update then
414- break
415- end
416- end
417- end
418-
398+ level = level or 1
419399 while true do
420400 local info = getinfo (co , level , " uf" )
421401 if not info then
422402 break
423403 end
424- info .level = is_self and level + 1 or level
404+ info .level = level
425405 info .curco = co
426406 match_funcinfo (info )
427407 level = level + 1
428408 end
429409 end
430410
411+ local function prepare_match ()
412+ local co = coroutine.running ()
413+ record_map [co ] = true
414+ record_map [match ] = true
415+ record_map [RECORD ] = true
416+ record_map [record_map ] = true
417+ record_map [insert_replace ] = true
418+ record_map [resolve_replace ] = true
419+ assert (getinfo (co , 3 , " f" ).func == sharetable .update )
420+ match_thread (co , 5 ) -- ignore match_thread and match_funcinfo frame
421+ end
422+
431423 match [" table" ] = match_table
432424 match [" function" ] = match_function
433425 match [" userdata" ] = match_userdata
434426 match [" thread" ] = match_thread
435427
428+ prepare_match ()
436429 match_internmt ()
437430
438431 local root = debug.getregistry ()
0 commit comments