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 c = {}
setmetatable(c,{__call = function(c)
local this = {}
c[this] = {}
return this
end})
c.i = {}
c.o = {}
local I = 1
local c = setmetatable({},{
__call = function(c,class,data,...)
local new = {}
-- todo: use a better data structure; recycle nexus
new.implies = {} -- Table of all dependency nexus of this class: it.items[0] == c
setmetatable(new,c)
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()
for char in ("abcdefghijklmnopqrstuvwxyz $;"):match(".") do
c.i[char] = c()
c.in = {}
c.out = {}
c.text = {}
c.cookie = c()
for char in ("abcdefghijklmnopqrstuvwxyz "):match(".") do
c.in[char] = c()
c.out[char] = c()
end
local function n(class,data,...)
local this = {up = {},class = class,data = data}
table.insert(c[class],this)
return this
end
local i = {}
setmetatable(i,{__call = function(i,this)
end})
local prev
local previous = n(c(),I)
while true do
prev = n(c[";"],ID,nil)
local input = io.read()
local mode,input = io.read():match("([#P])(.*)")
local t = ({["$"]=c.i,["#"]=c.o})[mode]
if t then
for char in input:match(".") do
if t[char] then
local this = n(t[char],ID,nil)
n(t.next,ID,prev,this)
i(this)
prev = this
for command in input:gmatch([^@]*) do
local name,text = command:match("(%a*)%s*(.*)")
if name == "cookie" then
local cookie = n(c.cookie,I)
n(c.next,I,previous,cookie)
previous = cookie
else
local mode
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
prev = n(t[";"],ID,nil)
end