Compare commits
No commits in common. "283be71809adeab6e734722c0c486bfd452929b4" and "0441c109bf55764453f12b45582faa73ce95e696" have entirely different histories.
283be71809
...
0441c109bf
|
|
@ -1,2 +1 @@
|
||||||
*.luo
|
*.luo
|
||||||
lunaclib.so
|
|
||||||
|
|
|
||||||
4
build.sh
4
build.sh
|
|
@ -1,4 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
cc -shared $(pkg-config --cflags luajit) lunaclib.c $(pkg-config --libs luajit) -o lunaclib.so
|
|
||||||
|
|
||||||
31
lunaclib.c
31
lunaclib.c
|
|
@ -1,31 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <lua.h>
|
|
||||||
#include <lauxlib.h>
|
|
||||||
|
|
||||||
static int u64_to_num(lua_State* L) {
|
|
||||||
#ifndef LUA_NUMBER_DOUBLE
|
|
||||||
#error Lua must be compiled with number as a double floating point
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const uint64_t h1 = luaL_checkint(L, 1);
|
|
||||||
const uint64_t h2 = luaL_checkint(L, 2);
|
|
||||||
|
|
||||||
const uint64_t stacked = (h2 << 32) | h1;
|
|
||||||
|
|
||||||
double res = *(double *)((char *)&stacked);
|
|
||||||
lua_pushnumber(L, res);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct luaL_Reg lib[] = {
|
|
||||||
{"u64_to_num", u64_to_num},
|
|
||||||
{NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
int luaopen_lunaclib(lua_State *L) {
|
|
||||||
luaL_openlib(L, "lunaclib", lib, 0);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@ local readbc = require('readbc')
|
||||||
local vm = require('vm')
|
local vm = require('vm')
|
||||||
local VM = vm.VM
|
local VM = vm.VM
|
||||||
|
|
||||||
fp = io.open('snippets/test1.luo')
|
fp = io.open('tests/test1.luo')
|
||||||
header = readbc.read_header(fp)
|
header = readbc.read_header(fp)
|
||||||
proto = readbc.read_proto(fp)
|
proto = readbc.read_proto(fp)
|
||||||
fp:close()
|
fp:close()
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,9 @@ local Metamethod = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local Opcodes_defs = gen_opcodes {
|
local Opcodes_defs = gen_opcodes {
|
||||||
opcode(0x25, 'POW', Mode.dst, Mode.none, Mode.lits, Metamethod.none),
|
opcode(37, 'POW', Mode.dst, Mode.none, Mode.lits, Metamethod.none),
|
||||||
opcode(0x29, 'KSHORT', Mode.dst, Mode.var, Mode.var, Metamethod.pow),
|
opcode(41, 'KSHORT', Mode.dst, Mode.var, Mode.var, Metamethod.pow),
|
||||||
opcode(0x4b, 'RET0', Mode.rbase, Mode.none, Mode.lit, Mode.none),
|
opcode(75, 'RET0', Mode.rbase, Mode.none, Mode.lit, Mode.none),
|
||||||
}
|
}
|
||||||
|
|
||||||
local function decode(ins)
|
local function decode(ins)
|
||||||
|
|
|
||||||
14
readbc.lua
14
readbc.lua
|
|
@ -1,8 +1,6 @@
|
||||||
-- module for reading serialized lua bytecode
|
-- module for reading serialized lua bytecode
|
||||||
|
|
||||||
local bit=require('bit')
|
local bit=require('bit')
|
||||||
local lunaclib = require('lunaclib')
|
|
||||||
local u64_to_num = lunaclib.u64_to_num
|
|
||||||
|
|
||||||
local HEADER_MAGIC = {27, string.byte('L'), string.byte('J')}
|
local HEADER_MAGIC = {27, string.byte('L'), string.byte('J')}
|
||||||
local FLAG_STRIP = 0x02
|
local FLAG_STRIP = 0x02
|
||||||
|
|
@ -55,7 +53,6 @@ local function read_uleb128(fp)
|
||||||
while not last_byte do
|
while not last_byte do
|
||||||
local uleb_byte = read_u8(fp)
|
local uleb_byte = read_u8(fp)
|
||||||
res = bit.bor(res, bit.lshift(bit.band(uleb_byte, 0x7f), shift))
|
res = bit.bor(res, bit.lshift(bit.band(uleb_byte, 0x7f), shift))
|
||||||
shift = shift + 7
|
|
||||||
|
|
||||||
if bit.band(uleb_byte, 0x80) == 0 then
|
if bit.band(uleb_byte, 0x80) == 0 then
|
||||||
last_byte = true
|
last_byte = true
|
||||||
|
|
@ -127,16 +124,7 @@ local function read_proto(fp)
|
||||||
local bcins = read_u32n(fp, numbc)
|
local bcins = read_u32n(fp, numbc)
|
||||||
local uvdata = read_u16n(fp, numuv)
|
local uvdata = read_u16n(fp, numuv)
|
||||||
-- local kgc
|
-- local kgc
|
||||||
local num = {}
|
-- local numkn
|
||||||
for i = 1, numkn do
|
|
||||||
local x = read_uleb128(fp)
|
|
||||||
if bit.band(x, 1) == 1 then
|
|
||||||
local y = read_uleb128(fp)
|
|
||||||
num[i] = u64_to_num(x, y)
|
|
||||||
else
|
|
||||||
num[i] = (x/2)-1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- local debug = fp:read(debugLen)
|
-- local debug = fp:read(debugLen)
|
||||||
|
|
||||||
-- TODO: remove when reading of kgc, numkn and debug is implemented
|
-- TODO: remove when reading of kgc, numkn and debug is implemented
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
local num = 2^15+1
|
|
||||||
local num64 = 2^32
|
|
||||||
local fp = 0.75
|
|
||||||
Loading…
Reference in New Issue