Module:IC10: Difference between revisions
From Stationeers Wiki
More actions
m added device highlighting and fixed r6-r9 |
m added a bunch more opcodes |
||
| Line 3: | Line 3: | ||
-- List of IC10 opcodes (all strings) | -- List of IC10 opcodes (all strings) | ||
local opcodes = { | local opcodes = { | ||
"add"," | "abs","add","alias","and", | ||
" | "b","beq","beqz","bge","bgez","bgt","blt","bne", | ||
" | "ceil","clrd","clr","define","div","exp","floor", | ||
"move"," | "get","getd","hcf","ins","jr","jal","j","lerp", | ||
" | "l","lb","lbn","lbs","log","ls","lr","max","min", | ||
"s","sb", | "mod","move","mul","not","nor","or","pop","poke", | ||
"yield" | "pow","put","putd","push","peek","rand","round", | ||
"rmap","s","sb","sbn","sbs","select","sla","sll", | |||
"sra","srl","sub","sqrt","trunc","yield", | |||
"sap","sapz","seq","seqz", | |||
"sge","sgez","sgt","sgtz","sle","slez","slt","sltz", | |||
"sna","snan","snanz","snaz","sne","snez" | |||
} | } | ||
Revision as of 05:51, 20 February 2026
local p = {}
-- List of IC10 opcodes (all strings) local opcodes = {
"abs","add","alias","and", "b","beq","beqz","bge","bgez","bgt","blt","bne", "ceil","clrd","clr","define","div","exp","floor", "get","getd","hcf","ins","jr","jal","j","lerp", "l","lb","lbn","lbs","log","ls","lr","max","min", "mod","move","mul","not","nor","or","pop","poke", "pow","put","putd","push","peek","rand","round", "rmap","s","sb","sbn","sbs","select","sla","sll", "sra","srl","sub","sqrt","trunc","yield", "sap","sapz","seq","seqz", "sge","sgez","sgt","sgtz","sle","slez","slt","sltz", "sna","snan","snanz","snaz","sne","snez"
}
-- Build lookup table local opcode_lookup = {} for _, op in ipairs(opcodes) do
opcode_lookup[op] = true
end
local function highlight_line(line)
line = mw.text.nowiki(line)
-- comments
line = string.gsub(line, "(#.*)",
'%1')
-- labels
line = string.gsub(line, "^(%w+:)",
'%1')
-- registers r0–r15
line = string.gsub(line, "%f[%w](r([0-9]|1[0-5]))%f[%W]",
'%1')
-- devices d0–d5
line = string.gsub(line, "%f[%w](d[0-5])%f[%W]",
'%1')
-- numbers hex
line = string.gsub(line, "%f[%w](%-?0x%x+)%f[%W]",
'%1')
-- numbers decimal
line = string.gsub(line, "%f[%w](%-?%d+)%f[%W]",
'%1')
-- opcodes
for op,_ in pairs(opcode_lookup) do
line = string.gsub(line,
"%f[%w]("..op..")%f[%W]",
'%1')
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 '
'
.. table.concat(lines, "\n") ..
''
end
return p