def call(self, args, context): self.ensure_args_gt(args, 2) self.ensure_arg_type(args, 0, ast.slist) new_context = eval.context(parent=context, meval_context=context.meval_context) for pair in args[0].lst: self.ensure_type(pair, ast.slist) name = pair.lst[0] self.ensure_type(name, ast.name) code = ast.statement_list(pair.lst[1:]) new_context.set(name.name, code.eval(context)) return ast.statement_list(args[1:]).eval(new_context)
def call(self, args, context): self.ensure_args_gt(args, 2) self.ensure_arg_type(args, 0, ast.name) name = args[0].name value = ast.statement_list(args[1:]).eval(context) context.set(name, value) return value
def call(self, args, context): self.ensure_args_gt(args, 2) self.ensure_arg_type(args, 0, ast.name) name = args[0].name if context.has(name): raise ast.runtime_error("define: cannot redefine variable %s" % name) value = ast.statement_list(args[1:]).eval(context) context.set(name, value) return value
def call(self, args, context): self.ensure_args_gt(args, 3) self.ensure_arg_type(args, 0, ast.name) name = args[0].name self.ensure_arg_type(args, 1, ast.slist) params = args[1].lst body = ast.statement_list(args[2:]) macro = user_defined_macro(params, body, context) context.set(name, macro) return macro
def call(self, args, context): self.ensure_args_gt(args, 2) self.ensure_arg_type(args, 0, ast.slist) code = ast.statement_list(args[1:]) params = [] for elem in args[0].lst: if isinstance(elem, ast.dotted_name): params.append(elem) break self.ensure_type(elem, ast.name) params.append(elem.name) return ast.function(params, code, context)