-
Notifications
You must be signed in to change notification settings - Fork 1
/
consts.rb
113 lines (90 loc) · 2.04 KB
/
consts.rb
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
module Mlua
LUAI_MAXSHORTLEN = 40
LUA_TNIL = 0
LUA_TBOOLEAN = 1
LUA_TLIGHTUSERDATA = 2
LUA_TNUMBER = 3
LUA_TSTRING = 4
LUA_TTABLE = 5
LUA_TFUNCTION = 6
LUA_TUSERDATA = 7
LUA_TTHREAD = 8
LUA_NUMTAGS = 9
LUA_TSHRSTR = LUA_TSTRING | (0 << 4)
LUA_TLNGSTR = LUA_TSTRING | (1 << 4)
LUA_TNUMFLT = LUA_TNUMBER | (0 << 4)
LUA_TNUMINT = LUA_TNUMBER | (1 << 4)
OPCODE_DEFINE = <<EOT
OP_MOVE AB
OP_LOADK ABx
OP_LOADKX A
OP_LOADBOOL ABC
OP_LOADNIL AB
OP_GETUPVAL AB
OP_GETTABUP ABC
OP_GETTABLE ABC
OP_SETTABUP ABC
OP_SETUPVAL AB
OP_SETTABLE ABC
OP_NEWTABLE AB
OP_SELF ABC
OP_ADD ABC
OP_SUB ABC
OP_MUL ABC
OP_MOD ABC
OP_POW ABC
OP_DIV ABC
OP_IDIV ABC
OP_BAND ABC
OP_BOR ABC
OP_BXOR ABC
OP_SHL ABC
OP_SHR ABC
OP_UNM AB
OP_BNOT AB
OP_NOT AB
OP_LEN AB
OP_CONCAT ABC
OP_JMP AsBx
OP_EQ ABC
OP_LT ABC
OP_LE ABC
OP_TEST AC
OP_TESTSET ABC
OP_CALL ABC
OP_TAILCALL ABC
OP_RETURN AB
OP_FORLOOP AsBx
OP_FORPREP AsBx
OP_TFORCALL AC
OP_TFORLOOP AsBx
OP_SETLIST ABC
OP_CLOSURE ABx
OP_VARARG AB
OP_EXTRAARG Ax
EOT
OPCODE_TYPES = []
OPCODE_NAMES = []
OPCODE_DEFINE.split(/\n/).reject{|x|x.strip==""}.each.with_index do |opstr,i|
opname, optype = opstr.strip.split(/\s+/)
const_set opname, i
OPCODE_NAMES.push opname[3..-1]
OPCODE_TYPES.push optype.to_sym
end
def self.csharp_code
puts "public enum OpCode {"
OPCODE_NAMES.each.with_index do |opname,i|
puts " #{opname} = #{i},"
end
puts "}"
puts
puts "public class OpDatabase {"
puts " public static readonly OpInfo[] Data = new OpInfo[]{"
OPCODE_TYPES.each_with_index do |optype,i|
opname = OPCODE_NAMES[i]
puts " new OpInfo(\"#{opname}\", OpType.#{optype}),"
end
puts " };"
puts "}"
end
end