def compute(self, env: Environment): x, y = self.x.evaluate(env), self.y.evaluate(env) func: function.FunctionObj = env.find_function('!') new_env = arrange_params_with_function_args([function.Param('x', x)], func, env) ret = func.compute(new_env) return ret
def compute(self, env: Environment): e = self.e.evaluate(env) func: function.FunctionObj = env.find_function('-') new_env = arrange_params_with_function_args([function.Param('e1', e)], func, env) ret = func.compute(new_env) return ret
def evaluate(self, env: Environment): e1, e2 = self.e1.evaluate(env), self.e2.evaluate(env) func: function.FunctionObj = env.find_function('^') ret = func.compute( [function.Param('e1', e1), function.Param('e2', e2)], env) return ret
def compute(self, env: Environment): e1, e2 = self.e1.evaluate(env), self.e2.evaluate(env) func: function.FunctionObj = env.find_function(self.op_name) new_env = arrange_params_with_function_args( [function.Param('e1', e1), function.Param('e2', e2)], func, env) ret = func.compute(new_env) return ret
def compute(self, env: Environment): if self.base_obj.get_type().name == 'symbol': fun: FunctionObj = env.find_function(self.base_obj.name) else: fun: FunctionObj = self.base_obj.evaluate(env) if not isinstance(fun, FunctionObj): raise errors.ApplyToNonFunction() args = [] assg_obj = RObj.get_r_obj('AssignObj') for item in self.items: # item_val = item.evaluate(env) if isinstance(item, DotsObj): args.extend(item.items) elif isinstance(item, Atomic): n = VectorObj.create([VectorItem(None, item)]) args.append(Param(None, n)) elif isinstance(item, assg_obj): if item.mode == 'plain': if item.item.get_type().name == 'symbol': name = item.item.name elif isinstance(item.item, Atomic): if item.item.get_type().name == 'character': name = item.item[0] else: raise errors.InvalidLeftHandAssignment() else: raise errors.InvalidLeftHandAssignment() arg = Param(name, item.value.evaluate(env)) args.append(arg) else: arg = Param(None, item.evaluate(env)) args.append(arg) else: arg = Param(None, item.evaluate(env)) args.append(arg) try: ret = fun.compute(args, env) except errors.R_RuntimeError as e: r = RError(self, e.message) if not self.exception_occurred(r): raise r return ret
def evaluate(self, env: Environment): fun_to_find = '<-' if isinstance(self.item, DLRObj): fun_to_find = '$<-' elif isinstance(self.item, AssignObj): fun_to_find = '[<-' elif isinstance(self.item, SuperAssignObj): fun_to_find = '[[<-' func: function.FunctionObj = env.find_function( fun_to_find, self.item.get_classes_as_python_list()) new_env = arrange_params_with_function_args([ function.Param('x', self.item), function.Param('value', self.value) ], func, env) ret = func.compute(new_env) return ret
def evaluate(self, env: Environment): standart_for_env = env.standart_output env.standart_output = self.standard_output try: for item in self.items: res = execute_item(item, env) self.standard_output(res.show_self()) except CommandException as e: self.standard_output(e.message) except R_RuntimeError as e: self.standard_output(e.message) except RError as e: func = env.find_function('print') try: arrange_params_with_function_args([Param('x', e)], func, env) except Exception as e: self.standard_output(str(e)) finally: env.standart_output = standart_for_env return None
def evaluate(self, env: Environment): if self.as_from_lang: try: return self.base_obj.compute(env) except errors.R_RuntimeError as e: r = RError.create_simple(self, e.message) if not self.exception_occurred(r): raise r if self.base_obj.get_type().name == 'symbol': fun: FunctionObj = env.find_function(self.base_obj.name) if not isinstance(fun, FunctionObj): raise RError.create_simple(self, errors.ApplyToNonFunction().message) else: fun: FunctionObj = self.base_obj.evaluate(env) if not isinstance(fun, FunctionObj): raise errors.ApplyToNonFunction() args = [] assg_obj = RObj.get_r_obj('AssignObj') for item in self.items: if isinstance(item, DotsObj): args.extend(item.items) elif isinstance(item, Atomic): n = VectorObj.create([VectorItem(None, item)]) args.append(Param(None, n)) elif isinstance(item, assg_obj): if item.item.get_type().name == 'symbol': name = item.item.name elif isinstance(item.item, Atomic): if item.item.get_type().name == 'character': name = item.item[0] else: raise RError.create_simple( self, errors.InvalidLeftHandAssignment().message) else: raise RError.create_simple( self, errors.InvalidLeftHandAssignment().message) arg = Param(name, item.value.evaluate(env)) args.append(arg) else: arg = Param(None, item.evaluate(env)) args.append(arg) # if item.mode == 'plain': # if item.item.get_type().name == 'symbol': # name = item.item.name # elif isinstance(item.item, Atomic): # if item.item.get_type().name == 'character': # name = item.item[0] # else: # raise errors.InvalidLeftHandAssignment() # else: # raise errors.InvalidLeftHandAssignment() # arg = Param(name, item.value.evaluate(env)) # args.append(arg) # else: # arg = Param(None, item.evaluate(env)) # args.append(arg) # else: # arg = Param(None, item.evaluate(env)) # args.append(arg) try: res = func_args_arrange(args, fun.input_args) new_env: Environment = Environment(env) for name, val in res.items(): new_env.add(name, val) ret = fun.compute(new_env) return ret except errors.R_RuntimeError as e: r = RError.create_simple(self, e.message) if not self.exception_occurred(r): raise r
def evaluate(self, env: Environment): e = self.e.evaluate(env) func: function.FunctionObj = env.find_function('-') ret = func.compute([function.Param('e1', e)], env) return ret
def evaluate(self, env: Environment): x, y = self.x.evaluate(env), self.y.evaluate(env) func: function.FunctionObj = env.find_function('!') ret = func.compute([function.Param('x', x)], env) return ret