This commit is contained in:
nganhkhoa 2021-05-17 21:15:40 +07:00
commit d19381964f
9 changed files with 277668 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

194
Cargo.lock generated Normal file
View File

@ -0,0 +1,194 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bytecount"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be0fdd54b507df8f22012890aadd099979befdba27713c767993f8380112ca7c"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "derive_more"
version = "0.99.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f82b1b72f1263f214c0f823371768776c4f5841b942c9883aa8e5ec584fd0ba6"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "full_moon"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e72478a3684da256f0affc9c56e57609716099e0a4c7792a22ff1bc7ae957ba8"
dependencies = [
"bytecount",
"cfg-if",
"derive_more",
"full_moon_derive",
"paste",
"peg",
"serde",
]
[[package]]
name = "full_moon_derive"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcca58f0025a2a265296475b86101d16cc3e3ca284528aa39edd738e6d896449"
dependencies = [
"indexmap",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "indexmap"
version = "1.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "optimize"
version = "0.1.0"
dependencies = [
"full_moon",
]
[[package]]
name = "paste"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880"
dependencies = [
"paste-impl",
"proc-macro-hack",
]
[[package]]
name = "paste-impl"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6"
dependencies = [
"proc-macro-hack",
]
[[package]]
name = "peg"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07c0b841ea54f523f7aa556956fbd293bcbe06f2e67d2eb732b7278aaf1d166a"
dependencies = [
"peg-macros",
"peg-runtime",
]
[[package]]
name = "peg-macros"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aa52829b8decbef693af90202711348ab001456803ba2a98eb4ec8fb70844c"
dependencies = [
"peg-runtime",
"proc-macro2",
"quote",
]
[[package]]
name = "peg-runtime"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c719dcf55f09a3a7e764c6649ab594c18a177e3599c467983cdf644bfc0a4088"
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro2"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "optimize"
version = "0.1.0"
authors = ["nganhkhoa <mail.nganhkhoa@gmail.com>"]
edition = "2018"
[dependencies]
full_moon = { version = "0.11.0", features = ["lua52"] }

276587
main_android_org.lua Normal file

File diff suppressed because it is too large Load Diff

625
small.lua Normal file
View File

@ -0,0 +1,625 @@
local L0_1, L1_1, L2_1, L3_1, L4_1, L5_1, L6_1, L7_1, L8_1, L9_1, L10_1, L11_1, L12_1, L13_1, L14_1, L15_1, L16_1, L17_1, L18_1, L19_1, L20_1, L21_1, L22_1, L23_1, L24_1, L25_1, L26_1, L27_1, L28_1, L29_1, L30_1, L31_1, L32_1, L33_1, L34_1, L35_1, L36_1, L37_1, L38_1, L39_1, L40_1, L41_1, L42_1, L43_1, L44_1, L45_1, L46_1, L47_1, L48_1, L49_1, L50_1, L51_1, L52_1, L53_1, L54_1, L55_1, L56_1, L57_1, L58_1, L59_1, L60_1, L61_1, L62_1, L63_1, L64_1, L65_1, L66_1, L67_1, L68_1, L69_1, L70_1, L71_1, L72_1, L73_1, L74_1, L75_1, L76_1, L77_1, L78_1, L79_1, L80_1, L81_1, L82_1, L83_1, L84_1, L85_1, L86_1, L87_1, L88_1, L89_1, L90_1, L91_1, L92_1, L93_1, L94_1, L95_1, L96_1, L97_1, L98_1, L99_1, L100_1, L101_1, L102_1, L103_1, L104_1, L105_1, L106_1, L107_1, L108_1, L109_1, L110_1, L111_1, L112_1, L113_1, L114_1, L115_1, L116_1, L117_1, L118_1, L119_1, L120_1, L121_1, L122_1, L123_1, L124_1, L125_1, L126_1, L127_1, L128_1, L129_1, L130_1, L131_1, L132_1, L133_1, L134_1, L135_1, L136_1, L137_1, L138_1, L139_1, L140_1, L141_1, L142_1, L143_1, L144_1, L145_1, L146_1, L147_1, L148_1, L149_1, L150_1, L151_1, L152_1, L153_1, L154_1, L155_1, L156_1, L157_1, L158_1, L159_1, L160_1, L161_1, L162_1, L163_1, L164_1, L165_1, L166_1, L167_1, L168_1, L169_1, L170_1, L171_1, L172_1, L173_1, L174_1, L175_1, L176_1, L177_1, L178_1, L179_1, L180_1, L181_1, L182_1, L183_1, L184_1, L185_1, L186_1, L187_1, L188_1, L189_1, L190_1, L191_1, L192_1, L193_1, L194_1, L195_1, L196_1, L197_1, L198_1, L199_1, L200_1, L201_1, L202_1, L203_1, L204_1, L205_1, L206_1, L207_1, L208_1, L209_1, L210_1, L211_1, L212_1, L213_1, L214_1, L215_1, L216_1, L217_1, L218_1, L219_1, L220_1, L221_1, L222_1, L223_1, L224_1, L225_1, L226_1, L227_1, L228_1, L229_1, L230_1
L1_1 = math
L1_1 = L1_1.fmod
L2_1 = math
L2_1 = L2_1.max
L3_1 = math
L3_1 = L3_1.min
L4_1 = math
L4_1 = L4_1.floor
L5_1 = math
L5_1 = L5_1.ceil
L6_1 = math
L6_1 = L6_1.random
L7_1 = string
L7_1 = L7_1.len
L8_1 = string
L8_1 = L8_1.char
L9_1 = string
L9_1 = L9_1.byte
L10_1 = string
L10_1 = L10_1.sub
L11_1 = string
L11_1 = L11_1.upper
L12_1 = string
L12_1 = L12_1.format
L13_1 = string
L13_1 = L13_1.len
L14_1 = string
L14_1 = L14_1.gsub
function L15_1(A0_2)
local L1_2
L1_2 = #A0_2
return L1_2
end
function L16_1(A0_2, A1_2)
end
L17_1 = table
L17_1 = L17_1.insert
L18_1 = unpack
L19_1 = bit
L19_1 = L19_1.band
L20_1 = bit
L20_1 = L20_1.bor
L21_1 = bit
L21_1 = L21_1.bxor
L22_1 = bit
L22_1 = L22_1.rshift
L23_1 = bit
L23_1 = L23_1.lshift
function L24_1(A0_2, A1_2)
local L2_2, L3_2
L2_2 = A0_2[A1_2]
if L2_2 == nil then
L3_2 = 0
return L3_2
end
return L2_2
end
function L25_1(A0_2)
local L1_2, L2_2, L3_2, L4_2
L1_2 = L15_1
L2_2 = A0_2
L1_2 = (L1_2(L2_2))
while 1 < L1_2 do
L2_2 = A0_2[L1_2]
if L2_2 ~= 0 then
break
end
A0_2[L1_2] = nil
L1_2 = L1_2 - 1
end
L2_2 = L16_1
L3_2 = A0_2
L4_2 = L1_2
L2_2(L3_2, L4_2)
end
function L26_1(A0_2)
local L1_2, L2_2
if -1 < A0_2 and A0_2 < 10 then
L1_2 = L8_1
L2_2 = 48 + A0_2
return L1_2(L2_2)
end
if 9 < A0_2 and A0_2 < 16 then
L1_2 = L8_1
L2_2 = 55 + A0_2
return L1_2(L2_2)
end
L1_2 = L8_1
L2_2 = 48
return L1_2(L2_2)
end
function L27_1(A0_2)
local L1_2
if A0_2 == nil then
L1_2 = 0
return L1_2
end
if 47 < A0_2 and A0_2 < 58 then
L1_2 = A0_2 - 48
return L1_2
end
if 64 < A0_2 and A0_2 < 71 then
L1_2 = A0_2 - 55
return L1_2
end
if 96 < A0_2 and A0_2 < 103 then
L1_2 = A0_2 - 87
return L1_2
end
L1_2 = 0
return L1_2
end
function L28_1(A0_2)
local L1_2, L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2, L14_2, L15_2, L16_2
L1_2 = ""
L2_2 = nil
L3_2 = nil
L4_2 = nil
L5_2 = 1
L6_2 = L15_1
L7_2 = A0_2
L6_2 = (L6_2(L7_2))
L7_2 = 1
for L8_2 = L5_2, L6_2, L7_2 do
L4_2 = A0_2[L8_2]
L9_2 = 1
L10_2 = 6
L11_2 = 1
for L12_2 = L9_2, L10_2, L11_2 do
L13_2 = L26_1
L14_2 = L1_1
L15_2 = L4_2
L16_2 = 16
L14_2, L15_2, L16_2 = L14_2(L15_2, L16_2)
L13_2 = (L13_2(L14_2, L15_2, L16_2))
L14_2 = L1_2
L1_2 = L13_2 .. L14_2
L13_2 = L4_1
L14_2 = L4_2 / 16
L13_2 = (L13_2(L14_2))
L4_2 = L13_2
end
end
L2_2 = 1
while true do
L5_2 = L13_1
L6_2 = L1_2
L5_2 = (L5_2(L6_2))
if not (L2_2 < L5_2) then
break
end
L5_2 = L9_1
L6_2 = L1_2
L7_2 = L2_2
L5_2 = (L5_2(L6_2, L7_2))
if L5_2 ~= 48 then
break
end
L2_2 = L2_2 + 1
end
L5_2 = L10_1
L6_2 = L1_2
L7_2 = L2_2
return L5_2(L6_2, L7_2)
end
function L29_1(A0_2)
local L1_2, L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2, L14_2, L15_2, L16_2, L17_2, L18_2
L1_2 = {}
L2_2 = nil
L3_2 = nil
L4_2 = 1
L5_2 = L5_1
L6_2 = L13_1
L7_2 = A0_2
L6_2 = (L6_2(L7_2))
L6_2 = L6_2 / 6
L5_2 = (L5_2(L6_2))
L6_2 = 1
for L7_2 = L4_2, L5_2, L6_2 do
L1_2[L7_2] = 0
L8_2 = 1
L9_2 = 6
L10_2 = 1
for L11_2 = L8_2, L9_2, L10_2 do
L12_2 = L1_2[L7_2]
L12_2 = 16 * L12_2
L13_2 = L27_1
L14_2 = L9_1
L15_2 = A0_2
L16_2 = L2_1
L17_2 = L13_1
L18_2 = A0_2
L17_2 = (L17_2(L18_2))
L18_2 = 6 * L7_2
L17_2 = L17_2 - L18_2
L17_2 = L17_2 + L11_2
L18_2 = 0
L16_2, L17_2, L18_2 = L16_2(L17_2, L18_2)
L14_2, L15_2, L16_2, L17_2, L18_2 = L14_2(L15_2, L16_2, L17_2, L18_2)
L13_2 = (L13_2(L14_2, L15_2, L16_2, L17_2, L18_2))
L12_2 = L12_2 + L13_2
L1_2[L7_2] = L12_2
end
end
L4_2 = L25_1
L5_2 = L1_2
L4_2(L5_2)
return L1_2
end
function L30_1(A0_2, A1_2)
local L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2
L2_2 = {}
L3_2 = L2_1
L4_2 = L15_1
L5_2 = A0_2
L4_2 = (L4_2(L5_2))
L5_2 = L15_1
L6_2 = A1_2
L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2 = L5_2(L6_2)
L3_2, L4_2, L5_2 = L3_2(L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2)
L2_2[1] = 0
L6_2 = 1
L7_2 = L3_2
L8_2 = 1
for L9_2 = L6_2, L7_2, L8_2 do
L10_2 = L24_1
L11_2 = A0_2
L12_2 = L9_2
L10_2 = (L10_2(L11_2, L12_2))
L11_2 = L24_1
L12_2 = A1_2
L13_2 = L9_2
L11_2 = (L11_2(L12_2, L13_2))
L10_2 = L10_2 + L11_2
L11_2 = L2_2[L9_2]
L5_2 = L10_2 + L11_2
if 16777215 < L5_2 then
L10_2 = L5_2 - 16777216
L2_2[L9_2] = L10_2
L10_2 = L9_2 + 1
L2_2[L10_2] = 1
else
L2_2[L9_2] = L5_2
L10_2 = L9_2 + 1
L2_2[L10_2] = 0
end
end
L6_2 = L25_1
L7_2 = L2_2
L6_2(L7_2)
return L2_2
end
function L31_1(A0_2, A1_2)
local L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2
L2_2 = {}
L3_2 = L2_1
L4_2 = L15_1
L5_2 = A0_2
L4_2 = (L4_2(L5_2))
L5_2 = L15_1
L6_2 = A1_2
L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2 = L5_2(L6_2)
L3_2, L4_2, L5_2 = L3_2(L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2)
L2_2[1] = 0
L6_2 = 1
L7_2 = L3_2
L8_2 = 1
for L9_2 = L6_2, L7_2, L8_2 do
L10_2 = L24_1
L11_2 = A0_2
L12_2 = L9_2
L10_2 = (L10_2(L11_2, L12_2))
L11_2 = L24_1
L12_2 = A1_2
L13_2 = L9_2
L11_2 = (L11_2(L12_2, L13_2))
L10_2 = L10_2 - L11_2
L11_2 = L2_2[L9_2]
L5_2 = L10_2 - L11_2
if L5_2 < 0 then
L10_2 = L5_2 + 16777216
L2_2[L9_2] = L10_2
L10_2 = L9_2 + 1
L2_2[L10_2] = 1
else
L2_2[L9_2] = L5_2
L10_2 = L9_2 + 1
L2_2[L10_2] = 0
end
end
L6_2 = L3_2 + 1
L6_2 = L2_2[L6_2]
if L6_2 == 1 then
L6_2 = nil
return L6_2
end
L6_2 = L25_1
L7_2 = L2_2
L6_2(L7_2)
return L2_2
end
function L32_1(A0_2, A1_2)
local L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2, L14_2, L15_2, L16_2, L17_2
L2_2 = {}
L3_2 = {}
L4_2 = nil
L5_2 = nil
L6_2 = nil
L7_2 = L15_1
L8_2 = A1_2
L7_2 = (L7_2(L8_2))
L8_2 = 1
L9_2 = -1
for L10_2 = L7_2, L8_2, L9_2 do
L3_2[1] = 0
L11_2 = 1
L12_2 = L15_1
L13_2 = A0_2
L12_2 = (L12_2(L13_2))
L13_2 = 1
for L14_2 = L11_2, L12_2, L13_2 do
L15_2 = A0_2[L14_2]
L16_2 = A1_2[L10_2]
L15_2 = L15_2 * L16_2
L16_2 = L3_2[L14_2]
L6_2 = L15_2 + L16_2
L15_2 = L14_2 + 1
L16_2 = L4_1
L17_2 = L6_2 / 16777216
L16_2 = (L16_2(L17_2))
L3_2[L15_2] = L16_2
L15_2 = L14_2 + 1
L15_2 = L3_2[L15_2]
L15_2 = L15_2 * 16777216
L15_2 = L6_2 - L15_2
L3_2[L14_2] = L15_2
end
L11_2 = L17_1
L12_2 = L2_2
L13_2 = 1
L14_2 = 0
L11_2(L12_2, L13_2, L14_2)
L11_2 = L30_1
L12_2 = L2_2
L13_2 = L3_2
L11_2 = (L11_2(L12_2, L13_2))
L2_2 = L11_2
end
L7_2 = L25_1
L8_2 = L2_2
L7_2(L8_2)
return L2_2
end
function L33_1(A0_2)
local L1_2, L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2
L1_2 = 0
L2_2 = nil
L3_2 = nil
L4_2 = L15_1
L5_2 = A0_2
L4_2 = (L4_2(L5_2))
L5_2 = 1
L6_2 = -1
for L7_2 = L4_2, L5_2, L6_2 do
L2_2 = A0_2[L7_2]
if L1_2 == 1 then
L8_2 = L4_1
L9_2 = L2_2 / 2
L8_2 = (L8_2(L9_2))
L8_2 = L8_2 + 8388608
A0_2[L7_2] = L8_2
else
L8_2 = L4_1
L9_2 = L2_2 / 2
L8_2 = (L8_2(L9_2))
A0_2[L7_2] = L8_2
end
L8_2 = L1_1
L9_2 = L2_2
L10_2 = 2
L8_2 = (L8_2(L9_2, L10_2))
L1_2 = L8_2
end
L4_2 = L25_1
L5_2 = A0_2
L4_2(L5_2)
return L1_2
end
function L34_1(A0_2, A1_2)
local L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2
L2_2 = {}
L3_2 = 0
L4_2 = nil
L5_2 = nil
L6_2 = nil
L6_2 = 16777216
L7_2 = 1
L8_2 = L15_1
L9_2 = A1_2
L8_2 = (L8_2(L9_2))
L9_2 = 1
for L10_2 = L7_2, L8_2, L9_2 do
L11_2 = L10_2 + 1
L12_2 = A1_2[L10_2]
L2_2[L11_2] = L12_2
end
L2_2[1] = 0
L7_2 = 23
L8_2 = 0
L9_2 = -1
for L10_2 = L7_2, L8_2, L9_2 do
L6_2 = L6_2 / 2
L11_2 = L33_1
L12_2 = L2_2
L11_2(L12_2)
L11_2 = L31_1
L12_2 = A0_2
L13_2 = L2_2
L11_2 = (L11_2(L12_2, L13_2))
L4_2 = L11_2
if L4_2 ~= nil then
L3_2 = L3_2 + L6_2
A0_2 = L4_2
end
end
L7_2 = L3_2
L8_2 = A0_2
return L7_2, L8_2
end
function L35_1(A0_2, A1_2)
local L2_2, L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2, L11_2, L12_2, L13_2
L2_2 = {}
L3_2 = {}
L4_2 = L15_1
L5_2 = A0_2
L4_2, L5_2 = L4_2(L5_2)
L6_2 = 1
L7_2 = L3_1
L8_2 = L15_1
L9_2 = A0_2
L8_2 = (L8_2(L9_2))
L9_2 = L15_1
L10_2 = A1_2
L9_2, L10_2, L11_2, L12_2, L13_2 = L9_2(L10_2)
L7_2 = (L7_2(L8_2, L9_2, L10_2, L11_2, L12_2, L13_2))
L7_2 = L7_2 - 1
L8_2 = 1
for L9_2 = L6_2, L7_2, L8_2 do
L10_2 = L17_1
L11_2 = L3_2
L12_2 = 1
L13_2 = A0_2[L4_2]
L10_2(L11_2, L12_2, L13_2)
L4_2 = L4_2 - 1
end
while 0 < L4_2 do
L6_2 = L17_1
L7_2 = L3_2
L8_2 = 1
L9_2 = A0_2[L4_2]
L6_2(L7_2, L8_2, L9_2)
L4_2 = L4_2 - 1
L6_2 = L34_1
L7_2 = L3_2
L8_2 = A1_2
L6_2, L7_2 = L6_2(L7_2, L8_2)
L3_2 = L7_2
L5_2 = L6_2
L6_2 = L17_1
L7_2 = L2_2
L8_2 = 1
L9_2 = L5_2
L6_2(L7_2, L8_2, L9_2)
end
L6_2 = L25_1
L7_2 = L2_2
L6_2(L7_2)
L6_2 = L2_2
L7_2 = L3_2
return L6_2, L7_2
end
function L36_1(A0_2, A1_2, A2_2)
local L3_2, L4_2, L5_2, L6_2, L7_2, L8_2, L9_2, L10_2
L3_2 = {}
L4_2 = {}
L5_2 = 1
L4_2[1] = L5_2
L5_2 = nil
L6_2 = 1
L7_2 = L15_1
L8_2 = A1_2
L7_2 = (L7_2(L8_2))
L8_2 = 1
for L9_2 = L6_2, L7_2, L8_2 do
L10_2 = A1_2[L9_2]
L3_2[L9_2] = L10_2
end
repeat
repeat
L6_2 = L33_1
L7_2 = L3_2
L6_2 = (L6_2(L7_2))
L5_2 = L6_2
if L5_2 == 1 then
L6_2 = L35_1
L7_2 = L32_1
L8_2 = L4_2
L9_2 = A0_2
L7_2 = (L7_2(L8_2, L9_2))
L8_2 = A2_2
L6_2, L7_2 = L6_2(L7_2, L8_2)
L4_2 = L7_2
L5_2 = L6_2
end
L6_2 = L35_1
L7_2 = L32_1
L8_2 = A0_2
L9_2 = A0_2
L7_2 = (L7_2(L8_2, L9_2))
L8_2 = A2_2
L6_2, L7_2 = L6_2(L7_2, L8_2)
A0_2 = L7_2
L5_2 = L6_2
L6_2 = L15_1
L7_2 = L3_2
L6_2 = (L6_2(L7_2))
until L6_2 == 1
L6_2 = L3_2[1]
until L6_2 == 0
return L4_2
end
function L37_1(...)
local L1_2, L2_2, L3_2, L4_2, L5_2, L6_2, L7_2
function L1_2(A0_3, ...)
local L2_3, L3_3, L4_3, L5_3
if not A0_3 then
else
L2_3 = L2_2
L3_3 = A0_3
L4_3 = L18_1
L5_3 = arg
L4_3, L5_3 = L4_3(L5_3)
return L2_3(L3_3, L4_3, L5_3)
end
end
function L2_2(A0_3, ...)
local L2_3, L3_3, L4_3, L5_3
if A0_3 < 6 then
L2_3 = L1_2
L3_3 = A0_3 + 1
L4_3 = L18_1
L5_3 = arg
L4_3, L5_3 = L4_3(L5_3)
return L2_3(L3_3, L4_3, L5_3)
else
L2_3 = L3_2
L3_3 = 3
L4_3 = L18_1
L5_3 = arg
L4_3, L5_3 = L4_3(L5_3)
return L2_3(L3_3, L4_3, L5_3)
end
end
function L3_2(A0_3, ...)
local L2_3, L3_3, L4_3, L5_3, L6_3, L7_3, L8_3, L9_3, L10_3, L11_3
L2_3 = fa
if L2_3 then
elseif A0_3 ~= 3 then
L2_3 = L2_2
L3_3 = A0_3 + 1
L4_3 = L18_1
L5_3 = arg
L4_3, L5_3, L6_3, L7_3, L8_3, L9_3, L10_3, L11_3 = L4_3(L5_3)
L2_3(L3_3, L4_3, L5_3, L6_3, L7_3, L8_3, L9_3, L10_3, L11_3)
else
L2_3 = {}
L3_3 = 1
L4_3 = #arg
L5_3 = 1
for L6_3 = L3_3, L4_3, L5_3 do
L7_3 = arg[L6_3]
if 1 < L6_3 then
L8_3 = L21_1
L9_3 = L21_1
L10_3 = arg[L6_3]
L11_3 = L6_3 - 1
L11_3 = arg[L11_3]
L9_3 = (L9_3(L10_3, L11_3))
L10_3 = L6_3 - 1
L10_3 = arg[L10_3]
L10_3 = L6_3 * L10_3
L10_3 = L10_3 % 256
L8_3 = (L8_3(L9_3, L10_3))
L7_3 = L8_3
L8_3 = table
L8_3 = L8_3.insert
L9_3 = L2_3
L10_3 = L8_1
L11_3 = L7_3
L10_3, L11_3 = L10_3(L11_3)
L8_3(L9_3, L10_3, L11_3)
else
L8_3 = L21_1
L9_3 = arg[L6_3]
L10_3 = #arg
L10_3 = L10_3 * 68
L10_3 = L10_3 % 256
L8_3 = (L8_3(L9_3, L10_3))
L7_3 = L8_3
end
end
L3_3 = table
L3_3 = L3_3.concat
L4_3 = L2_3
return L3_3(L4_3)
end
end
L4_2 = L1_2
L5_2 = 1
L6_2 = L18_1
L7_2 = arg
L6_2, L7_2 = L6_2(L7_2)
return L4_2(L5_2, L6_2, L7_2)
end

50
src/main.rs Normal file
View File

@ -0,0 +1,50 @@
mod visitor;
use std::fs;
use full_moon::parse;
use visitor::Visitor;
use visitor::ConstantFolder;
fn main() {
// let contents = fs::read_to_string("main_android_org.lua")
let contents = fs::read_to_string("small.lua")
.expect("Something went wrong reading the file");
let tree = parse(&contents).expect("Parsing gone wrong");
let mut folder = ConstantFolder{};
folder.visit(tree);
// let nodes = tree.nodes_mut();
// for stmt in nodes.stmts() {
// match stmt {
// Stmt::LocalAssignment(_locals) => {
// // for name in locals.names() {
// // println!("name: {}", name)
// // }
// }
// Stmt::Assignment(assignment) => {
// for expr in assignment.expressions() {
// match expr {
// Expression::Value { value } => {
// match &**value {
// Value::Var(Var::Expression(ve)) => {
// println!("assign value var expression {}", ve.prefix());
// }
// Value::Var(Var::Name(name)) => {
// println!("assign value var name {}", name.token());
// }
// _ => {}
// }
// }
// _ => {}
// };
// }
// }
// _ => {
// // println!("stmt {}", stmt)
// }
// };
// }
}

5
src/visitor.rs Normal file
View File

@ -0,0 +1,5 @@
mod visitor;
mod constant_folder;
pub use visitor::*;
pub use constant_folder::*;

View File

@ -0,0 +1,117 @@
use full_moon::ast::*;
use crate::visitor::Visitor;
struct VariableValue {}
// value: Literal | String | Module | ReducedExpression
struct Variable {
name: String,
value: VariableValue
}
pub struct ConstantFolder {
locals: Vec<Variable>
}
impl ConstantFolder {
/// Return `Name` struct for a valid standard library name/function
///
/// Lua has standard library modules like `math.max`, `math.min`
/// This function returns a Name if the given argument are valid
/// This is to disambiguate between Var.Name
///
/// # Arguments
///
/// * `module` - Standard library model
/// * `name` - The module
///
fn name_from_standard_library(name: &str) -> Option<&str> {
let standard_library_names = vec![
"math", "string", "table", "bit"
];
if standard_library_names.contains(&name) {
Some(name)
} else {
None
}
}
fn visit_expression<'a>(&mut self, expression: Expression<'a>) {
match expression {
Expression::BinaryOperator {
lhs,
rhs,
binop
} => {
}
Expression::Parentheses {
contained,
expression,
} => {}
Expression::UnaryOperator {
unop,
expression,
} => {}
Expression::Value {
value
} => {}
_ => {}
}
}
}
impl Visitor for ConstantFolder {
fn visit_assignment<'a>(&mut self, assignment: &Assignment<'a>) {
println!("visit assignment {}", assignment);
}
fn visit_do<'a>(&mut self, do_: &Do<'a>) {
println!("visit do {}", do_);
}
fn visit_function_call<'a>(&mut self, function_call: &FunctionCall<'a>) {
println!("visit function_call {}", function_call);
}
fn visit_function_declaration<'a>(&mut self, function_declaration: &FunctionDeclaration<'a>) {
println!("visit function_declaration {}", function_declaration);
}
fn visit_generic_for<'a>(&mut self, generic_for: &GenericFor<'a>) {
println!("visit generic_for {}", generic_for);
}
fn visit_if<'a>(&mut self, if_: &If<'a>) {
println!("visit if {}", if_);
}
fn visit_local_assignment<'a>(&mut self, local_assignment: &LocalAssignment<'a>) {
println!("visit local_assignment {}", local_assignment);
}
fn visit_local_function<'a>(&mut self, local_function: &LocalFunction<'a>) {
println!("visit local_function {}", local_function);
}
fn visit_numeric_for<'a>(&mut self, numeric_for: &NumericFor<'a>) {
println!("visit numeric_for {}", numeric_for);
}
fn visit_repeat<'a>(&mut self, repeat: &Repeat<'a>) {
println!("visit repeat {}", repeat);
}
fn visit_while<'a>(&mut self, while_: &While<'a>) {
println!("visit while {}", while_);
}
fn visit_goto<'a>(&mut self, goto: &lua52::Goto<'a>) {
println!("visit goto {}", goto);
}
fn visit_label<'a>(&mut self, label: &lua52::Label<'a>) {
println!("visit label {}", label);
}
}

81
src/visitor/visitor.rs Normal file
View File

@ -0,0 +1,81 @@
use full_moon::ast::*;
pub trait Visitor {
fn visit<'a>(&mut self, tree: Ast<'a>) {
let nodes = tree.nodes();
for stmt in nodes.stmts() {
self.visit_statement(stmt)
}
}
fn visit_statement<'a>(&mut self, stmt: &Stmt<'a>) {
match stmt {
Stmt::Assignment(assignment) => {
self.visit_assignment(assignment)
}
Stmt::Do(do_) => {
self.visit_do(do_)
}
Stmt::FunctionCall(function_call) => {
self.visit_function_call(function_call)
}
Stmt::FunctionDeclaration(function_declaration) => {
self.visit_function_declaration(function_declaration)
}
Stmt::GenericFor(generic_for) => {
self.visit_generic_for(generic_for)
}
Stmt::If(if_) => {
self.visit_if(if_)
}
Stmt::LocalAssignment(local_assignment) => {
self.visit_local_assignment(local_assignment)
}
Stmt::LocalFunction(local_function) => {
self.visit_local_function(local_function)
}
Stmt::NumericFor(numeric_for) => {
self.visit_numeric_for(numeric_for)
}
Stmt::Repeat(repeat) => {
self.visit_repeat(repeat)
}
Stmt::While(while_) => {
self.visit_while(while_)
}
// Stmt::CompoundAssignment(compound_assignment) => {
// self.visit_compound_assignment(compound_assignment)
// }
// Stmt::ExportedTypeDeclaration(exported_type_declaration) => {
// self.visit_exported_type_declaration(exported_type_declaration)
// }
// Stmt::TypeDeclaration(type_declaration) => {
// self.visit_type_declaration(type_declaration)
// }
Stmt::Goto(goto) => {
self.visit_goto(goto)
}
Stmt::Label(label) => {
self.visit_label(label)
}
_ => {}
};
}
fn visit_assignment<'a>(&mut self, assignment: &Assignment<'a>);
fn visit_do<'a>(&mut self, do_: &Do<'a>);
fn visit_function_call<'a>(&mut self, function_call: &FunctionCall<'a>);
fn visit_function_declaration<'a>(&mut self, function_declaration: &FunctionDeclaration<'a>);
fn visit_generic_for<'a>(&mut self, generic_for: &GenericFor<'a>);
fn visit_if<'a>(&mut self, if_: &If<'a>);
fn visit_local_assignment<'a>(&mut self, local_assignment: &LocalAssignment<'a>);
fn visit_local_function<'a>(&mut self, local_function: &LocalFunction<'a>);
fn visit_numeric_for<'a>(&mut self, numeric_for: &NumericFor<'a>);
fn visit_repeat<'a>(&mut self, repeat: &Repeat<'a>);
fn visit_while<'a>(&mut self, while_: &While<'a>);
// fn visit_compound_assignment<'a>(&mut self, compound_assignment: &CompoundAssignment<'a>);
// fn visit_exported_type_declaration<'a>(&mut self, exported_type_declaration: &ExportedTypeDeclaration<'a>);
// fn visit_type_declaration<'a>(&mut self, type_declaration: &TypeDeclaration<'a>);
fn visit_goto<'a>(&mut self, goto: &lua52::Goto<'a>);
fn visit_label<'a>(&mut self, label: &lua52::Label<'a>);
}