-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.py
32 lines (27 loc) · 1.02 KB
/
function.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
class Function():
def __init__(self, name, return_type, node):
self.name = name
self.return_type = return_type
self.node = node
def __repr__(self):
return "Function"
__str__ = __repr__
class BuiltinFunctionArguments(Function):
def __init__(self, interpreter, this_object, arguments, node):
self.interpreter = interpreter
self.this_object = this_object
self.arguments = arguments
self.node = node
class BuiltinFunction(Function):
def __init__(self, name, return_type, callback):
Function.__init__(self, name, return_type, None)
self.callback = callback
def call(self, args):
if not isinstance(args, BuiltinFunctionArguments):
raise Exception("BuiltinFunction.call expects args as BuiltinFunctionArguments")
return self.callback(args)
def compare_value(self, other):
return self == other
def __repr__(self):
return "BuiltinFunction[{}]".format(self.name)
__str__ = __repr__