示例#1
0
	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)
示例#2
0
	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
示例#3
0
	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
示例#4
0
	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
示例#5
0
	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)