diff --git a/.buildactions/00_init.lua b/.buildactions/00_init.lua new file mode 100644 index 0000000..1bcda07 --- /dev/null +++ b/.buildactions/00_init.lua @@ -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" \ No newline at end of file diff --git a/.buildactions/10_zlua.lua b/.buildactions/10_zlua.lua new file mode 100644 index 0000000..1a490e6 --- /dev/null +++ b/.buildactions/10_zlua.lua @@ -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" \ No newline at end of file diff --git a/.buildactions/90_package.lua b/.buildactions/90_package.lua new file mode 100644 index 0000000..1137183 --- /dev/null +++ b/.buildactions/90_package.lua @@ -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" \ No newline at end of file diff --git a/build.sh b/build.sh index a20c7b7..8d55862 100755 --- a/build.sh +++ b/build.sh @@ -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 - $@ \ No newline at end of file diff --git a/build.sh.old b/build.sh.old new file mode 100755 index 0000000..a20c7b7 --- /dev/null +++ b/build.sh.old @@ -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 diff --git a/escape.lua b/escape.lua new file mode 100644 index 0000000..8ee51f2 --- /dev/null +++ b/escape.lua @@ -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"))) \ No newline at end of file diff --git a/luabuild.lua b/luabuild.lua new file mode 100644 index 0000000..2a86453 --- /dev/null +++ b/luabuild.lua @@ -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.") \ No newline at end of file diff --git a/module/bootloader.lua b/module/bootloader.lua new file mode 100644 index 0000000..7916e3e --- /dev/null +++ b/module/bootloader.lua @@ -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 ]])() \ No newline at end of file diff --git a/psychos.tsar b/psychos.tsar new file mode 100644 index 0000000..da8a4fe Binary files /dev/null and b/psychos.tsar differ diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..9c2edfe Binary files /dev/null and b/test.lua differ diff --git a/zlua.lua b/zlua.lua new file mode 100644 index 0000000..f959b6b --- /dev/null +++ b/zlua.lua @@ -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 +--]]---------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +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)) \ No newline at end of file