From 144d50fc0391841d167bf44591c75f9ba224e482 Mon Sep 17 00:00:00 2001 From: paladin Date: Fri, 26 Jun 2026 03:13:17 +0100 Subject: [PATCH] Wiped; Added nexus, classes, dependency heuristic, dependency solver shell, main loop /w commands --- main.lua | 117 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 32 deletions(-) diff --git a/main.lua b/main.lua index a63d4a0..0b058a7 100644 --- a/main.lua +++ b/main.lua @@ -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