def test_type_tuples():
    t = TypeStruct(scope=scope('T'), is_fully_resolved=True)
    t_star = TypePointer(pointee=t)

    # Simple tuple.
    simplify_type_system_test('(fp, [cast(fp, T*)], cast(fp,T*))',
                              '(fp, [fp], fp)',
                              TypeTuple(members=[TypeFelt(), t, t_star], ))

    # Nested.
    simplify_type_system_test(
        '(fp, (), ([cast(fp, T*)],))', '(fp, (), ([fp],))',
        TypeTuple(members=[
            TypeFelt(),
            TypeTuple(members=[]),
            TypeTuple(members=[t])
        ], ))
Exemple #2
0
def test_type_tuples():
    t = TypeStruct(scope=scope('T'), is_fully_resolved=False)
    t_star = TypePointer(pointee=t)

    # Simple tuple.
    assert simplify_type_system(parse_expr('(fp, [cast(fp, T*)], cast(fp,T*))')) == (
        parse_expr('(fp, [fp], fp)'), TypeTuple(members=[TypeFelt(), t, t_star],)
    )

    # Nested.
    assert simplify_type_system(parse_expr('(fp, (), ([cast(fp, T*)],))')) == (
        parse_expr('(fp, (), ([fp],))'), TypeTuple(
            members=[
                TypeFelt(),
                TypeTuple(members=[]),
                TypeTuple(members=[t])],
        )
    )
 def visit_ExprTuple(self, expr: ExprTuple) -> Tuple[ExprTuple, TypeTuple]:
     args = expr.members.args
     # Call visit on each member to obtain a list of the form (expr, type).
     member_expr_types = [self.visit(arg.expr) for arg in args]
     result_members = [
         dataclasses.replace(arg, expr=expr)
         for arg, (expr, _) in zip(args, member_expr_types)
     ]
     result_expr = dataclasses.replace(expr,
                                       members=dataclasses.replace(
                                           expr.members,
                                           args=result_members))
     cairo_type = TypeTuple(
         members=[expr_type for expr, expr_type in member_expr_types],
         location=expr.location)
     return result_expr, cairo_type
 def visit_ExprTuple(self, expr: ExprTuple) -> Tuple[Expression, CairoType]:
     args = expr.members.args
     member_expr_types = [
         self.visit(cast(ExprAssignment, arg).expr) for arg in args
     ]
     result_members = [
         dataclasses.replace(arg, expr=expr)
         for arg, (expr, _) in zip(args, member_expr_types)
     ]
     result_expr = dataclasses.replace(expr,
                                       members=dataclasses.replace(
                                           expr.members,
                                           args=result_members))
     cairo_type = TypeTuple(
         members=[expr_type for expr, expr_type in member_expr_types],
         location=expr.location)
     return result_expr, cairo_type
Exemple #5
0
 def type_tuple(self, value, meta):
     return TypeTuple(members=value, location=self.meta2loc(meta))
Exemple #6
0
def test_type_tuple():
    typ = parse_type('(felt)')
    assert typ == TypeTuple(members=[TypeFelt()])
    assert typ.format() == '(felt)'
    assert parse_type('( felt, felt* , (felt, T.S,)* )').format(
    ) == '(felt, felt*, (felt, T.S)*)'