From 9fd46b571fbd0cc8623b9230879f049bfe67ac48 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 13 Jan 2016 07:40:14 -0800 Subject: [PATCH] set up as a proper module; fix some stuff --- Class.lua => lips/Class.lua | 0 Dumper.lua => lips/Dumper.lua | 4 ++-- Lexer.lua => lips/Lexer.lua | 15 +++++++++++++-- Parser.lua => lips/Parser.lua | 10 +++++----- data.lua => lips/data.lua | 0 lips.lua => lips/init.lua | 4 +++- overrides.lua => lips/overrides.lua | 4 +++- 7 files changed, 26 insertions(+), 11 deletions(-) rename Class.lua => lips/Class.lua (100%) rename Dumper.lua => lips/Dumper.lua (99%) rename Lexer.lua => lips/Lexer.lua (96%) rename Parser.lua => lips/Parser.lua (98%) rename data.lua => lips/data.lua (100%) rename lips.lua => lips/init.lua (97%) rename overrides.lua => lips/overrides.lua (99%) diff --git a/Class.lua b/lips/Class.lua similarity index 100% rename from Class.lua rename to lips/Class.lua diff --git a/Dumper.lua b/lips/Dumper.lua similarity index 99% rename from Dumper.lua rename to lips/Dumper.lua index e2f52d1..faacf02 100644 --- a/Dumper.lua +++ b/lips/Dumper.lua @@ -1,13 +1,13 @@ local insert = table.insert local floor = math.floor -local data = require "data" +local data = require "lips.data" local function bitrange(x, lower, upper) return floor(x/2^lower) % 2^(upper - lower + 1) end -local Dumper = require("Class")() +local Dumper = require("lips.Class")() function Dumper:init(writer, fn, options) self.writer = writer self.fn = fn or '(string)' diff --git a/Lexer.lua b/lips/Lexer.lua similarity index 96% rename from Lexer.lua rename to lips/Lexer.lua index fa81190..922f454 100644 --- a/Lexer.lua +++ b/lips/Lexer.lua @@ -1,10 +1,21 @@ local byte = string.byte local char = string.char local find = string.find +local open = io.open -local data = require "data" +local data = require "lips.data" -local Lexer = require("Class")() +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 Lexer = require("lips.Class")() function Lexer:init(asm, fn, options) self.asm = asm self.fn = fn or '(string)' diff --git a/Parser.lua b/lips/Parser.lua similarity index 98% rename from Parser.lua rename to lips/Parser.lua index 01d662a..f3e9bc3 100644 --- a/Parser.lua +++ b/lips/Parser.lua @@ -1,12 +1,12 @@ local insert = table.insert local format = string.format -local data = require "data" -local overrides = require "overrides" -local Dumper = require "Dumper" -local Lexer = require "Lexer" +local data = require "lips.data" +local overrides = require "lips.overrides" +local Dumper = require "lips.Dumper" +local Lexer = require "lips.Lexer" -local Parser = require("Class")() +local Parser = require("lips.Class")() function Parser:init(writer, fn, options) self.fn = fn or '(string)' self.main_fn = self.fn diff --git a/data.lua b/lips/data.lua similarity index 100% rename from data.lua rename to lips/data.lua diff --git a/lips.lua b/lips/init.lua similarity index 97% rename from lips.lua rename to lips/init.lua index 8f2d53e..d3dfac7 100644 --- a/lips.lua +++ b/lips/init.lua @@ -12,7 +12,9 @@ local assembler = { ]], } -local Parser = require "Parser" +local open = io.open + +local Parser = require "lips.Parser" local function readfile(fn) local f = open(fn, 'r') diff --git a/overrides.lua b/lips/overrides.lua similarity index 99% rename from overrides.lua rename to lips/overrides.lua index c06bad1..dfbce6e 100644 --- a/overrides.lua +++ b/lips/overrides.lua @@ -1,4 +1,6 @@ -local data = require "data" +local insert = table.insert + +local data = require "lips.data" local instructions = data.instructions local overrides = {}