Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit a57562a

Browse files
committed
Add module operator support
1 parent c2b77b7 commit a57562a

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

tc/core/tc2halide.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ Expr translateExpr(
158158
return t(0) * t(1);
159159
case '/':
160160
return t(0) / t(1);
161+
case '%':
162+
return t(0) % t(1);
161163
case lang::TK_MIN:
162164
return min(t(0), t(1));
163165
case lang::TK_MAX:

tc/lang/lexer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace lang {
8787
_(TK_LET, "let", "") \
8888
_(TK_EXISTS, "exists", "exists")
8989

90-
static const char* valid_single_char_tokens = "+-*/()[]?:,={}><!";
90+
static const char* valid_single_char_tokens = "+-*/()[]?:,={}><!%";
9191

9292
enum TokenKind {
9393
// we use characters to represent themselves so skip all valid characters
@@ -137,7 +137,7 @@ struct SharedParserData {
137137
{TK_AND},
138138
{'>', '<', TK_LE, TK_GE, TK_EQ, TK_NE},
139139
{'+', '-'},
140-
{'*', '/'},
140+
{'*', '/', '%'},
141141
};
142142
std::vector<std::vector<int>> unary_ops = {
143143
{'-', '!'},

tc/lang/sema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ struct Sema {
293293
case '-':
294294
case '*':
295295
case '/':
296+
case '%':
296297
case TK_MIN:
297298
case TK_MAX: {
298299
auto nexp =

tc/lang/test_expected/math.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(-
22
(+
33
(+
4-
(- (const 3 (int32)))
4+
(%
5+
(- (const 3 (int32)))
6+
(const 2 (int32)))
57
(*
68
(const 4 (int32))
79
(const 5 (int32))))

test/cuda/test_corner_cases.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ TEST(TestCornerCases, E23) {
285285
at::Scalar(d[0]).toFloat());
286286
}
287287

288+
TEST(TestCornerCases, E24) {
289+
auto a = I();
290+
auto b = I();
291+
auto r = I(0);
292+
Succeed(
293+
"def f(int32 a, int32 b) -> (c) { c(i) = int32(a % b) where i in 0:1 }",
294+
{a, b},
295+
{r});
296+
CHECK_EQ(at::Scalar(r[0]).toInt(), 0);
297+
}
298+
288299
int main(int argc, char** argv) {
289300
::testing::InitGoogleTest(&argc, argv);
290301
::gflags::ParseCommandLineFlags(&argc, &argv, true);

test/test_lang.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int main(int argc, char** argv) {
232232
ASSERT(s->tree(0)->stringValue() == "min");
233233
}
234234
{
235-
std::string stuff = "-3+4*5+7-a";
235+
std::string stuff = "-3%2+4*5+7-a";
236236
Parser p(stuff);
237237
auto r = p.parseExp();
238238
std::stringstream ss;

0 commit comments

Comments
 (0)