-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnebbdyrfunction.py
More file actions
28 lines (21 loc) · 849 Bytes
/
Copy pathnebbdyrfunction.py
File metadata and controls
28 lines (21 loc) · 849 Bytes
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
# -*- coding: utf-8 -*-
from environment import Environment
from errors import Return
class NebbdyrFunction:
def __init__(self, declaration, closure):
self.declaration = declaration
self.closure = closure
def call(self, interpreter, arguments):
environment = Environment(self.closure)
for i, parameter in enumerate(self.declaration.parameters):
environment.define(parameter, arguments[i])
try:
interpreter.execute_block(self.declaration.body, environment)
except Return as return_value:
return return_value.value
def Nebbdyr_function(self, declaration):
self.declaration = declaration
def arity(self):
return len(self.declaration.parameters)
def to_string(self):
return "<fn " + self.declaration.name.lexeme + ">"