From 52a5777949f2e83e062b6f556c60492e762ef97b Mon Sep 17 00:00:00 2001 From: mooz Date: Wed, 21 Nov 2018 21:21:07 +0100 Subject: [PATCH] =?UTF-8?q?Use=20l7801=20extension=20for=20=C2=B5PD7801=20?= =?UTF-8?q?compiler.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 1 + CMakeLists.txt | 2 +- l7801.c | 4 +- l7801.lua | 114 +++++++++--------- samples/{scv_hello.l65 => scv_hello.l7801} | 0 ...gue_tester.l65 => scv_plogue_tester.l7801} | 0 samples/{scv_test.l65 => scv_test.l7801} | 0 scv.l65 => scv.l7801 | 0 uPD7801.lua | 68 +++++------ 9 files changed, 95 insertions(+), 94 deletions(-) rename samples/{scv_hello.l65 => scv_hello.l7801} (100%) rename samples/{scv_plogue_tester.l65 => scv_plogue_tester.l7801} (100%) rename samples/{scv_test.l65 => scv_test.l7801} (100%) rename scv.l65 => scv.l7801 (100%) diff --git a/.travis.yml b/.travis.yml index e67f384..ad3969b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ script: - cmake . -DCMAKE_BUILD_TYPE=Release - make - cd samples; for f in *.l65; do echo $f; ../l65 $f || break; done; cd .. + - cd samples; for f in *.l7801; do echo $f; ../l7801 $f || break; done; cd .. - cp l65 l65-$TRAVIS_TAG-$TRAVIS_OS_NAME deploy: provider: releases diff --git a/CMakeLists.txt b/CMakeLists.txt index 8be35fe..df1762b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,7 @@ set(L7801_HEADERS ${L65_HEADERS} ) -set(L7801_FILES ${L65_SOURCE_DIR}/scv.l65) +set(L7801_FILES ${L65_SOURCE_DIR}/scv.l7801) set(L7801_SCRIPTS ${L65_SOURCE_DIR}/asm.lua diff --git a/l7801.c b/l7801.c index 18c6442..a403714 100644 --- a/l7801.c +++ b/l7801.c @@ -140,12 +140,12 @@ static int luaopen_l7801(lua_State *L) } #define SRC_LUA(name) { #name, 0, script_ ## name ## _lua, sizeof(script_ ## name ## _lua) } -#define SRC_L65(name) { #name, 1, script_ ## name ## _l65, sizeof(script_ ## name ## _l65) } +#define SRC_L7801(name) { #name, 1, script_ ## name ## _l7801, sizeof(script_ ## name ## _l7801) } static struct script { const char *name; int t; const char *data; size_t sz; } embedded[] = { SRC_LUA(dkjson), SRC_LUA(l65cfg), SRC_LUA(re), - SRC_L65(scv), + SRC_L7801(scv), }; #undef SRC_LUA #undef SRC_L7801 diff --git a/l7801.lua b/l7801.lua index a7f086e..491c667 100644 --- a/l7801.lua +++ b/l7801.lua @@ -2131,7 +2131,7 @@ local function ParseLua(src, src_name) end -local function Format65(ast) +local function Format7801(ast) local function splitLines(str) if str:match("\n") then local lines = {} @@ -2538,34 +2538,34 @@ local function Format65(ast) end local dirsep = package.config:sub(1,1) -local dirl65 = (string.match(arg[0], "(.*[\\/]).*") or ''):gsub('/',dirsep) -local searchl65 = '' -if #dirl65 > 0 then - searchl65 = string.format(";%s?;%s?.l65", dirl65, dirl65) - package.path = package.path .. string.format(";%s?.lua", dirl65) +local dirl7801 = (string.match(arg[0], "(.*[\\/]).*") or ''):gsub('/',dirsep) +local searchl7801 = '' +if #dirl7801 > 0 then + searchl7801 = string.format(";%s?;%s?.l7801", dirl7801, dirl7801) + package.path = package.path .. string.format(";%s?.lua", dirl7801) end -l65_def = { +l7801_def = { parse = ParseLua, - format = Format65, + format = Format7801, searcher_index = 2, - search_path = string.format(".%s?;.%s?.l65%s", dirsep, dirsep, searchl65), + search_path = string.format(".%s?;.%s?.l7801%s", dirsep, dirsep, searchl7801), load_org = load, loadfile_org = loadfile, dofile_org = dofile, } -if not l65 then l65 = l65_def else for k,v in pairs(l65_def) do l65[k]=v end end -l65.report = function(success, ...) +if not l7801 then l7801 = l7801_def else for k,v in pairs(l7801_def) do l7801[k]=v end end +l7801.report = function(success, ...) if success then return success,... end local message=... io.stderr:write(tostring(message)..'\n') os.exit(-1) end -l65.msghandler = function(msg) +l7801.msghandler = function(msg) local o = function(s) io.stderr:write(s) end msg = tostring(msg) - msg = msg:gsub('%[string "(.-%.l65)"%]', '%1') -- [string "xxx.l65"] -> xxx.l65 + msg = msg:gsub('%[string "(.-%.l7801)"%]', '%1') -- [string "xxx.l7801"] -> xxx.l7801 local trace_cur = debug.traceback(nil, 2) - trace_cur = trace_cur:gsub('%[string "(.-%.l65)"%]', '%1') -- [string "xxx.l65"] -> xxx.l65 + trace_cur = trace_cur:gsub('%[string "(.-%.l7801)"%]', '%1') -- [string "xxx.l7801"] -> xxx.l7801 trace_cur = trace_cur:gsub('stack traceback:', '') local i=2 @@ -2574,7 +2574,7 @@ l65.msghandler = function(msg) while true do local n,v = debug.getlocal(i, j) if not n then break end - if n == 'l65dbg' then + if n == 'l7801dbg' then o(string.format("%s\n", msg)) if trace_cur:find("in local 'late'") then local lines = {} @@ -2585,7 +2585,7 @@ l65.msghandler = function(msg) o(table.concat(lines,'\n')) end local trace = v.trace:match(".-\n(.*)\n.-'xpcall'") - trace = trace:gsub('%[string "(.-%.l65)"%]', '%1') + trace = trace:gsub('%[string "(.-%.l7801)"%]', '%1') trace = trace:gsub('stack traceback:', '') o(trace .. '\n') os.exit(-2) @@ -2601,32 +2601,32 @@ l65.msghandler = function(msg) end do local getembedded = type(arg[-1]) == 'function' and arg[-1] - l65.load_embedded = function(name) + l7801.load_embedded = function(name) if not getembedded then return end - local src,isl65 = getembedded(name) + local src,isl7801 = getembedded(name) if not src then return end - if isl65 then - name = name .. '.l65' - local st, ast = l65.report(l65.parse(src, name)) - src = l65.format(ast) + if isl7801 then + name = name .. '.l7801' + local st, ast = l7801.report(l7801.parse(src, name)) + src = l7801.format(ast) else name = name .. '.lua' end - local bc = assert(l65.load_org(src, name)) + local bc = assert(l7801.load_org(src, name)) return bc, name end end -l65.searcher = function(name) - local filename,err = package.searchpath(name, l65.search_path, '.', '.') +l7801.searcher = function(name) + local filename,err = package.searchpath(name, l7801.search_path, '.', '.') if not filename then return err end local file = assert(io.open(filename, 'rb')) local src = file:read('*a') file:close() - local st, ast = l65.report(l65.parse(src, filename)) - local bc = assert(l65.load_org(l65.format(ast), filename)) + local st, ast = l7801.report(l7801.parse(src, filename)) + local bc = assert(l7801.load_org(l7801.format(ast), filename)) return bc, filename end -l65.load = function(chunk, chunkname, mode, ...) +l7801.load = function(chunk, chunkname, mode, ...) local chunk_t,s = type(chunk) if chunk_t == 'string' then s = chunk elseif chunk_t == 'function' then @@ -2635,12 +2635,12 @@ l65.load = function(chunk, chunkname, mode, ...) else return nil, string.format("invalid type for chunk %s: %s", chunkname or "=(load)", chunk_t) end if s:sub(1,4) == "\x1bLua" then -- a binary file - return l65.load_org(s, chunkname, mode, ...) + return l7801.load_org(s, chunkname, mode, ...) end - local st, ast = l65.report(l65.parse(s, chunkname or "=(load)")) - return l65.load_org(l65.format(ast), chunkname, 't', ...) + local st, ast = l7801.report(l7801.parse(s, chunkname or "=(load)")) + return l7801.load_org(l7801.format(ast), chunkname, 't', ...) end -l65.loadfile = function(filename, mode, ...) +l7801.loadfile = function(filename, mode, ...) local s if not filename then s = io.read('*a') else @@ -2649,34 +2649,34 @@ l65.loadfile = function(filename, mode, ...) s = file:read('*a') file:close() end - return l65.load(s, filename, mode, ...) + return l7801.load(s, filename, mode, ...) end -l65.dofile = function(filename) - local f = l65.report(l65.loadfile(filename)) +l7801.dofile = function(filename) + local f = l7801.report(l7801.loadfile(filename)) return f() end -l65.installhooks = function() - if package.searchers[l65.searcher_index] ~= l65.searcher then - table.insert(package.searchers, l65.searcher_index, l65.searcher) +l7801.installhooks = function() + if package.searchers[l7801.searcher_index] ~= l7801.searcher then + table.insert(package.searchers, l7801.searcher_index, l7801.searcher) end - if not l65.hooks_installed then l65.hooks_installed = true - load = l65.load - loadfile = l65.loadfile - dofile = l65.dofile + if not l7801.hooks_installed then l7801.hooks_installed = true + load = l7801.load + loadfile = l7801.loadfile + dofile = l7801.dofile end end -l65.uninstallhooks = function() +l7801.uninstallhooks = function() for k,v in ipairs(package.searchers) do - if v == l65.searcher then table.remove(package.searchers, k) break end + if v == l7801.searcher then table.remove(package.searchers, k) break end end - if l65.hooks_installed then l65.hooks_installed = nil - load = l65.load_org - loadfile = l65.loadfile_org - dofile = l65.dofile_org + if l7801.hooks_installed then l7801.hooks_installed = nil + load = l7801.load_org + loadfile = l7801.loadfile_org + dofile = l7801.dofile_org end end -table.insert(package.searchers, l65.searcher_index, l65.load_embedded) -l65.installhooks() +table.insert(package.searchers, l7801.searcher_index, l7801.load_embedded) +l7801.installhooks() function getopt(optstring, ...) local opts = { } @@ -2712,16 +2712,16 @@ function getopt(optstring, ...) end) end -local cfg=require"l65cfg" l65.cfg=cfg +local cfg=require"l65cfg" l7801.cfg=cfg local version = function() - print(string.format("l65 %s", cfg.version)) + print(string.format("l7801 %s", cfg.version)) end local usage = function(f) if not f then f = io.stdout end f:write(string.format([[ Usage: %s [options] file [args] Options: - -d Dump the Lua code after l65 parsing into file + -d Dump the Lua code after l7801 parsing into file -h Display this information -v Display the release version ]], arg[0])) @@ -2740,12 +2740,12 @@ for opt,arg,i in getopt("d:hv", ...) do if opt == false then inf=arg optix=i+1 break end end if not inf then return invalid_usage() end -if dump then l65.format = function(ast) - local s=Format65(ast) l65.format = Format65 +if dump then l7801.format = function(ast) + local s=Format7801(ast) l7801.format = Format7801 local f = assert(io.open(dump, 'wb')) f:write(s) f:close() return s end end local fn='' for i=#inf,1,-1 do local c=inf:sub(i,i) if c==dirsep or c=='/' then break end fn=c..fn if c=='.' then fn='' end end filename=fn -local f = l65.report(l65.loadfile(inf)) -return xpcall(f, l65.msghandler, select(optix, ...)) +local f = l7801.report(l7801.loadfile(inf)) +return xpcall(f, l7801.msghandler, select(optix, ...)) diff --git a/samples/scv_hello.l65 b/samples/scv_hello.l7801 similarity index 100% rename from samples/scv_hello.l65 rename to samples/scv_hello.l7801 diff --git a/samples/scv_plogue_tester.l65 b/samples/scv_plogue_tester.l7801 similarity index 100% rename from samples/scv_plogue_tester.l65 rename to samples/scv_plogue_tester.l7801 diff --git a/samples/scv_test.l65 b/samples/scv_test.l7801 similarity index 100% rename from samples/scv_test.l65 rename to samples/scv_test.l7801 diff --git a/scv.l65 b/scv.l7801 similarity index 100% rename from scv.l65 rename to scv.l7801 diff --git a/uPD7801.lua b/uPD7801.lua index 7f85bfd..4aee978 100644 --- a/uPD7801.lua +++ b/uPD7801.lua @@ -111,9 +111,9 @@ local opregxx ={ } M.opregxx = opregxx for k,v in pairs(opregxx) do M[k] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 2 end - local bin = function() local l65dbg=l65dbg return { v.opc, M.op_eval_byte(late,early) } end + local bin = function() local l7801dbg=l7801dbg return { v.opc, M.op_eval_byte(late,early) } end table.insert(M.section_current.instructions, { size=size, cycles=v.cycles, bin=bin }) end end @@ -138,9 +138,9 @@ local opaxx ={ } M.opaxx = opaxx for k,v in pairs(opaxx) do M[k .. 'a'] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 2 end - local bin = function() local l65dbg=l65dbg return { v.opc, M.op_eval_byte(late,early) } end + local bin = function() local l7801dbg=l7801dbg return { v.opc, M.op_eval_byte(late,early) } end table.insert(M.section_current.instructions, { size=size, cycles=v.cycles, bin=bin }) end end @@ -165,9 +165,9 @@ local opw = { } M.opw = opw for k,v in pairs(opw) do M[k .. 'imm'] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 3 end - local bin = function() local l65dbg=l65dbg + local bin = function() local l7801dbg=l7801dbg local x = M.op_eval_word(late,early) return { v.opc, x&0xff, x>>8 } end @@ -183,9 +183,9 @@ local opr16w = { } M.opr16w = opr16w for k,v in pairs(opr16w) do M[k] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 3 end - local bin = function() local l65dbg=l65dbg + local bin = function() local l7801dbg=l7801dbg local x = M.op_eval_word(late,early) return { v.opc, x&0xff, x>>8 } end @@ -195,11 +195,11 @@ end M['calt' .. 'imm'] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local op = { cycles=19 } op.size = function() late,early = M.size_op(late,early) return 1 end op.bin = function() - local l65dbg=l65dbg + local l7801dbg=l7801dbg local x = M.op_eval_byte(late,early) if (x%2 == 1) then error("offset should be even : " .. x) end if x < 0x80 or x > 0xfe then error("offset out of range : " .. x) end @@ -210,10 +210,10 @@ M['calt' .. 'imm'] = function(late, early) end M['calf' .. 'imm'] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local op = { cycles=16 } op.size = function() late,early = M.size_op(late,early) return 2 end - op.bin = function() local l65dbg=l65dbg + op.bin = function() local l7801dbg=l7801dbg local x = 0 + M.op_eval_word(late,early) if x < 0x0800 or x > 0xffff then error("subroutine address out of range [0x0800-0xffff]: " .. x) end x = x - 0x0800; @@ -223,7 +223,7 @@ M['calf' .. 'imm'] = function(late, early) end M.jr = function(label) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local parent,offset = M.label_current local section,rorg = M.section_current,M.location_current.rorg local op = { cycles=13 } @@ -233,7 +233,7 @@ M.jr = function(label) return 1 end op.bin = function() - local l65dbg=l65dbg + local l7801dbg=l7801dbg local x,l = label,label if type(x) == 'function' then x=x() end if type(x) == 'string' then @@ -254,7 +254,7 @@ M.jr = function(label) end M.jre = function(label) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local parent,offset = M.label_current local section,rorg = M.section_current,M.location_current.rorg local op = { cycles=17 } @@ -264,7 +264,7 @@ M.jre = function(label) return 2 end op.bin = function() - local l65dbg=l65dbg + local l7801dbg=l7801dbg local x,l = label,label if type(x) == 'function' then x=x() end if type(x) == 'string' then @@ -296,9 +296,9 @@ local opwa = { } M.opwa = opwa for k,v in pairs(opwa) do M[k .. 'wa'] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 2 end - local bin = function() local l65dbg=l65dbg return { v.opc, M.op_eval_byte(late,early) } end + local bin = function() local l7801dbg=l7801dbg return { v.opc, M.op_eval_byte(late,early) } end table.insert(M.section_current.instructions, { size=size, cycles=v.cycles, bin=bin }) end end @@ -309,14 +309,14 @@ local opwaxx = { } M.opwaxx = opwaxx for k,v in pairs(opwaxx) do M[k .. 'waxx'] = function(late_offset, late_data, early_offset, early_data) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late_offset,early_offset = M.size_op(late_offset,early_offset) late_data,early_data = M.size_op(late_data,early_data) return 3 end local bin = function() - local l65dbg=l65dbg + local l7801dbg=l7801dbg return { v.opc, M.op_eval_byte(late_offset,early_offset), M.op_eval_byte(late_data,early_data) } end table.insert(M.section_current.instructions, { size=size, cycles=v.cycles, bin=bin }) @@ -401,10 +401,10 @@ local opinout={ } M.opinout = op4inout for k,v in pairs(opinout) do M[k .. 'imm'] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local op = { cycles=v.cycles } op.size = function() late,early = M.size_op(late,early) return 2 end - op.bin = function() local l65dbg=l65dbg + op.bin = function() local l7801dbg=l7801dbg local x = 0x00 + M.op_eval_byte(late,early) return { v.opc, 0x00, x } end @@ -492,10 +492,10 @@ for i,o in ipairs(op64names) do if not M[name] then local l = k M[name] = function(late,early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local op = { cycles=11 } op.size = function() late,early = M.size_op(late,early) return 3 end - op.bin = function() local l65dbg=l65dbg + op.bin = function() local l7801dbg=l7801dbg local x = 0x00 + l; local y = 0x00 + M.op_eval_byte(late,early) return { 0x64, x, y } @@ -515,10 +515,10 @@ for i,o in ipairs(op64names) do if not M[name] then local l = k M[name] = function(late,early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local op = { cycles=11 } op.size = function() late,early = M.size_op(late,early) return 3 end - op.bin = function() local l65dbg=l65dbg + op.bin = function() local l7801dbg=l7801dbg local x = 0x00 + l; local y = 0x00 + M.op_eval_byte(late,early) return { 0x64, x, y } @@ -550,9 +550,9 @@ local op74wa = { } M.op74wa = op74wa for k,v in pairs(op74wa) do M[k .. 'wa'] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 3 end - local bin = function() local l65dbg=l65dbg return { 0x74, v.opc, M.op_eval_byte(late,early) } end + local bin = function() local l7801dbg=l7801dbg return { 0x74, v.opc, M.op_eval_byte(late,early) } end table.insert(M.section_current.instructions, { size=size, cycles=v.cycles, bin=bin }) end end @@ -569,9 +569,9 @@ local op70ind = { } M.op70ind = op70ind for k,v in pairs(op70ind) do M[k] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 4 end - local bin = function() local l65dbg=l65dbg + local bin = function() local l7801dbg=l7801dbg local x = M.op_eval_word(late,early) return { 0x70, v.opc, x&0xff, x>>8 } end @@ -591,9 +591,9 @@ local op70indr8 = { } M.op70indr8 = op70indr8 for k,v in pairs(op70indr8) do M[k] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 4 end - local bin = function() local l65dbg=l65dbg + local bin = function() local l7801dbg=l7801dbg local x = M.op_eval_word(late,early) return { 0x70, v.opc, x&0xff, x>>8 } end @@ -613,9 +613,9 @@ local op70r8ind = { } M.op70r8ind = op70r8ind for k,v in pairs(op70r8ind) do M[k] = function(late, early) - local l65dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } + local l7801dbg = { info=debug.getinfo(2, 'Sl'), trace=debug.traceback(nil, 1) } local size = function() late,early = M.size_op(late,early) return 4 end - local bin = function() local l65dbg=l65dbg + local bin = function() local l7801dbg=l7801dbg local x = M.op_eval_word(late,early) return { 0x70, v.opc, x&0xff, x>>8 } end