The wiki has moved!

Visit the new wiki at stationeers-wiki.com The old wiki here at legacy.stationeers-wiki.com will sunset eventually.

Edits made after the 7th of March 6PM EST were NOT carried over to the new server as previously announced right here in this box.

 Actions

Module

Difference between revisions of "IC10"

From Unofficial Stationeers Wiki

m (fixing register highlighting)
m (fixing register highlighting)
Line 46: Line 46:
  
 
     -- real registers r0–r15
 
     -- real registers r0–r15
     line = string.gsub(line, "%f[%w](r(0?[0-9]|1[0-5]))%f[%W]",
+
     line = string.gsub(line, "%f[%w](r([0-9]|1[0-5]))%f[%W]",
 
         '<span style="color:#4fc1ff;">%0</span>')
 
         '<span style="color:#4fc1ff;">%0</span>')
  
 
     -- placeholder r?
 
     -- placeholder r?
     line = string.gsub(line, "%f[%w](r%?)%f[%W]",
+
     line = string.gsub(line, "%f[%w]r%?", '<span style="color:#4fc1ff;">%0</span>')
        '<span style="color:#4fc1ff;">%0</span>')
 
  
 
     -- devices d0–d5 plus d?
 
     -- devices d0–d5 plus d?

Revision as of 01:51, 20 February 2026

Documentation for this module may be created at Module:IC10/doc

local p = {}

-- List of IC10 opcodes (all strings)
local opcodes = {
    "alias","define","hcf","yield",
    "abs","add","ceil","div","pow","exp","floor","log","max","min","mod","move","mul","rand","round","sqrt","sub","trunc","lerp",
    "acos","asin","atan","atan2","cos","sin","tan",
    "clr","clrd","get","getd","peek","poke","pop","push","put","putd",
    "l","lr","ls","s","ss","rmap",
    "lb","lbn","lbns","lbs","sb","sbn","sbs",
    "and","nor","not","or","sla","sll","sra","srl","xor","ext","ins",
    "select","sdns","sdse","sap","sapz","seq","seqz","sge","sgez","sgt","sgtz","sle","slez","slt","sltz","sna","snan","snanz","snaz","sne","snez",
    "j","jal","jr",
    "bdnvl","bdnvs","bdns","bdnsal","bdse","bdseal","brdns","brdse",
    "bap","brap","bapal","bapz","brapz","bapzal",
    "beq","breq","beqal","beqz","breqz","beqzal",
    "bge","brge","bgeal","bgez","brgez","bgezal",
    "bgt","brgt","bgtal","bgtz","brgtz","bgtzal",
    "ble","brle","bleal","blez","brlez","blezal",
    "blt","brlt","bltal","bltz","brltz","bltzal",
    "bna","brna","bnaal","bnan","brnan","bnaz","brnaz","bnazal",
    "bne","brne","bneal","bnez","brnez","bnezal"
}

-- Build lookup table
local opcode_lookup = {}
for _, op in ipairs(opcodes) do
    opcode_lookup[op] = true
end

local function highlight_line(line)
    -- breaks strings in IC10 as it escapes "" line = mw.text.nowiki(line)
    --minimal replacement instead
    line = line
    :gsub("&", "&amp;")
    :gsub("<", "&lt;")
    :gsub(">", "&gt;")

    -- comments
    line = string.gsub(line, "(#.*)",
        '<span style="color:#6a9955;font-style:italic;">%1</span>')

    -- labels
    line = string.gsub(line, "^(%w+:)",
        '<span style="color:#dcdcaa;">%1</span>')

    -- real registers r0–r15
    line = string.gsub(line, "%f[%w](r([0-9]|1[0-5]))%f[%W]",
        '<span style="color:#4fc1ff;">%0</span>')

    -- placeholder r?
    line = string.gsub(line, "%f[%w]r%?", '<span style="color:#4fc1ff;">%0</span>')

    -- devices d0–d5 plus d?
    line = string.gsub(line, "%f[%w](d([0-5]|%?))%f[%W]",
        '<span style="color:#4fc1ff;">%1</span>')

    -- numbers hex
    line = string.gsub(line, "%f[%w](%-?0x%x+)%f[%W]",
        '<span style="color:#b5cea8;">%1</span>')
    -- numbers decimal
    line = string.gsub(line, "%f[%w](%-?%d+)%f[%W]",
        '<span style="color:#b5cea8;">%1</span>')

    -- opcodes
    for op,_ in pairs(opcode_lookup) do
        line = string.gsub(line,
            "%f[%w]("..op..")%f[%W]",
            '<span style="color:#c586c0;font-weight:bold;">%1</span>')
    end

    return line
end

function p.highlight(frame)
    local text = frame.args[1] or ""
    local lines = mw.text.split(text, "\n")

    for i,line in ipairs(lines) do
        lines[i] = highlight_line(line)
    end

    return '<pre style="font-family:monospace; background-color:#f8f9fa; border:1px solid #eaecf0; white-space:pre; display:block; padding:8px;">'
        .. table.concat(lines, "\n") ..
        '</pre>'
end

return p