diff --git a/README.md b/README.md index f84c305..6bf13ff 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,55 @@ true/false: boolean (immediate) $hello nwae: string (immediate) nodolla: either a label is called so (immediate) or it's a variable +``` +Types: + +e anything +v any variable +ve any set variable +s string +vs string variable +n number +vn number variable +ui unsigned integer number +b bool +vn bool variable -How to use this mod: +Instructions: + +mov , Copies from into to. +getvar [, ] Sets varname to the current variable called if it's set. If exists is passed, it's set to a bool indicating whether the variable was set. +add , to += from +add , to = to and from +add , to = to .. from +mul , to *= from +mul , to = to or from +mul , str = str:rep(from) +neg num = -num +neg var = not var +neg str = str:rev() +inv num = 1 / num +mod , num = num % dv +jmp [, ] If c is not false, the instruction pointer is set to p. To disallow infinite loops, the program is interrupted after changing the ip, the mod should then consider restarting it. +call push the ip, then jmp p; used to execute subroutines +ret pop something, then jmp there; used to exit subroutines +push [, [, […]]] put values onto the stack; from left to right +pop [, [, […]]] takes values from the stack and sets the passed variables to them; from left to right +equal , a = a == b +less , a = a < b; after executing, a is a bool +less , a = a < b; less also works for strings +usleep aborts the program for at least floor(max(0, t)) ms +sleep executes usleep with t * 1000000 as argument +get_us_time stores minetest.get_us_time() into to; can be used to measure time differences +tostring var = tostring(var) +print [, [, […]]] adds variables to the log, seperated by \t, \n is added at the end +flush Output the log, this should vary for every mod. +``` + + + +How mods can use this mod: ``` local mylog = print @@ -26,13 +72,13 @@ local function mystart(parsed_code) return true end end, parsed_code) + thread:suscitate() mykeepalive(thread) end mystart(parsed_code) local function mykeepalive(thread) - thread:suscitate() if not thread.stopped then return end diff --git a/standardbefehlssatz.lua b/standardbefehlssatz.lua index b149286..14e255d 100644 --- a/standardbefehlssatz.lua +++ b/standardbefehlssatz.lua @@ -12,6 +12,15 @@ s = { return true, params[2] end, + getvar = function(params, faden) + local p = params[1] + if type(p) ~= "string" then + return false, UAT + end + p = faden.vars[p] + return true, {p, params[2] and p ~= nil} + end, + add = function(params, faden) if #params ~= 2 then return false, WNOA @@ -144,7 +153,7 @@ s = { if not subsucc then return false, SE .. msg end - subsucc,msg = s.jmp({msg}, faden) + subsucc,msg = s.jmp(msg, faden) if not subsucc then return false, SE .. msg end @@ -194,8 +203,14 @@ s = { return false, WNOA end local p1,p2 = unpack(params) - if type(p1) ~= "number" - or type(p2) ~= "number" then + local t1 = type(p1) + local t2 = type(p2) + if t1 ~= t2 then + return false, "different argument types" + end + + if t1 ~= "number" + and t1 ~= "string" then return false, UAT end return true, p1 < p2 diff --git a/util/standartbefehlssatz_doc.lua b/util/standartbefehlssatz_doc.lua new file mode 100644 index 0000000..033a52f --- /dev/null +++ b/util/standartbefehlssatz_doc.lua @@ -0,0 +1,66 @@ +local types = { + {"e", "anything"}, + {"v", "any variable"}, + {"ve", "any set variable"}, + {"s", "string"}, + {"vs", "string variable"}, + {"n", "number"}, + {"vn", "number variable"}, + {"ui", "unsigned integer number"}, + {"b", "bool"}, + {"vn", "bool variable"} +} + +local instr = { + {"mov", ", ", "Copies from into to."}, + {"getvar", "[, ]", "Sets varname to the current variable called if it's set. If exists is passed, it's set to a bool indicating whether the variable was set."}, + {"add", ", ", "to += from"}, + {"add", ", ", "to = to and from"}, + {"add", ", ", "to = to .. from"}, + {"mul", ", ", "to *= from"}, + {"mul", ", ", "to = to or from"}, + {"mul", ", ", "str = str:rep(from)"}, + {"neg", "", "num = -num"}, + {"neg", "", "var = not var"}, + {"neg", "", "str = str:rev()"}, + {"inv", "", "num = 1 / num"}, + {"mod", ", ", "num = num % dv"}, + {"jmp", "[, ]", "If c is not false, the instruction pointer is set to p. To disallow infinite loops, the program is interrupted after changing the ip, the mod should then consider restarting it."}, + {"call", "", "push the ip, then jmp p; used to execute subroutines"}, + {"ret", "", "pop something, then jmp there; used to exit subroutines"}, + {"push", "[, [, […]]]", "put values onto the stack; from left to right"}, + {"pop", "[, [, […]]]", "takes values from the stack and sets the passed variables to them; from left to right"}, + {"equal", ", ", "a = a == b"}, + {"less", ", ", "a = a < b; after executing, a is a bool"}, + {"less", ", ", "a = a < b; less also works for strings"}, + {"usleep", "", "aborts the program for at least floor(max(0, t)) ms"}, + {"sleep", "", "executes usleep with t * 1000000 as argument"}, + {"get_us_time", "", "stores minetest.get_us_time() into to; can be used to measure time differences"}, + {"tostring", "", "var = tostring(var)"}, + {"print", "[, [, […]]]", "adds variables to the log, seperated by \\t, \\n is added at the end"}, + {"flush", "", "Output the log, this should vary for every mod."}, +} + +local mbl = 0 +local mal = 0 +for i = 1,#instr do + local bef = instr[i] + mbl = math.max(#bef[1], mbl) + mal = math.max(#bef[2], mal) +end + +local mtl = 2 + +local o = "Types:\n\n" +for i = 1,#types do + local t = types[i] + o = o .. t[1] .. (" "):rep(mtl - #t[1] + 2) .. t[2] .. "\n" +end + +o = o .. "\n\nInstructions:\n\n" +for i = 1,#instr do + i = instr[i] + o = o .. i[1] .. (" "):rep(mbl - #i[1] + 2) .. i[2] .. (" "):rep(mal - #i[2] + 2) .. i[3] .. "\n" +end + +print(o)