-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmethodMang.py
63 lines (53 loc) · 1.91 KB
/
methodMang.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!python3
from methods import io, data, math, types, functions, control, logic
import tokenz
import interpreter
intp = interpreter.Interpreter()
class UndefinedFunctionError(Exception): pass
def reg(it, c):
it.valid = it.valid + [(c().methods, c())]
class Call:
def __init__(self, method, args, allowBan, doEval=True):
self.method = method
self.a = args
self.de = doEval
self.ab = allowBan
self.vals = []
for t in self.a:
self.vals.append(str(t.val))
self.valid = []
reg(self, io.IO)
reg(self, data.Data)
reg(self, math.Math)
reg(self, types.Types)
reg(self, functions.Functions)
reg(self, control.Control)
reg(self, logic.Logic)
def run(self):
f = False
for m in self.valid:
if self.method in m[0]:
if self.method in m[1].banned and not self.ab:
f = False
break
if self.de:
if self.method != "var":
args2pass = ""
args2pass = " ".join(self.vals)
args2pass = intp.eval(args2pass)
else:
args2pass = ""
args2pass = " ".join(self.vals)
a = tokenz.tokenize(args2pass)
args2pass = intp.eval(tokenz.detokenize(a[1:]))
a[0].type = "ident"
args2pass = [a[0]] + args2pass
else:
args2pass = self.a
return_val = m[1].funcs[m[0].index(self.method)](args2pass)
f = True
break
if not f:
return_val = None
raise UndefinedFunctionError("Attempted to run function %s, but was undefined" % self.method)
return return_val