]> git.lizzy.rs Git - metalua.git/blob - src/samples/walk_id_test.mlua
walk_id_test sample fix
[metalua.git] / src / samples / walk_id_test.mlua
1 -{ extension 'match' }
2
3 require 'metalua.walk.id'
4
5 ast = +{ block:
6          y = type(1)
7          function foo(x)
8             local type = 'number'
9             assert(x==type or not x)
10          end
11          foo(x) }
12
13 disp = |msg,ast| printf("\n%s:\n%s", msg, table.tostring(ast, 80, 'nohash'))
14 disp('initial term', ast)
15
16 do -- Make globals explicit:
17    local ast = table.deep_copy(ast)
18    local cfg = { id = { } }
19    function cfg.id.free(i) 
20       i <- `Index{ `Id '_G', `String{i[1]} } 
21       return 'break'
22    end   
23    walk_id.block(cfg, ast)
24    disp('Globals made explicit', ast)
25 end
26