Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
leissa committed Apr 24, 2024
1 parent 8da1efc commit f4a21a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
24 changes: 10 additions & 14 deletions lit/regex/match_wds.thorin
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
.let Top = ⊤:.Nat;
.let re = %regex.conj 2 (%regex.cls.w, %regex.conj 2 (%regex.cls.d, %regex.cls.s));

.con .extern main[mem: %mem.M, argc: .I32, argv: %mem.Ptr («⊤:.Nat; %mem.Ptr («⊤:.Nat; .I8», 0)», 0), exit : .Cn [%mem.M, .I32]] = {
.con handle_match [mem: %mem.M, matched: .Bool, match: %mem.Ptr(«Top; .I8», 0)] = {

exit (mem, %core.conv.u .i32 matched)
};

.con match_argument[mem: %mem.M, .I32] = {
.let arg1 = %mem.lea (Top, ‹Top; %mem.Ptr («⊤:.Nat; .I8», 0)›, 0) (argv, 1I32);;
.let (`mem, to_match) = %mem.load (mem, arg1);
.let (`mem, matched, pos) = re (mem, to_match, 0:(.Idx Top));
exit (mem, %core.conv.u .i32 matched)
};

.con .extern main[mem: %mem.M, argc: .I32, argv: %mem.Ptr («⊤:.Nat; %mem.Ptr («⊤:.Nat; .I8», 0)», 0), exit : .Cn [%mem.M, .I32]] =
(exit, match_argument) # (%core.icmp.ug (argc, 1I32)) (mem, 0I32)
};
.where
.con handle_match [mem: %mem.M, matched: .Bool, match: %mem.Ptr(«Top; .I8», 0)] =
exit (mem, %core.conv.u .i32 matched);

.con match_argument[mem: %mem.M, .I32] =
.let arg1 = %mem.lea (Top, ‹Top; %mem.Ptr («⊤:.Nat; .I8», 0)›, 0) (argv, 1I32);
.let (`mem, to_match) = %mem.load (mem, arg1);
.let (`mem, matched, pos) = re (mem, to_match, 0:(.Idx Top));
exit (mem, %core.conv.u .i32 matched);
.end
// CHECK-NOT: %regex.
4 changes: 1 addition & 3 deletions src/thorin/ast/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ Ptr<Expr> Parser::parse_decl_expr() {
auto track = tracker();
auto decls = parse_decls();
auto expr = parse_expr("final expression of a declaration expression");
if (expr->isa<ErrorExpr>())
for (const auto& decl : decls) ast().note(decl->loc(), "declaration belonging to this declaration expression");
return ptr<DeclExpr>(track, std::move(decls), std::move(expr), false);
}

Expand All @@ -330,7 +328,7 @@ Ptr<Expr> Parser::parse_lit_expr() {
return ptr<LitExpr>(track, tok, std::move(type));
}

Ptr<Expr> Parser::parse_sigma_expr() { return ptr<SigmaExpr>(parse_tuple_ptrn(false, Dbg(ahead().loc(), Sym()))); }
Ptr<Expr> Parser::parse_sigma_expr() { return ptr<SigmaExpr>(parse_tuple_ptrn(false, Dbg(ahead().loc()))); }

Ptr<Expr> Parser::parse_tuple_expr() {
auto track = tracker();
Expand Down

0 comments on commit f4a21a5

Please sign in to comment.