1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-05-18 16:33:22 -07:00
lips/lips/util.lua

38 lines
786 B
Lua
Raw Normal View History

2016-01-15 11:15:02 -08:00
local floor = math.floor
local open = io.open
local function Class(inherit)
local class = {}
local mt_obj = {__index = class}
local mt_class = {
__call = function(self, ...)
local obj = setmetatable({}, mt_obj)
obj:init(...)
return obj
end,
__index = inherit,
}
return setmetatable(class, mt_class)
end
local function readfile(fn)
local f = open(fn, 'r')
if not f then
error('could not open assembly file for reading: '..tostring(fn), 2)
end
local asm = f:read('*a')
f:close()
return asm
end
local function bitrange(x, lower, upper)
return floor(x/2^lower) % 2^(upper - lower + 1)
end
return {
Class = Class,
readfile = readfile,
bitrange = bitrange,
}