def _Apply(self, ast): fn_id = ast.function().id if fn_id in self.applies: args = ast.arguments() arity = len(args) return S.Apply(S.Name(fn_id + str(arity)), args) else: return ast
def _If(self, e): self.rewrite_children(e) test = e.test() body = S.Lambda([], e.body()) orelse = S.Lambda([], e.orelse()) e.parameters = [test, body, orelse] return S.Apply(e, [])
def _Apply(self, ast): #This catches the case where a procedure that is being #converted to a closure is recursive. In this case, #we don't make a new closure, we simply call the one #we've already got proc_name = ast.function().id if proc_name in self.env and isinstance(self.env[proc_name], list): return S.Apply(ast.function(), ast.arguments() + self.env[proc_name]) return self.rewrite_children(ast)
def _Apply(self, ast): fn_id = ast.function().id arity = -1 if fn_id in self.applies: args = ast.arguments() arity = len(args) elif fn_id in self.binders: arity = self.arity assert (arity > 0) if arity > 0: return S.Apply(S.Name(fn_id + str(arity)), ast.arguments()) else: return ast
def build_cast(cast_name, args): "Helper function to build cast expressions" return S.Apply(S.Name(cast_name), args)
def _Map(self, ast): args = ast.parameters arity = len(args) - 1 assert (arity > 0) return S.Apply(S.Name('map' + str(arity)), args)