Example #1
0
 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)))
Example #2
0
 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)))
Example #3
0
 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))
Example #4
0
 def apply_rigid(self, value, varg):
     yield values.RigidStructure(value.constructor, value.args + [varg])
Example #5
0
 def strong_eval_rigid_strutures(self, value):
     for vargs in self.strong_eval_values(value.args):
         yield values.RigidStructure(value.constructor, vargs)