def strong_eval_value(self, value): if value.is_thunk(): for v in self.strong_eval_expression(value.expr, value.env): yield v elif value.is_integer_constant(): yield value elif value.is_closure(): yield value elif value.is_primitive(): for part in self.strong_eval_expression(value.args): yield values.Primitive(value.name, vargs) elif value.is_rigid_structure(): for vargs in self.strong_eval_values(value.args): yield values.RigidStructure(value.constructor, vargs) elif value.is_flex_structure(): for vargs in self.strong_eval_values(value.args): if value.is_decided(): yield values.FlexStructure(value.symbol, vargs) else: for v in self.apply_many(value.symbol.representative(), vargs): yield from self.strong_eval_value(v) else: raise Exception( 'Strong evaluation not implemented for {cls}.'.format( cls=type(value)))
def eval_variable_or_constructor(self, expr, env): if env.is_defined(expr.name): yield from self.eval_defined_variable_or_constructor(expr, env) else: yield ( values.RigidStructure(expr.name, []) if expr.name in self._constructors else values.Primitive(expr.name, []) if expr.name in self._primitives else exception_with( 'Name {name} is not a variable nor a constructor.'.format( name=expr.name)))
def apply_primitive(self, value, varg): assert value.name in self._primitives vargs = value.args + [varg] if len(vargs) < self._primitives[value.name].arity: yield values.Primitive(value.name, vargs) return yield from ( self.primitive_sequence(*vargs) if value.name == common.OP_SEQUENCE else self.primitive_alternative(*vargs) if value.name == common.OP_ALTERNATIVE else self.primitive_unify( *vargs) if value.name == common.OP_UNIFY else exception_with( 'Primitive "{name}" not implemented.'.format( name=value.name)))
def eval_variable_or_constructor(self, expr, env): if env.is_defined(expr.name): value0 = env.value(expr.name) for value in self.eval_value(value0): env.set(expr.name, value) yield value env.set(expr.name, value0) elif expr.name in self._constructors: yield values.RigidStructure(expr.name, []) elif expr.name in self._primitives: yield values.Primitive(expr.name, []) else: raise Exception( 'Name {name} is not a variable nor a constructor.'.format( name=expr.name))
def strong_eval_primitives(self, value): for vargs in self.strong_eval_values(value.args): yield values.Primitive(value.name, vargs)