Exemple #1
0
	def evaluate(self, env):
		try:
			# special-casing builtin functions
			try: return builtins[self.name]
			except KeyError: pass
			closure = env[self.name]
		except KeyError as e:
			#print "evaluating", self, env
			raise UndefinedVariable(e.args[0])
		return closure() # invocate the closure
Exemple #2
0
	def evaluate(self, env):
		function_value = evaluate(self.function_expr, env) # Schauen Sie bitte auf die Methode call in der Klasse function.
		if not isinstance(function_value, tuple):
			raise NotCallable(function_value)
		
		function = function_value[0]
		function_env = function_value[1]
		
		if len(self.act_args) != len(function.args):
			raise WrongNumOfArguments
		
		fenv = dict(function_env)
		if function.name:
			fenv[function.name] = closure(function_value, {})
		fenv.update(zip(function.args, map(lambda a: closure(a, env), self.act_args)))
		#for key in function_env:
		#	fenv[key] = function_env[key]
		
		#print "%s(%s)"%(self.function_expr, ','.join(map(str, evaluate(self.act_args, env))))
		return function.call(fenv)
Exemple #3
0
	def evaluate(self, env): # shall return a structure
		if not self.fields:
			return evaluate(self.value, env)
		else:
			struct = evaluate(self.struct, env)
			if not isinstance(struct, dict):
				#print self.struct, struct, self.fields, self.value
				raise ForvelkiError("unable to update field %s of non-structure %s" % (self.fields[0], self.struct))
			nd = dict(struct)
			fields = deque(self.fields)
			updated_field = fields.popleft()
			next_struct = nd[updated_field]() if updated_field in nd else {}
			nd[updated_field] = closure(field_update(next_struct, fields, self.value), env)
			return evaluate(closed_structure(nd), env) 
Exemple #4
0
	def evaluate(self, env):
		closed = {}
		for key in self:
			closed[key] = closure(self[key], env)
		return closed_structure(closed)
Exemple #5
0
	def call(self, env):
		for assign in self.assigns:
			env[assign.name] = closure(assign.value, env)
		return evaluate(self.expr, env)