Skip to content

Commit

Permalink
Add new metaprogramming tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kehemo committed Oct 23, 2024
1 parent 2f4df14 commit 4ca7e23
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/exo/frontend/pyparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ def parse_array_indexing(self, node):

def unquote_to_index(unquoted, ref_node, srcinfo, top_level):
if isinstance(unquoted, (int, float)):
return self.AST.Const(unquoted, self.getsrcinfo(e))
return self.AST.Const(unquoted, srcinfo)
elif isinstance(unquoted, ExoExpression) and isinstance(
unquoted._inner, self.AST.expr
):
Expand All @@ -1271,12 +1271,16 @@ def unquote_to_index(unquoted, ref_node, srcinfo, top_level):
(
None
if unquoted.start is None
else unquote_to_index(unquoted.start, False)
else unquote_to_index(
unquoted.start, ref_node, srcinfo, False
)
),
(
None
if unquoted.stop is None
else unquote_to_index(unquoted.stop, False)
else unquote_to_index(
unquoted.stop, ref_node, srcinfo, False
)
),
srcinfo,
)
Expand Down
16 changes: 16 additions & 0 deletions tests/golden/test_metaprogramming/test_quote_complex_expr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// foo(
// a : i32 @DRAM
// )
void foo( void *ctxt, int32_t* a ) {
*a = *a + ((int32_t) 1) + ((int32_t) 1);
}

17 changes: 17 additions & 0 deletions tests/golden/test_metaprogramming/test_quote_elision.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// foo(
// a : i32 @DRAM,
// b : i32 @DRAM
// )
void foo( void *ctxt, const int32_t* a, int32_t* b ) {
*b = *a;
}

18 changes: 18 additions & 0 deletions tests/golden/test_metaprogramming/test_scope_collision1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// foo(
// a : i32 @DRAM
// )
void foo( void *ctxt, int32_t* a ) {
int32_t b;
b = ((int32_t) 2);
*a = ((int32_t) 1);
}

17 changes: 17 additions & 0 deletions tests/golden/test_metaprogramming/test_scope_collision2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// foo(
// a : i32 @DRAM,
// b : i32 @DRAM
// )
void foo( void *ctxt, const int32_t* a, int32_t* b ) {
*b = *a;
}

19 changes: 19 additions & 0 deletions tests/golden/test_metaprogramming/test_statement_assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// foo(
// a : i32 @DRAM
// )
void foo( void *ctxt, int32_t* a ) {
*a += ((int32_t) 1);
*a += ((int32_t) 2);
*a += ((int32_t) 1);
*a += ((int32_t) 2);
}

18 changes: 18 additions & 0 deletions tests/golden/test_metaprogramming/test_type_quote_elision.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// foo(
// a : i8 @DRAM,
// x : i8[2] @DRAM
// )
void foo( void *ctxt, int8_t* a, const int8_t* x ) {
*a += x[0];
*a += x[1];
}

16 changes: 16 additions & 0 deletions tests/golden/test_metaprogramming/test_unquote_elision.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// foo(
// a : i32 @DRAM
// )
void foo( void *ctxt, int32_t* a ) {
*a = *a * ((int32_t) 2);
}

25 changes: 25 additions & 0 deletions tests/golden/test_metaprogramming/test_unquote_in_slice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// bar(
// a : i8[10, 10] @DRAM
// )
void bar( void *ctxt, int8_t* a ) {
for (int_fast32_t i = 0; i < 5; i++) {
foo(ctxt,(struct exo_win_1i8){ &a[(i) * (10) + 2], { 1 } });
}
}

// foo(
// a : [i8][2] @DRAM
// )
void foo( void *ctxt, struct exo_win_1i8 a ) {
a.data[0] += a.data[a.strides[0]];
}

26 changes: 26 additions & 0 deletions tests/golden/test_metaprogramming/test_unquote_index_tuple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// bar(
// a : i8[10, 10, 10] @DRAM
// )
void bar( void *ctxt, int8_t* a ) {
for (int_fast32_t i = 0; i < 7; i++) {
foo(ctxt,(struct exo_win_2i8){ &a[(i) * (100) + (i) * (10) + i + 1], { 10, 1 } });
}
}

// foo(
// a : [i8][2, 2] @DRAM
// )
void foo( void *ctxt, struct exo_win_2i8 a ) {
a.data[0] += a.data[a.strides[1]];
a.data[a.strides[0]] += a.data[a.strides[0] + a.strides[1]];
}

31 changes: 31 additions & 0 deletions tests/golden/test_metaprogramming/test_unquote_slice_object1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "test.h"



#include <stdio.h>
#include <stdlib.h>



// bar(
// a : i8[10, 10] @DRAM
// )
void bar( void *ctxt, int8_t* a ) {
for (int_fast32_t i = 0; i < 10; i++) {
foo(ctxt,(struct exo_win_1i8){ &a[(i) * (10) + 1], { 1 } });
}
for (int_fast32_t i = 0; i < 10; i++) {
foo(ctxt,(struct exo_win_1i8){ &a[(i) * (10) + 5], { 1 } });
}
for (int_fast32_t i = 0; i < 10; i++) {
foo(ctxt,(struct exo_win_1i8){ &a[(i) * (10) + 2], { 1 } });
}
}

// foo(
// a : [i8][2] @DRAM
// )
void foo( void *ctxt, struct exo_win_1i8 a ) {
a.data[0] += a.data[a.strides[0]];
}

Loading

0 comments on commit 4ca7e23

Please sign in to comment.