This commit is contained in:
Sam Roxanne 2020-06-02 19:09:37 -05:00
parent 7dda36fd1d
commit 50cfb2bbf2
11 changed files with 219 additions and 14 deletions

View File

@ -0,0 +1,6 @@
function actions.init()
os.execute("mkdir -p target")
os.execute("luacomp module/bootloader.lua -O target/init.lua")
end
actions[#actions+1] = "init"

19
.buildactions/10_zlua.lua Normal file
View File

@ -0,0 +1,19 @@
local function makezlua(file)
local path = file:match("^(.+)/.+%..+$")
os.execute("mkdir -p target/"..path)
os.execute("cat "..file.." | luamin -c | lua zlua.lua > target/"..file)
end
function actions.files()
local libs = find("lib", "*.lua")
local svcs = find("service", "*.lua")
for i=1, #libs do
makezlua(libs[i])
end
for i=1, #svcs do
makezlua(svcs[i])
end
end
actions[#actions+1] = "files"

View File

@ -0,0 +1,6 @@
function actions.package()
os.execute("cp -r cfg target")
os.execute("cd target; find $".."(ls) -depth | tsar -o > ../psychos.tsar")
end
actions[#actions+1] = "package"

View File

@ -1,14 +1,2 @@
#!/bin/bash
LUA=${LUA:-lua}
rm -r target/*
mkdir -p target/doc &>/dev/null
$LUA luapreproc.lua module/init.lua target/init.lua
echo _OSVERSION=\"PsychOS 2.0a2-$(git rev-parse --short HEAD)\" > target/version.lua
cat target/version.lua target/init.lua > target/tinit.lua
mv target/tinit.lua target/init.lua
cp -r service/ lib/ cfg/ target/
rm target/version.lua
rm -r doc/ &>/dev/null
$LUA finddesc.lua doc/ $(find lib/ module/ -type f|sort)
$LUA gendoc.lua target/doc/kernel.dict $(find module/ -type f|sort)
pandoc doc/apidoc.md docs-metadata.yml --template=template.tex -o doc/apidoc.pdf
#!/usr/bin/env bash
luacomp luabuild.lua 2>/dev/null | lua - $@

14
build.sh.old Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
LUA=${LUA:-lua}
rm -r target/*
mkdir -p target/doc &>/dev/null
$LUA luapreproc.lua module/init.lua target/init.lua
echo _OSVERSION=\"PsychOS 2.0a2-$(git rev-parse --short HEAD)\" > target/version.lua
cat target/version.lua target/init.lua > target/tinit.lua
mv target/tinit.lua target/init.lua
cp -r service/ lib/ cfg/ target/
rm target/version.lua
rm -r doc/ &>/dev/null
$LUA finddesc.lua doc/ $(find lib/ module/ -type f|sort)
$LUA gendoc.lua target/doc/kernel.dict $(find module/ -type f|sort)
pandoc doc/apidoc.md docs-metadata.yml --template=template.tex -o doc/apidoc.pdf

22
escape.lua Normal file
View File

@ -0,0 +1,22 @@
local function mkstr(d)
local dat = "\""
for i=1, #d do
if (d:sub(i,i) == "\\") then
dat = dat .. ("\\\\")
elseif (d:sub(i,i) == "\"") then
dat = dat .. ("\\\"")
elseif (d:sub(i,i) == "\n") then
dat = dat .. ("\\n")
elseif (d:sub(i,i) == "\r") then
dat = dat .. ("\\r")
elseif (d:sub(i,i) == "\t") then
dat = dat .. ("\\t")
else
dat = dat .. (d:sub(i,i))
end
end
dat = dat .. ("\"")
return dat
end
io.stdout:write(mkstr(io.stdin:read("*a")))

47
luabuild.lua Normal file
View File

@ -0,0 +1,47 @@
local actions = {}
local function list(dir)
local h = io.popen("ls \""..dir.."\"", "r")
local ents = {}
for l in h:lines() do
ents[#ents+1] = l
end
h:close()
return ents
end
local function find(dir, pattern, inverse, ctype)
local h = io.popen("find \""..dir.."\" "..(((inverse) and "-not ") or "")..(((ctype) and "-type "..ctype.." ") or "").."-name \""..pattern.."\"", "r")
local ents = {}
for l in h:lines() do
ents[#ents+1] = l
end
h:close()
return ents
end
local function lastmod(file)
local h = io.popen("stat -c %Y \""..file.."\"")
local num = tonumber(h:read("*a"))
h:close()
return num
end
@[[local h = io.popen("ls .buildactions", "r")
for line in h:lines() do]]
--#include @[{".buildactions/"..line}]
@[[end]]
function actions.all()
for i=1, #actions do
actions[actions[i]]()
end
end
if not arg[1] then
arg[1] = "all"
end
actions[arg[1]]()
print("Build complete.")

21
module/bootloader.lua Normal file
View File

@ -0,0 +1,21 @@
_OSVERSION="PsychOS 2.0a2-$[[git rev-parse --short HEAD]]"
function lzss_decompress(a)local b,c,d,e,j,i,h,g=1,'',''while b<=#a do
e=c.byte(a,b)b=b+1
for k=0,7 do h=c.sub
g=h(a,b,b)if e>>k&1<1 and b<#a then
i=c.unpack('>I2',a,b)j=1+(i>>4)g=h(d,j,j+(i&15)+2)b=b+1
end
b=b+1
c=c..g
d=h(d..g,-4^6)end
end
return c end
local oload = load
function load(src, ...)
if (src:sub(1,4) == "\27ZLS") then
src = lzss_decompress(src:sub(5))
end
return oload(src, ...)
end
load($[[ luacomp -mluamin module/init.lua | lua zlua.lua | lua escape.lua ]])()

BIN
psychos.tsar Normal file

Binary file not shown.

BIN
test.lua Normal file

Binary file not shown.

82
zlua.lua Normal file
View File

@ -0,0 +1,82 @@
local f = io.stdin:read("*a")
--[[----------------------------------------------------------------------------
LZSS - encoder / decoder
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
--]]----------------------------------------------------------------------------
--------------------------------------------------------------------------------
local M = {}
local string, table = string, table
--------------------------------------------------------------------------------
local POS_BITS = 12
local LEN_BITS = 16 - POS_BITS
local POS_SIZE = 1 << POS_BITS
local LEN_SIZE = 1 << LEN_BITS
local LEN_MIN = 3
--------------------------------------------------------------------------------
function M.compress(input)
local offset, output = 1, {}
local window = ''
local function search()
for i = LEN_SIZE + LEN_MIN - 1, LEN_MIN, -1 do
local str = string.sub(input, offset, offset + i - 1)
local pos = string.find(window, str, 1, true)
if pos then
return pos, str
end
end
end
while offset <= #input do
local flags, buffer = 0, {}
for i = 0, 7 do
if offset <= #input then
local pos, str = search()
if pos and #str >= LEN_MIN then
local tmp = ((pos - 1) << LEN_BITS) | (#str - LEN_MIN)
buffer[#buffer + 1] = string.pack('>I2', tmp)
else
flags = flags | (1 << i)
str = string.sub(input, offset, offset)
buffer[#buffer + 1] = str
end
window = string.sub(window .. str, -POS_SIZE)
offset = offset + #str
else
break
end
end
if #buffer > 0 then
output[#output + 1] = string.char(flags)
output[#output + 1] = table.concat(buffer)
end
end
return table.concat(output)
end
io.stdout:write("\27ZLS"..M.compress(f))