Skip to content

Commit

Permalink
Reorder visitor method
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani authored Oct 11, 2023
1 parent 1edfd05 commit 1188ff3
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/interpreted/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,22 +409,6 @@ def visit_Module(self, node: Module) -> None:
for stmt in node.body:
self.visit(stmt)

def visit_FunctionDef(self, node: FunctionDef) -> None:
parent_scope = self.scope
function = UserFunction(node, parent_scope, self.globals)

decorators = reversed(node.decorators)

for decorator_node in decorators:
decorator = self.visit(decorator_node.value)

if not isinstance(decorator, Function):
object_type = decorator.__class__.__name__
raise InterpreterError(f"{object_type!r} object is not callable")

function = decorator.call(self, [function])
self.scope.set(node.name, function)

def visit_Import(self, node: Import) -> None:
for alias in node.names:
name = alias.name
Expand Down Expand Up @@ -485,6 +469,22 @@ def visit_ImportFrom(self, node: ImportFrom) -> None:
member = module_scope.get(alias.name)
self.scope.set(name, member)

def visit_FunctionDef(self, node: FunctionDef) -> None:
parent_scope = self.scope
function = UserFunction(node, parent_scope, self.globals)

decorators = reversed(node.decorators)

for decorator_node in decorators:
decorator = self.visit(decorator_node.value)

if not isinstance(decorator, Function):
object_type = decorator.__class__.__name__
raise InterpreterError(f"{object_type!r} object is not callable")

function = decorator.call(self, [function])
self.scope.set(node.name, function)

def visit_Assign(self, node: Assign) -> None:
value = self.visit(node.value)
assert len(node.targets) == 1 # TODO
Expand Down

0 comments on commit 1188ff3

Please sign in to comment.