Example #1
0
    def serialize_run_module_implementation(self, stream, operand_kinds,
                                            truth_vectors):
        self.set_stream(stream)

        self.add_include(self.SUPPORT_MODULE)
        self.add_include(self.TYPES_MODULE)
        self.add_include(self.COMPUTING_MODULE)
        self.newline()

        # For each truth vector, generate a run procedure.
        for i, truth_vector in enumerate(truth_vectors):
            if i > 0:
                self.newline()

            self.add_subprogram_signature(
                self.get_run_procedure_name(truth_vector), None, [], [], False)
            self.write('{')
            self.newline()
            with self.indent(self.INDENT):
                call_to_run = ast.Call(
                    ast.VariableUsage(self.ENTRY_POINT_NAME), [
                        op_kind.actuals[op_truth]
                        for op_kind, op_truth in itertools.izip(
                            operand_kinds, truth_vector)
                    ])
                self.handle(
                    ast.Call(ast.VariableUsage(self.ASSERT_PROC_NAME), [
                        ast.Comparison(ast.RelOp.EQ, call_to_run,
                                       ast.LitteralBoolean(truth_vector[-1]))
                    ]))
                self.write(';')
                self.newline()
            self.write('}')
            self.newline()
Example #2
0
    def get_program(self, param):
        temp_name = 'result'
        temp_usage = ast.VariableUsage(temp_name)

        return ast.Program([
            (temp_name, ast.BooleanType),
        ], [
            ast.Assign(temp_usage,
                       ast.Call(ast.VariableUsage('identity'), [param])),
            ast.Return(temp_usage),
        ])
Example #3
0
 def handle_language_specific_operand(self, xoperand):
     self.check_language(xoperand)
     # Languages can process identifiers in a specific way.
     formal_name, remaining_tag = self.format_tree(
         ast.VariableUsage(xoperand.formal_name))
     if remaining_tag:
         self.add_tag(remaining_tag)
     self.write(xoperand.format.format(formal_name=formal_name))
Example #4
0
 def get_operand(self, param):
     return ast.Comparison(self.operator, ast.VariableUsage(param),
                           self.value)
Example #5
0
 def get_operand(self, param):
     return ast.VariableUsage(param)