1
0
mirror of https://github.com/HybridDog/pdisc.git synced 2024-11-15 23:00:37 +01:00

remove obsolete argument count tests

M  standardbefehlssatz.lua
D  textures/pdisc.png
M  util/standartbefehlssatz_doc.lua
This commit is contained in:
Hybrid Dog 2017-01-12 18:35:11 +01:00
parent 7589a04a9a
commit f566b8b557
3 changed files with 22 additions and 63 deletions

View File

@ -6,9 +6,6 @@ local STRL = "attempt on exceeding maximum string length"
local s local s
s = { s = {
mov = function(params) mov = function(params)
if #params ~= 2 then
return false, WNOA
end
return true, params[2] return true, params[2]
end, end,
@ -18,17 +15,13 @@ s = {
return false, UAT return false, UAT
end end
p = faden.vars[p] p = faden.vars[p]
return true, {p, params[2] and p ~= nil} return true, {p, p ~= nil}
end, end,
add = function(params, faden) add = function(params, faden)
if #params ~= 2 then
return false, WNOA
end
local p1,p2 = unpack(params) local p1,p2 = unpack(params)
local t1 = type(p1) local t1 = type(p1)
local t2 = type(p2) if t1 ~= type(p2) then
if t1 ~= t2 then
return false, "different argument types" return false, "different argument types"
end end
@ -38,16 +31,16 @@ s = {
if t1 == "boolean" then if t1 == "boolean" then
return true, p1 and p2 return true, p1 and p2
end end
if #p1 + #p2 > faden.strlen_max then if t1 == "string" then
return false, STRL if #p1 + #p2 > faden.strlen_max then
return false, STRL
end
return true, p1 .. p2
end end
return true, p1 .. p2 return false, UAT
end, end,
mul = function(params) mul = function(params)
if #params ~= 2 then
return false, WNOA
end
local p1,p2 = unpack(params) local p1,p2 = unpack(params)
local t1 = type(p1) local t1 = type(p1)
local t2 = type(p2) local t2 = type(p2)
@ -72,9 +65,6 @@ s = {
end, end,
neg = function(params) neg = function(params)
if #params ~= 1 then
return false, WNOA
end
local v = params[1] local v = params[1]
local t = type(v) local t = type(v)
if t == "number" then if t == "number" then
@ -83,13 +73,13 @@ s = {
if t == "boolean" then if t == "boolean" then
return true, not v return true, not v
end end
return true, v:rev() if t == "string" then
return true, v:rev()
end
return false, UAT
end, end,
inv = function(params) inv = function(params)
if #params ~= 1 then
return false, WNOA
end
local p = params[1] local p = params[1]
if type(p) ~= "number" then if type(p) ~= "number" then
return false, UAT return false, UAT
@ -98,24 +88,18 @@ s = {
end, end,
mod = function(params) mod = function(params)
if #params ~= 2 then
return false, WNOA
end
local p1,p2 = unpack(params) local p1,p2 = unpack(params)
if type(p1) ~= "number" or type(p2) ~= "number" then if type(p1) ~= "number"
or type(p2) ~= "number" then
return false, UAT return false, UAT
end end
return true, p1 % p2 return true, p1 % p2
end, end,
jmp = function(params, faden) jmp = function(params, faden)
local pcnt = #params if #params >= 2
if pcnt == 2 then and not params[2] then
if not params[2] then return true
return true
end
elseif pcnt ~= 1 then
return false, WNOA
end end
local p = params[1] local p = params[1]
if type(p) ~= "number" then if type(p) ~= "number" then
@ -134,9 +118,6 @@ s = {
end, end,
call = function(params, faden) call = function(params, faden)
if #params ~= 1 then
return false, WNOA
end
local subsucc,msg = s.push(faden.ip + 1, faden) local subsucc,msg = s.push(faden.ip + 1, faden)
if not subsucc then if not subsucc then
return false, SE .. msg return false, SE .. msg
@ -192,20 +173,13 @@ s = {
end, end,
equal = function(params) equal = function(params)
if #params ~= 2 then
return false, WNOA
end
return true, params[1] == params[2] return true, params[1] == params[2]
end, end,
less = function(params) less = function(params)
if #params ~= 2 then
return false, WNOA
end
local p1,p2 = unpack(params) local p1,p2 = unpack(params)
local t1 = type(p1) local t1 = type(p1)
local t2 = type(p2) if t1 ~= type(p2) then
if t1 ~= t2 then
return false, "different argument types" return false, "different argument types"
end end
@ -217,9 +191,6 @@ s = {
end, end,
usleep = function(params, faden) usleep = function(params, faden)
if #params ~= 1 then
return false, WNOA
end
local p = params[1] local p = params[1]
if type(p) ~= "number" then if type(p) ~= "number" then
return false, UAT return false, UAT
@ -230,16 +201,13 @@ s = {
end, end,
sleep = function(params, faden) sleep = function(params, faden)
if #params ~= 1 then
return false, WNOA
end
local p = params[1] local p = params[1]
if type(p) ~= "number" then if type(p) ~= "number" then
return false, UAT return false, UAT
end end
local subsucc,msg = s.usleep({p * 1000000}, faden) local subsucc,msg = s.usleep({p * 1000000}, faden)
if not subsucc then if not subsucc then
return false, SE .. msg error(SE .. msg)
end end
return true return true
end, end,
@ -249,9 +217,6 @@ s = {
end, end,
tostring = function(params) tostring = function(params)
if #params ~= 1 then
return false, WNOA
end
return true, tostring(params[1]) return true, tostring(params[1])
end, end,
@ -273,12 +238,9 @@ local so_math_fcts = {"sin", "asin", "cos", "acos", "tan", "atan", "exp", "log",
for i = 1,#so_math_fcts do for i = 1,#so_math_fcts do
i = so_math_fcts[i] i = so_math_fcts[i]
s[i] = function(params) s[i] = function(params)
if #params ~= 1 then
return false, WNOA
end
local p = params[1] local p = params[1]
if type(p) ~= "number" then if type(p) ~= "number" then
return false, UAT return false, "this arithmetic function needs a number as argument"
end end
return true, math[i](p) return true, math[i](p)
end end
@ -288,13 +250,10 @@ local to_math_fcts = {"pow"}
for i = 1,#to_math_fcts do for i = 1,#to_math_fcts do
i = to_math_fcts[i] i = to_math_fcts[i]
s[i] = function(params) s[i] = function(params)
if #params ~= 2 then
return false, WNOA
end
local p1,p2 = unpack(params) local p1,p2 = unpack(params)
if type(p1) ~= "number" if type(p1) ~= "number"
or type(p2) ~= "number" then or type(p2) ~= "number" then
return false, UAT return false, "this arithmetic function needs 2 numbers as args"
end end
return true, math[i](p1, p2) return true, math[i](p1, p2)
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 B

View File

@ -26,7 +26,7 @@ local instr = {
{"inv", "<vn num>", "num = 1 / num"}, {"inv", "<vn num>", "num = 1 / num"},
{"mod", "<vn num>, <n dv>", "num = num % dv"}, {"mod", "<vn num>, <n dv>", "num = num % dv"},
{"jmp", "<ui p>[, <e c>]", "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."}, {"jmp", "<ui p>[, <e c>]", "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", "<ui p>", "push the ip, then jmp p; used to execute subroutines"}, {"call", "<ui p>[, <e c>]", "push the ip, then jmp p; used to execute subroutines"},
{"ret", "", "pop something, then jmp there; used to exit subroutines"}, {"ret", "", "pop something, then jmp there; used to exit subroutines"},
{"push", "<e a>[, <e b>[, <e c>[…]]]", "put values onto the stack; from left to right"}, {"push", "<e a>[, <e b>[, <e c>[…]]]", "put values onto the stack; from left to right"},
{"pop", "<v a>[, <v b>[, <v c>[…]]]", "takes values from the stack and sets the passed variables to them; from left to right"}, {"pop", "<v a>[, <v b>[, <v c>[…]]]", "takes values from the stack and sets the passed variables to them; from left to right"},