forked from leegao/LuaInLua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.lua
90 lines (84 loc) · 3.16 KB
/
hello.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-- local ll1 = require 'll1.ll1'
local parser = require 'lua.parser'
local utils = require 'common.utils'
local re = require 'parsing.re'
local undump = require 'bytecode.undump'
--print(config:pretty())
--print(utils.to_list(config:follow('block')))
--print(config:follows():dot())
--ll1.yacc(parser.grammar)
-- print(utils.to_list(config:get_dependency_graph().reverse['suffixedexp\'star#1']))
--print(utils.to_list(config:first('stat')))
--local seen = {['suffixedexp\'star#1'] = true}
--for node, _, forward, reverse in config:get_dependency_graph():reverse_dfs('suffixedexp\'star#1') do
-- if seen[node] then
-- print(node)
-- for rev, tag in pairs(reverse) do
-- for suffix in pairs(tag) do
-- local first = ll1.first(config, suffix)
-- if first[''] then
-- print('', rev, utils.to_string(suffix))
-- seen[rev] = true
-- end
-- if first['LBRACE'] or first['String'] or first['LBRACK'] or first['LPAREN'] then
-- if not first[''] then print('', rev, utils.to_string(suffix)) end
-- print('', '', utils.to_list(ll1.first(config, suffix)))
-- end
-- end
-- end
-- end
--end
--ll1.yacc(parser.grammar)
--local srcs = {}
--for line in io.lines 'lua/parser.lua' do
-- table.insert(srcs, line)
--end
--debug.sethook(
-- function(...)
-- local info = debug.getinfo(2)
-- local info2 = debug.getinfo(4)
-- if not info.name and info.short_src == './lua/parser.lua' and info2.short_src == './ll1/ll1.lua' then
-- -- print("call: " .. info.short_src .. ':' .. info.currentline .. ':')
-- local local_src = srcs[info.linedefined]
-- if local_src:sub(1, #'__GRAMMAR__.grammar["') == '__GRAMMAR__.grammar["' then
-- local _, index = debug.getlocal(4, 7)
-- local _, conf = debug.getlocal(4, 1)
-- local _, state = debug.getlocal(4, 3)
-- local production = conf.configuration[state][index]
-- print(utils.to_string(production))
-- print("call: " .. info.short_src .. ':' .. info.currentline .. ':', srcs[info.linedefined])
-- end
-- end
-- end,
-- "c")
local luac = require "luac"
local dump = require "bytecode.dump"
local undump = require "bytecode.undump"
--local prototype = undump.undump(function(...) print(...) end)
--for pc, op in ipairs(prototype.code) do
-- print(pc, op)
--end
--
--local foo, bytecode, prototype, dumper = luac "testing/hello_world.lua"
--dumper()
--foo()
local compiler, bytecode, prototype, dumper = luac "lua/compiler.lua"
-- dumper()
compiler = compiler()
local tree = parser(io.open("lua/compiler.lua", 'r'):read('*all'))
local prototype = compiler(tree)
local bytecode = dump.dump(prototype)
local compiler, err = loadstring(tostring(bytecode))
compiler = compiler()
local tree = parser(io.open("lua/compiler.lua", 'r'):read('*all'))
local prototype = compiler(tree)
local bytecode = dump.dump(prototype)
local compiler, err = loadstring(tostring(bytecode))
compiler = compiler()
local tree = parser(io.open("testing/hello_world.lua", 'r'):read('*all'))
local prototype = compiler(tree)
local bytecode = dump.dump(prototype)
local func, err = loadstring(tostring(bytecode))
func()
--local foo = luac "testing/hello_world.lua"
--foo()