|- lowky, kind forget what all this does -| || :stacks: ( .arity .1 @stdio.arity @stdio.1 @stdio.2 @jet.arity @jet.1 ) :rule: ( .arity 1 pushsym .1 10 pushsym .arity 1 pushsym .1 33 pushsym .arity 1 pushsym .1 100 pushsym .arity 1 pushsym .1 108 pushsym .arity 1 pushsym .1 114 pushsym .arity 1 pushsym .1 111 pushsym .arity 1 pushsym .1 87 pushsym .arity 1 pushsym .1 32 pushsym .arity 1 pushsym .1 44 pushsym .arity 1 pushsym .1 111 pushsym .arity 1 pushsym .1 108 pushsym .arity 1 pushsym .1 108 pushsym .arity 1 pushsym .1 101 pushsym .arity 1 pushsym .1 72 pushsym .arity 1 pushsym .1 print pushsym done @stdio.arity 2 0 match @stdio.1 write 0 match @stdio.2 $char 0 bind @stdio.arity pop @stdio.1 pop @stdio.2 pop @jet.arity 1 pushsym @jet.1 9 pushsym @jet.arity 1 pushsym @jet.1 105 pushsym @jet.arity 1 pushsym @jet.1 111 pushsym @jet.arity 1 pushsym @jet.1 46 pushsym @jet.arity 1 pushsym @jet.1 119 pushsym @jet.arity 1 pushsym @jet.1 114 pushsym @jet.arity 1 pushsym @jet.1 105 pushsym @jet.arity 1 pushsym @jet.1 116 pushsym @jet.arity 1 pushsym @jet.1 101 pushsym @jet.arity 1 pushsym @jet.1 40 pushsym @jet.arity 1 pushsym @jet.1 115 pushsym @jet.arity 1 pushsym @jet.1 116 pushsym @jet.arity 1 pushsym @jet.1 114 pushsym @jet.arity 1 pushsym @jet.1 105 pushsym @jet.arity 1 pushsym @jet.1 110 pushsym @jet.arity 1 pushsym @jet.1 103 pushsym @jet.arity 1 pushsym @jet.1 46 pushsym @jet.arity 1 pushsym @jet.1 99 pushsym @jet.arity 1 pushsym @jet.1 104 pushsym @jet.arity 1 pushsym @jet.1 97 pushsym @jet.arity 1 pushsym @jet.1 114 pushsym @jet.arity 1 pushsym @jet.1 40 pushsym @jet.arity 1 pushsym @jet.1 116 pushsym @jet.arity 1 pushsym @jet.1 111 pushsym @jet.arity 1 pushsym @jet.1 110 pushsym @jet.arity 1 pushsym @jet.1 117 pushsym @jet.arity 1 pushsym @jet.1 109 pushsym @jet.arity 1 pushsym @jet.1 98 pushsym @jet.arity 1 pushsym @jet.1 101 pushsym @jet.arity 1 pushsym @jet.1 114 pushsym @jet.arity 1 pushsym @jet.1 40 pushsym @jet.arity 1 pushsym @jet.1 122 pushsym @jet.arity 1 pushsym @jet.1 100 pushsym @jet.arity 1 pushsym @jet.1 99 pushsym @jet.arity 1 pushsym @jet.1 104 pushsym @jet.arity 1 pushsym @jet.1 97 pushsym @jet.arity 1 pushsym @jet.1 114 pushsym @jet.arity 1 pushsym @jet.1 41 pushsym @jet.arity 1 pushsym @jet.1 41 pushsym @jet.arity 1 pushsym @jet.1 41 pushsym @jet.arity 1 pushsym @jet.1 10 pushsym done .arity 1 0 match .1 print 0 match .arity 1 1 match .1 $char 1 bind .arity pop .1 pop .arity pop .1 pop .arity 1 pushsym .1 print pushsym @stdio.arity 2 pushsym @stdio.1 write pushsym @stdio.2 $char pushvar done .arity 1 0 match .1 print 0 match .arity pop .1 pop done ) || :: compile module header :: compile stacks :: compile rules :rule id: 0 :: compile run function |:@symbols stacks:| :@symbol as string: $1 |:@symbols: explode $symbol| :@jet: " self\:ensure_stack("@symbol as string") self\:push_string("@symbol as string", $symbol) " |:: get $symbol as string| :@symbols: explode $symbol |:: push to arguments| :arguments: :: move to arguments |:: move to arguments? :@symbol as string: $char| :reversed string: $char |:: move to arguments? :reversed string: $char| :arguments: $char |:: move to arguments| |:: move $depth to arguments| :arguments: $depth :arguments: |:: next rule id? :rule id: $id| :@math: add $id 1 |:: next rule id :@math: $z| :rule id: $z |:: compile stacks :stacks: $stack| :: get $stack as string :: push to arguments :: compile empty stack :: compile stacks |:: compile stacks| |:: compile rules :rule: $more-op-codes?| :: compile header for current rule :: compile bytecode for current rule :: compile footer for current rule :: next rule id :: compile rules |:: compile rules| |:: compile run function| :: compile run header :rule index: 1 :: compile rule tree :: compile run footer |:: compile header for current rule :rule id: $id?| :: print (formatted) :message: "function nova_core\:rule_{%d}()\n" :arguments: $id :arguments: |:: compile bytecode for current rule :rule: ($stack $symbol $depth match)| :: get $symbol as string :: push to arguments :: move $depth to arguments :: get $stack as string :: push to arguments :: compile match operation :: compile bytecode for current rule :compiled rules: (match $depth $symbol $stack) |:: compile bytecode for current rule :rule: ($stack $var $depth bind)| :: get $var as string :: z-encode string :: push to arguments :: move $depth to arguments :: get $stack as string :: push to arguments :: get $var as string :: z-encode string :: push to arguments :: compile bind operation :: compile bytecode for current rule :compiled rules: (bind $depth $var $stack) |:: compile bytecode for current rule :rule: ($stack pop)| :: get $stack as string :: push to arguments :: compile pop operation :: compile bytecode for current rule :compiled rules: (pop $stack) |:: compile bytecode for current rule? :rule: (@jet.arity 1 pushsym @jet.1 $char pushsym)| :@stdio: write $char |:: compile bytecode for current rule :rule: ($stack $symbol pushsym)| :: get $symbol as string :: push to arguments :: get $stack as string :: push to arguments :: compile pushsym operation :: compile bytecode for current rule :compiled rules: (pushsym $symbol $stack) |:: compile bytecode for current rule :rule: ($stack $symbol pushvar)| :: get $symbol as string :: z-encode string :: push to arguments :: get $stack as string :: push to arguments :: compile pushvar operation :: compile bytecode for current rule :compiled rules: (pushvar $symbol $stack) |:: compile bytecode for current rule :rule: done| :: compile done operation |:: compile footer for current rule| :: print (formatted) :message: "end\n" |:: compile empty stack| :: print (formatted) :message: "nova_core.stacks["{}"] = { n = 0 ; }\n" |:: compile match operation| :: print (formatted) :message: "\tif not match(self.stacks["{}"], {%d}, "{}") then return false end\n" |:: compile bind operation| :: print (formatted) :message: "\tlocal {} = peek(self.stacks["{}"], {%d})\n\tif not {} then return false end\n" |:: compile pop operation| :: print (formatted) :message: "\tpop(self.stacks["{}"])\n" |:: compile pushsym operation| :: print (formatted) :message: "\tpush(self.stacks["{}"], "{}")\n" |:: compile pushvar operation| :: print (formatted) :message: "\tpush(self.stacks["{}"], {})\n" |:: compile done operation| :: print (formatted) :message: "\treturn true\n" |:: compile run header| :: print (formatted) :message: " function nova_core\:run() \tlocal run_rules = true \tself\:rule_0() \twhile run_rules do \t\trun_rules = false " |:: compile rule tree :rule index: 0 :rule id: 0?| |:: compile rule tree :rule index: $index :rule id: $index?| :: end rule tree |:: compile rule tree :rule index: $index?| :: compile rule $index :: next rule index :: compile rule tree |:: compile rule 1| :: print (formatted) :message: "\t\tif self\:rule_1() then\n\t\t\trun_rules = true\n" |:: compile rule $n| :: print (formatted) :message: "\t\telseif self\:rule_{%d}() then\n\t\t\trun_rules = true\n" :arguments: $n :arguments: |:: next rule index? :rule index: $index| :@math: add $index 1 |:: next rule index :@math: $z| :rule index: $z |:: end rule tree| :: print (formatted) :message: "\t\tend\n" |:: compile run footer| :: print (formatted) :message: "\tend\nend\nnova_core\:run()\n" |:: z-encode string? :@symbol as string: "!" | :reversed string: "nz" |:: z-encode string? :@symbol as string: """ | :reversed string: "Qz" |:: z-encode string? :@symbol as string: "#" | :reversed string: "hz" |:: z-encode string? :@symbol as string: "$" | :reversed string: "dz" |:: z-encode string? :@symbol as string: "%" | :reversed string: "vz" |:: z-encode string? :@symbol as string: "&" | :reversed string: "az" |:: z-encode string? :@symbol as string: """ | :reversed string: "qz" |:: z-encode string? :@symbol as string: "(" | :reversed string: "LZ" |:: z-encode string? :@symbol as string: ")" | :reversed string: "RZ" |:: z-encode string? :@symbol as string: "*" | :reversed string: "tz" |:: z-encode string? :@symbol as string: "+" | :reversed string: "pz" |:: z-encode string? :@symbol as string: "," | :reversed string: "Cz" |:: z-encode string? :@symbol as string: "-" | :reversed string: "mz" |:: z-encode string? :@symbol as string: "." | :reversed string: "iz" |:: z-encode string? :@symbol as string: "/" | :reversed string: "sz" |:: z-encode string? :@symbol as string: "\:"| :reversed string: "CZ" |:: z-encode string? :@symbol as string: ";" | :reversed string: "SZ" |:: z-encode string? :@symbol as string: ">" | :reversed string: "gz" |:: z-encode string? :@symbol as string: "=" | :reversed string: "ez" |:: z-encode string? :@symbol as string: "<" | :reversed string: "lz" |:: z-encode string? :@symbol as string: "?" | :reversed string: "Iz" |:: z-encode string? :@symbol as string: "@" | :reversed string: "Az" |:: z-encode string? :@symbol as string: "Z" | :reversed string: "ZZ" |:: z-encode string? :@symbol as string: "[" | :reversed string: "MZ" |:: z-encode string? :@symbol as string: "\" | :reversed string: "rz" |:: z-encode string? :@symbol as string: "]" | :reversed string: "NZ" |:: z-encode string? :@symbol as string: "^" | :reversed string: "cz" |:: z-encode string? :@symbol as string: "_" | :reversed string: "uz" |:: z-encode string? :@symbol as string: "`" | :reversed string: "Bz" |:: z-encode string? :@symbol as string: "z" | :reversed string: "zz" |:: z-encode string? :@symbol as string: "{" | :reversed string: "OZ" |:: z-encode string? :@symbol as string: "\|"| :reversed string: "bz" |:: z-encode string? :@symbol as string: "}" | :reversed string: "PZ" |:: z-encode string? :@symbol as string: "~" | :reversed string: "Tz" |:: z-encode string? :@symbol as string: $ch | :reversed string: $ch |:: z-encode string| |:: compile module header| :: print (formatted) :message: " local nova_core = { } nova_core.stacks = { } local function push(stack, value) table.insert(stack, value) stack.n = stack.n + 1 end local function match(stack, depth, value) local index = stack.n - depth if index <= 0 then return false end local tuple = stack[index] if not tuple then return false end return tuple == value end local function peek(stack, depth) local index = stack.n - depth if index <= 0 then return nil end local tuple = stack[index] if not tuple then return nil end return tuple end local function pop(stack) stack.n = stack.n - 1 table.remove(stack) end function nova_core\:fact(stack, ...) local tuple, arity, arity_label, symbol_label_template = {...}, tostring(select("#", ...)), stack .. ".arity", stack .. ".%d" push(self.stacks[arity_label], arity) for i, symbol in ipairs(tuple) do push(self.stacks[symbol_label_template\:format(i)], symbol) end end function nova_core\:take(stack) local tuple = { } local arity_label, symbol_label_template = stack .. ".arity", stack .. ".%d" local arity_stack = self.stacks[arity_label] if arity_stack.n == 0 then return nil end for arity = 1, tonumber(peek(arity_stack, 0)) do local stack = self.stacks[symbol_label_template\:format(arity)] table.insert(tuple, peek(stack, 0)) pop(stack) end pop(self.stacks[arity_label]) return tuple end function nova_core\:take_string(stack) local str = { } local fact = self\:take(stack) while fact do table.insert(str, string.char(tonumber(fact[1]))) fact = self\:take(stack) end return table.concat(str) end function nova_core\:push_string(stack, string) for i = #string, 1, -1 do self\:fact(stack, tostring(string.byte(string\:sub(i, i)))) end end function nova_core\:ensure_stack(stack) if not self.stacks[stack] then self.stacks[stack] = { n = 0 } end end function nova_core\:print_stacks() local stack_names = {} local longest_name = -math.huge for key, _ in pairs(self.stacks) do table.insert(stack_names, key) longest_name = math.max(#key, longest_name) end table.sort(stack_names) for _, stack_name in ipairs(stack_names) do local tuples = { string.rep(" ", longest_name - #stack_name) .. stack_name .. "\:" } local stack = self.stacks[stack_name] for i = stack.n, 1, -1 do table.insert(tuples, "(" .. stack[i] .. ")") end io.stderr\:write(table.concat(tuples, " ")) io.stderr\:write("%\n") end end "