Wiped; Added nexus, classes, dependency heuristic, dependency solver shell, main loop /w commands

This commit is contained in:
paladin
2026-06-26 03:13:17 +01:00
parent d28c008c5d
commit 144d50fc03
+85 -32
View File
@@ -1,40 +1,93 @@
local ID = 1 local I = 1
local c = {}
setmetatable(c,{__call = function(c) local c = setmetatable({},{
local this = {} __call = function(c,class,data,...)
c[this] = {} local new = {}
return this -- todo: use a better data structure; recycle nexus
end}) new.implies = {} -- Table of all dependency nexus of this class: it.items[0] == c
c.i = {} setmetatable(new,c)
c.o = {} return new
end
})
c.d = c() -- depend
c.s = c() -- solve
c.c = c() -- commit
c.h = c() -- cookie heuristic
local function h(it)
-- Find and return the data value of the first heuristic unit super-nexus of this object
for item,index in pairs(it.index) do
if item.class = c.h then
return item.data
end
end
end
local function s(it)
-- todo: use some sort of heuristic here like A*
local options = {it}
while true do
table.sort(branches,function(a,b) return h(a) > h(b) end)
for depends in pairs(it.class.implies) do
depends.
end
break
end
end
local n = setmetatable({},{
__call = function(n,class,data,...)
local new = {}
setmetatable(new,n)
new.class = class
table.insert(class.instances,class)
new.data = data
new.items = {...}
for index,item in pairs(new.items) do
item.index[new] = index
end
new.index = {}
s(new)
return new
end
})
c.next = c() c.next = c()
for char in ("abcdefghijklmnopqrstuvwxyz $;"):match(".") do c.in = {}
c.i[char] = c() c.out = {}
c.text = {}
c.cookie = c()
for char in ("abcdefghijklmnopqrstuvwxyz "):match(".") do
c.in[char] = c()
c.out[char] = c()
end end
local function n(class,data,...)
local this = {up = {},class = class,data = data} local previous = n(c(),I)
table.insert(c[class],this)
return this
end
local i = {}
setmetatable(i,{__call = function(i,this)
end})
local prev
while true do while true do
prev = n(c[";"],ID,nil)
local input = io.read() local input = io.read()
local mode,input = io.read():match("([#P])(.*)") for command in input:gmatch([^@]*) do
local t = ({["$"]=c.i,["#"]=c.o})[mode] local name,text = command:match("(%a*)%s*(.*)")
if t then if name == "cookie" then
for char in input:match(".") do local cookie = n(c.cookie,I)
if t[char] then n(c.next,I,previous,cookie)
local this = n(t[char],ID,nil) previous = cookie
n(t.next,ID,prev,this) else
i(this) local mode
prev = this if name == "in" or name == "" then
mode = c.in
elseif name == "out" then
mode = c.out
else
error(string.format("Unknown command '@%s'",name))
end
for char in text:match(".") do
if mode[char] then
local object = n(mode[char],I)
n(c.next,I,previous,object)
previous = object
end
end end
end end
end end
prev = n(t[";"],ID,nil)
end end