MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
ast.h
Go to the documentation of this file.
1#pragma once
2
3#include <deque>
4#include <memory>
5
6#include <fe/arena.h>
7#include <fe/assert.h>
8#include <fe/cast.h>
9
10#include "mim/driver.h"
11
12#include "mim/ast/tok.h"
13
14namespace mim::ast {
15
16class LamDecl;
17class Module;
18class Scopes;
19class Emitter;
20
21template<class T> using Ptr = fe::Arena::Ptr<const T>;
22template<class T> using Ptrs = std::deque<Ptr<T>>;
23/* */ using Dbgs = std::deque<Dbg>;
24
25struct AnnexInfo {
26 AnnexInfo(Sym sym_plugin, Sym sym_tag, plugin_t id_plugin, tag_t id_tag)
27 : sym{sym_plugin, sym_tag}
28 , id{id_plugin, id_tag, 0, 0} {
29 assert(Annex::mangle(sym_plugin) == id_plugin);
30 }
31
32 bool is_pi() const { return pi && *pi && bool((*pi)->isa<Pi>()); }
33
34 struct {
35 Sym plugin, tag;
36 } sym;
37 struct {
38 plugin_t plugin;
39 tag_t tag;
40 uint8_t curry, trip;
41 } id;
42 std::deque<std::deque<Sym>> subs; ///< List of subs which is a list of aliases.
44 std::optional<const Pi*> pi;
45 bool fresh = true;
46};
47
48class AST {
49public:
50 AST() = default;
52 : world_(&world) {}
53 AST(AST&& other)
54 : AST() {
55 swap(*this, other);
56 }
57 ~AST();
58
59 /// @name Getters
60 ///@{
61 World& world() { return *world_; }
62 Driver& driver() { return world().driver(); }
63 Error& error() { return err_; }
64 const Error& error() const { return err_; }
65 ///@}
66
67 /// @name Sym
68 ///@{
69 Sym sym(const char* s) { return driver().sym(s); }
70 Sym sym(std::string_view s) { return driver().sym(s); }
71 Sym sym(const std::string& s) { return driver().sym(s); }
72 Sym sym_anon() { return sym("_"); } ///< `"_"`.
73 Sym sym_return() { return sym("return"); } ///< `"return"`.
74 Sym sym_error() { return sym("_error_"); } ///< `"_error_"`.
75 ///@}
76
77 template<class T, class... Args> auto ptr(Args&&... args) {
78 return arena_.mk<const T>(std::forward<Args&&>(args)...);
79 }
80
81 /// @name Formatted Output
82 ///@{
83 // clang-format off
84 template<class... Args> Error& error(Loc loc, const char* fmt, Args&&... args) const { return err_.error(loc, fmt, std::forward<Args&&>(args)...); }
85 template<class... Args> Error& warn (Loc loc, const char* fmt, Args&&... args) const { return err_.warn (loc, fmt, std::forward<Args&&>(args)...); }
86 template<class... Args> Error& note (Loc loc, const char* fmt, Args&&... args) const { return err_.note (loc, fmt, std::forward<Args&&>(args)...); }
87 // clang-format on
88 ///@}
89
90 /// @name Manage Annex
91 ///@{
93 const auto& plugin2annexes(Sym plugin) { return plugin2sym2annex_[plugin]; }
94 ///@}
95
96 void bootstrap(Sym plugin, std::ostream& h);
97
98 friend void swap(AST& a1, AST& a2) noexcept {
99 using std::swap;
100 // clang-format off
101 swap(a1.world_, a2.world_);
102 swap(a1.arena_, a2.arena_);
103 swap(a1.err_, a2.err_);
104 // clang-format on
105 }
106
107private:
108 World* world_ = nullptr;
109 fe::Arena arena_;
110 mutable Error err_;
111 absl::node_hash_map<fe::Sym, absl::node_hash_map<fe::Sym, AnnexInfo>> plugin2sym2annex_;
112};
113
114class Node : public fe::RuntimeCast<Node> {
115protected:
117 : loc_(loc) {}
118 virtual ~Node() {}
119
120public:
121 Loc loc() const { return loc_; }
122
123 virtual std::ostream& stream(Tab&, std::ostream&) const = 0;
124 void dump() const;
125
126private:
127 Loc loc_;
128};
129
130class Expr : public Node {
131protected:
133 : Node(loc) {}
134
135public:
136 Ref emit(Emitter&) const;
137 virtual void bind(Scopes&) const = 0;
138 virtual Ref emit_decl(Emitter&, Ref /*type*/) const { fe::unreachable(); }
139 virtual void emit_body(Emitter&, Ref /*decl*/) const { fe::unreachable(); }
140
141private:
142 virtual Ref emit_(Emitter&) const = 0;
143};
144
145class Decl : public Node {
146protected:
148 : Node(loc) {}
149
150public:
151 Ref def() const { return def_; }
152
153protected:
154 mutable Ref def_ = nullptr;
155};
156
157class ValDecl : public Decl {
158protected:
160 : Decl(loc) {}
161
162public:
163 virtual void bind(Scopes&) const = 0;
164 virtual void emit(Emitter&) const = 0;
165};
166
167/*
168 * Ptrn
169 */
170
171class Ptrn : public Decl {
172public:
173 Ptrn(Loc loc, bool rebind, Dbg dbg)
174 : Decl(loc)
175 , dbg_(dbg)
176 , rebind_(rebind) {}
177
178 bool rebind() const { return rebind_; }
179 Dbg dbg() const { return dbg_; }
180
181 virtual void bind(Scopes&, bool quiet = false) const = 0;
182 Ref emit_value(Emitter&, Ref) const;
183 virtual Ref emit_type(Emitter&) const = 0;
184
185 [[nodiscard]] static Ptr<Expr> to_expr(AST&, Ptr<Ptrn>&&);
186 [[nodiscard]] static Ptr<Ptrn> to_ptrn(Ptr<Expr>&&);
187
188private:
189 virtual void emit_value_(Emitter&, Ref) const {}
190
191 Dbg dbg_;
192 bool rebind_;
193};
194
195class ErrorPtrn : public Ptrn {
196public:
198 : Ptrn(loc, false, Dbg()) {}
199
200 void bind(Scopes&, bool quiet = false) const override;
201 Ref emit_type(Emitter&) const override;
202 std::ostream& stream(Tab&, std::ostream&) const override;
203};
204
205/// `dbg: type`
206class IdPtrn : public Ptrn {
207public:
209 : Ptrn(loc, rebind, dbg)
210 , type_(std::move(type)) {}
211
212 const Expr* type() const { return type_.get(); }
213
215 auto loc = type->loc();
216 return ast.ptr<IdPtrn>(loc, false, Dbg(loc, ast.sym_anon()), std::move(type));
217 }
219 auto loc = (type && dbg) ? dbg.loc() + type->loc() : type ? type->loc() : dbg.loc();
220 return ast.ptr<IdPtrn>(loc, false, dbg, std::move(type));
221 }
222
223 void bind(Scopes&, bool quiet = false) const override;
224 Ref emit_type(Emitter&) const override;
225 std::ostream& stream(Tab&, std::ostream&) const override;
226
227private:
228 Ptr<Expr> type_;
229};
230
231/// `dbg_0 ... dbg_n-2 id` where `id` = `dbg_n-1: type`
232class GrpPtrn : public Ptrn {
233public:
234 GrpPtrn(Dbg dbg, const IdPtrn* id)
235 : Ptrn(dbg.loc(), false, dbg)
236 , id_(id) {}
237
238 const IdPtrn* id() const { return id_; }
239
240 void bind(Scopes&, bool quiet = false) const override;
241 Ref emit_type(Emitter&) const override;
242 std::ostream& stream(Tab&, std::ostream&) const override;
243
244private:
245 const IdPtrn* id_;
246};
247
248/// `dbg::(ptrn_0, ..., ptrn_n-1)` or `dbg::[ptrn_0, ..., ptrn_n-1]`
249class TuplePtrn : public Ptrn {
250public:
252 : Ptrn(loc, rebind, dbg)
253 , delim_l_(delim_l)
254 , ptrns_(std::move(ptrns)) {}
255
256 Tok::Tag delim_l() const { return delim_l_; }
257 Tok::Tag delim_r() const { return Tok::delim_l2r(delim_l()); }
258 bool is_paren() const { return delim_l() == Tok::Tag::D_paren_l; }
259 bool is_brckt() const { return delim_l() == Tok::Tag::D_brckt_l; }
260
261 const auto& ptrns() const { return ptrns_; }
262 const Ptrn* ptrn(size_t i) const { return ptrns_[i].get(); }
263 size_t num_ptrns() const { return ptrns().size(); }
264
265 void bind(Scopes&, bool quiet = false) const override;
266 Ref emit_type(Emitter&) const override;
267 Ref emit_decl(Emitter&, Ref type) const;
268 Ref emit_body(Emitter&, Ref decl) const;
269 std::ostream& stream(Tab&, std::ostream&) const override;
270
271private:
272 void emit_value_(Emitter&, Ref) const override;
273
274 Tok::Tag delim_l_;
275 Ptrs<Ptrn> ptrns_;
276};
277
278/*
279 * Expr
280 */
281
282class ErrorExpr : public Expr {
283public:
285 : Expr(loc) {}
286
287 void bind(Scopes&) const override;
288 std::ostream& stream(Tab&, std::ostream&) const override;
289
290private:
291 Ref emit_(Emitter&) const override;
292};
293
294class InferExpr : public Expr {
295public:
297 : Expr(loc) {}
298
299 void bind(Scopes&) const override;
300 std::ostream& stream(Tab&, std::ostream&) const override;
301
302private:
303 Ref emit_(Emitter&) const override;
304};
305
306/// `sym`
307class IdExpr : public Expr {
308public:
310 : Expr(dbg.loc())
311 , dbg_(dbg) {}
312
313 Dbg dbg() const { return dbg_; }
314 const Decl* decl() const { return decl_; }
315
316 void bind(Scopes&) const override;
317 std::ostream& stream(Tab&, std::ostream&) const override;
318
319private:
320 Ref emit_(Emitter&) const override;
321
322 Dbg dbg_;
323 mutable const Decl* decl_ = nullptr;
324};
325
326/// `tag`
327class PrimaryExpr : public Expr {
328public:
330 : Expr(loc)
331 , tag_(tag) {}
333 : PrimaryExpr(tok.loc(), tok.tag()) {}
334
335 Tok::Tag tag() const { return tag_; }
336
337 void bind(Scopes&) const override;
338 std::ostream& stream(Tab&, std::ostream&) const override;
339
340private:
341 Ref emit_(Emitter&) const override;
342
343 Tok::Tag tag_;
344};
345
346/// `tok:type`
347class LitExpr : public Expr {
348public:
350 : Expr(loc)
351 , tok_(tok)
352 , type_(std::move(type)) {}
353
354 Tok tok() const { return tok_; }
355 Tok::Tag tag() const { return tok_.tag(); }
356 const Expr* type() const { return type_.get(); }
357
358 void bind(Scopes&) const override;
359 std::ostream& stream(Tab&, std::ostream&) const override;
360
361private:
362 Ref emit_(Emitter&) const override;
363
364 Tok tok_;
365 Ptr<Expr> type_;
366};
367
368/// `decls e` or `e where decls` if @p where is `true`.
369class DeclExpr : public Expr {
370public:
372 : Expr(loc)
373 , decls_(std::move(decls))
374 , expr_(std::move(expr))
375 , is_where_(is_where) {}
376
377 const auto& decls() const { return decls_; }
378 bool is_where() const { return is_where_; }
379 const Expr* expr() const { return expr_.get(); }
380
381 void bind(Scopes&) const override;
382 std::ostream& stream(Tab&, std::ostream&) const override;
383
384private:
385 Ref emit_(Emitter&) const override;
386
387 Ptrs<ValDecl> decls_;
388 Ptr<Expr> expr_;
389 bool is_where_;
390};
391
392/// `Type level`
393class TypeExpr : public Expr {
394public:
396 : Expr(loc)
397 , level_(std::move(level)) {}
398
399 const Expr* level() const { return level_.get(); }
400
401 void bind(Scopes&) const override;
402 std::ostream& stream(Tab&, std::ostream&) const override;
403
404private:
405 Ref emit_(Emitter&) const override;
406
407 Ptr<Expr> level_;
408};
409
410// lam
411
412/// `dom -> codom`
413class ArrowExpr : public Expr {
414public:
415 ArrowExpr(Loc loc, Ptr<Expr>&& dom, Ptr<Expr>&& codom)
416 : Expr(loc)
417 , dom_(std::move(dom))
418 , codom_(std::move(codom)) {}
419
420private:
421 const Expr* dom() const { return dom_.get(); }
422 const Expr* codom() const { return codom_.get(); }
423
424 void bind(Scopes&) const override;
425 Ref emit_decl(Emitter&, Ref type) const override;
426 void emit_body(Emitter&, Ref decl) const override;
427 std::ostream& stream(Tab&, std::ostream&) const override;
428
429private:
430 Ref emit_(Emitter&) const override;
431
432 Ptr<Expr> dom_;
433 Ptr<Expr> codom_;
434 mutable Pi* decl_ = nullptr;
435};
436
437/// One of:
438/// * ` dom_0 ... dom_n-1 -> codom`
439/// * `Cn dom_0 ... dom_n-1`
440/// * `Fn dom_0 ... dom_n-1 -> codom`
441class PiExpr : public Expr {
442public:
443 class Dom : public Node {
444 public:
446 : Node(loc)
447 , is_implicit_(is_implicit)
448 , ptrn_(std::move(ptrn)) {}
449
450 bool is_implicit() const { return is_implicit_; }
451 const Ptrn* ptrn() const { return ptrn_.get(); }
452 const IdPtrn* ret() const { return ret_.get(); }
453
454 void add_ret(AST& ast, Ptr<Expr>&& type) const {
455 auto loc = type->loc();
456 ret_ = ast.ptr<IdPtrn>(loc, false, Dbg(loc, ast.sym_return()), std::move(type));
457 }
458
459 virtual void bind(Scopes& scopes, bool quiet = false) const;
460 virtual void emit_type(Emitter&) const;
461 std::ostream& stream(Tab&, std::ostream&) const override;
462
463 protected:
464 mutable Pi* pi_ = nullptr;
465 mutable Pi* decl_ = nullptr;
466
467 private:
468 bool is_implicit_;
469 Ptr<Ptrn> ptrn_;
470 mutable Ptr<IdPtrn> ret_;
471
472 friend class PiExpr;
473 };
474
475 PiExpr(Loc loc, Tok::Tag tag, Ptrs<Dom>&& doms, Ptr<Expr>&& codom)
476 : Expr(loc)
477 , tag_(tag)
478 , doms_(std::move(doms))
479 , codom_(std::move(codom)) {
480 assert(num_doms() != 0);
481 }
482
483private:
484 Tok::Tag tag() const { return tag_; }
485 const Ptrs<Dom>& doms() const { return doms_; }
486 const Dom* dom(size_t i) const { return doms_[i].get(); }
487 size_t num_doms() const { return doms_.size(); }
488 const Expr* codom() const { return codom_.get(); }
489
490 void bind(Scopes&) const override;
491 Ref emit_decl(Emitter&, Ref type) const override;
492 void emit_body(Emitter&, Ref decl) const override;
493 std::ostream& stream(Tab&, std::ostream&) const override;
494
495private:
496 Ref emit_(Emitter&) const override;
497
498 Tok::Tag tag_;
499 mutable Ptrs<Dom> doms_;
500 Ptr<Expr> codom_;
501};
502
503/// Wraps a LamDecl as Expr.
504class LamExpr : public Expr {
505public:
507
508 const LamDecl* lam() const { return lam_.get(); }
509
510 void bind(Scopes&) const override;
511 Ref emit_decl(Emitter&, Ref type) const override;
512 void emit_body(Emitter&, Ref decl) const override;
513 std::ostream& stream(Tab&, std::ostream&) const override;
514
515private:
516 Ref emit_(Emitter&) const override;
517
518 Ptr<LamDecl> lam_;
519};
520
521/// `callee arg`
522class AppExpr : public Expr {
523public:
525 : Expr(loc)
526 , is_explicit_(is_explicit)
527 , callee_(std::move(callee))
528 , arg_(std::move(arg)) {}
529
530 bool is_explicit() const { return is_explicit_; }
531 const Expr* callee() const { return callee_.get(); }
532 const Expr* arg() const { return arg_.get(); }
533
534 void bind(Scopes&) const override;
535 std::ostream& stream(Tab&, std::ostream&) const override;
536
537private:
538 Ref emit_(Emitter&) const override;
539
540 bool is_explicit_;
541 Ptr<Expr> callee_;
542 Ptr<Expr> arg_;
543};
544
545/// `ret ptrn = callee $ arg; body`
546class RetExpr : public Expr {
547public:
549 : Expr(loc)
550 , ptrn_(std::move(ptrn))
551 , callee_(std::move(callee))
552 , arg_(std::move(arg))
553 , body_(std::move(body)) {}
554
555 const Ptrn* ptrn() const { return ptrn_.get(); }
556 const Expr* callee() const { return callee_.get(); }
557 const Expr* arg() const { return arg_.get(); }
558 const Expr* body() const { return body_.get(); }
559
560 void bind(Scopes&) const override;
561 std::ostream& stream(Tab&, std::ostream&) const override;
562
563private:
564 Ref emit_(Emitter&) const override;
565
566 Ptr<Ptrn> ptrn_;
567 Ptr<Expr> callee_;
568 Ptr<Expr> arg_;
569 Ptr<Expr> body_;
570};
571// tuple
572
573/// Just wraps TuplePtrn as Expr.
574class SigmaExpr : public Expr {
575public:
577 : Expr(ptrn->loc())
578 , ptrn_(std::move(ptrn)) {}
579
580 const TuplePtrn* ptrn() const { return ptrn_.get(); }
581
582 void bind(Scopes&) const override;
583 Ref emit_decl(Emitter&, Ref type) const override;
584 void emit_body(Emitter&, Ref decl) const override;
585 std::ostream& stream(Tab&, std::ostream&) const override;
586
587private:
588 Ref emit_(Emitter&) const override;
589
590 Ptr<TuplePtrn> ptrn_;
591
593};
594
595/// `(elem_0, ..., elem_n-1)`
596class TupleExpr : public Expr {
597public:
599 : Expr(loc)
600 , elems_(std::move(elems)) {}
601
602 const auto& elems() const { return elems_; }
603 const Expr* elem(size_t i) const { return elems_[i].get(); }
604 size_t num_elems() const { return elems().size(); }
605
606 void bind(Scopes&) const override;
607 std::ostream& stream(Tab&, std::ostream&) const override;
608
609private:
610 Ref emit_(Emitter&) const override;
611
612 Ptrs<Expr> elems_;
613};
614
615/// `«dbg: shape; body»` or `‹dbg: shape; body›`
616template<bool arr> class ArrOrPackExpr : public Expr {
617public:
619 : Expr(loc)
620 , shape_(std::move(shape))
621 , body_(std::move(body)) {}
622
623 const IdPtrn* shape() const { return shape_.get(); }
624 const Expr* body() const { return body_.get(); }
625
626 void bind(Scopes&) const override;
627 std::ostream& stream(Tab&, std::ostream&) const override;
628
629private:
630 Ref emit_(Emitter&) const override;
631
632 Ptr<IdPtrn> shape_;
633 Ptr<Expr> body_;
634};
635
638
639/// `tuple#index`
640class ExtractExpr : public Expr {
641public:
643 : Expr(loc)
644 , tuple_(std::move(tuple))
645 , index_(std::move(index)) {}
647 : Expr(loc)
648 , tuple_(std::move(tuple))
649 , index_(index) {}
650
651 const Expr* tuple() const { return tuple_.get(); }
652 const auto& index() const { return index_; }
653 const Decl* decl() const { return decl_; }
654
655 void bind(Scopes&) const override;
656 std::ostream& stream(Tab&, std::ostream&) const override;
657
658private:
659 Ref emit_(Emitter&) const override;
660
661 Ptr<Expr> tuple_;
662 std::variant<Ptr<Expr>, Dbg> index_;
663 mutable const Decl* decl_ = nullptr;
664};
665
666/// `ins(tuple, index, value)`
667class InsertExpr : public Expr {
668public:
670 : Expr(loc)
671 , tuple_(std::move(tuple))
672 , index_(std::move(index))
673 , value_(std::move(value)) {}
674
675 const Expr* tuple() const { return tuple_.get(); }
676 const Expr* index() const { return index_.get(); }
677 const Expr* value() const { return value_.get(); }
678
679 void bind(Scopes&) const override;
680 std::ostream& stream(Tab&, std::ostream&) const override;
681
682private:
683 Ref emit_(Emitter&) const override;
684
685 Ptr<Expr> tuple_;
686 Ptr<Expr> index_;
687 Ptr<Expr> value_;
688};
689
690/*
691 * Decls
692 */
693
694/// `let ptrn: type = value;`
695class LetDecl : public ValDecl {
696public:
698 : ValDecl(loc)
699 , ptrn_(std::move(ptrn))
700 , value_(std::move(value)) {}
701
702 const Ptrn* ptrn() const { return ptrn_.get(); }
703 const Expr* value() const { return value_.get(); }
704
705 void bind(Scopes&) const override;
706 void emit(Emitter&) const override;
707 std::ostream& stream(Tab&, std::ostream&) const override;
708
709private:
710 Ptr<Ptrn> ptrn_;
711 Ptr<Expr> value_;
712 mutable AnnexInfo* annex_ = nullptr;
713 mutable sub_t sub_;
714};
715
716/// `axm ptrn: type = value;`
717class AxiomDecl : public ValDecl {
718public:
719 class Alias : public Decl {
720 public:
722 : Decl(dbg.loc())
723 , dbg_(dbg) {}
724
725 Dbg dbg() const { return dbg_; }
726
727 void bind(Scopes&, const AxiomDecl*) const;
728 std::ostream& stream(Tab&, std::ostream&) const override;
729
730 private:
731 Dbg dbg_;
732 mutable Dbg full_;
733
734 friend class AxiomDecl;
735 };
736
738 : ValDecl(loc)
739 , dbg_(dbg)
740 , subs_(std::move(subs))
741 , type_(std::move(type))
742 , normalizer_(normalizer)
743 , curry_(curry)
744 , trip_(trip) {}
745
746 Dbg dbg() const { return dbg_; }
747 const auto& subs() const { return subs_; }
748 size_t num_subs() const { return subs_.size(); }
749 const auto& sub(size_t i) const { return subs_[i]; }
750 const Expr* type() const { return type_.get(); }
751 Dbg normalizer() const { return normalizer_; }
752 Tok curry() const { return curry_; }
753 Tok trip() const { return trip_; }
754
755 void bind(Scopes&) const override;
756 void emit(Emitter&) const override;
757 std::ostream& stream(Tab&, std::ostream&) const override;
758
759private:
760 Dbg dbg_;
761 std::deque<Ptrs<Alias>> subs_;
762 Ptr<Expr> type_;
763 Dbg normalizer_;
764 Tok curry_, trip_;
765 mutable AnnexInfo* annex_ = nullptr;
766 mutable Ref mim_type_;
767};
768
769/// `.rec dbg: type = body`
770class RecDecl : public ValDecl {
771public:
773 : ValDecl(loc)
774 , dbg_(dbg)
775 , type_(std::move(type))
776 , body_(std::move(body))
777 , next_(std::move(next)) {}
778
779 Dbg dbg() const { return dbg_; }
780 const Expr* type() const { return type_.get(); }
781 const Expr* body() const { return body_.get(); }
782 const RecDecl* next() const { return next_.get(); }
783
784 void bind(Scopes&) const override;
785 virtual void bind_decl(Scopes&) const;
786 virtual void bind_body(Scopes&) const;
787
788 void emit(Emitter&) const override;
789 virtual void emit_decl(Emitter&) const;
790 virtual void emit_body(Emitter&) const;
791
792 std::ostream& stream(Tab&, std::ostream&) const override;
793
794private:
795 Dbg dbg_;
796 Ptr<Expr> type_;
797 Ptr<Expr> body_;
798 Ptr<RecDecl> next_;
799 mutable AnnexInfo* annex_ = nullptr;
800 mutable sub_t sub_;
801};
802
803/// One of:
804/// * `λ dom_0 ... dom_n-1 -> codom`
805/// * `cn dom_0 ... dom_n-1`
806/// * `fn dom_0 ... dom_n-1 -> codom`
807/// * `lam dbg dom_0 ... dom_n-1 -> codom`
808/// * `con dbg dom_0 ... dom_n-1`
809/// * `fun dbg dom_0 ... dom_n-1 -> codom`
810class LamDecl : public RecDecl {
811public:
812 class Dom : public PiExpr::Dom {
813 public:
815 : PiExpr::Dom(loc, is_implicit, std::move(ptrn))
816 , filter_(std::move(filter)) {}
817
818 const Expr* filter() const { return filter_.get(); }
819
820 void bind(Scopes& scopes, bool quiet = false) const override;
821 Lam* emit_value(Emitter&) const;
822 std::ostream& stream(Tab&, std::ostream&) const override;
823
824 private:
825 Ptr<Expr> filter_;
826 mutable Lam* lam_;
827
828 friend class LamDecl;
829 };
830
833 bool is_external,
834 Dbg dbg,
835 Ptrs<Dom>&& doms,
837 Ptr<Expr>&& body,
839 : RecDecl(loc, dbg, nullptr, std::move(body), std::move(next))
840 , tag_(tag)
841 , is_external_(is_external)
842 , doms_(std::move(doms))
843 , codom_(std::move(codom)) {
844 assert(num_doms() != 0);
845 }
846
847 Tok::Tag tag() const { return tag_; }
848 bool is_external() const { return is_external_; }
849 const Ptrs<Dom>& doms() const { return doms_; }
850 const Dom* dom(size_t i) const { return doms_[i].get(); }
851 size_t num_doms() const { return doms_.size(); }
852 const Expr* codom() const { return codom_.get(); }
853
854 void bind_decl(Scopes&) const override;
855 void bind_body(Scopes&) const override;
856 void emit_decl(Emitter&) const override;
857 void emit_body(Emitter&) const override;
858 std::ostream& stream(Tab&, std::ostream&) const override;
859
860private:
861 Tok::Tag tag_;
862 bool is_external_;
863 Ptrs<Dom> doms_;
864 Ptr<Expr> codom_;
865 mutable AnnexInfo* annex_ = nullptr;
866 mutable sub_t sub_;
867};
868
869/// `cfun dbg dom -> codom`
870class CDecl : public ValDecl {
871public:
873 : ValDecl(loc)
874 , tag_(tag)
875 , dbg_(dbg)
876 , dom_(std::move(dom))
877 , codom_(std::move(codom)) {}
878
879 Dbg dbg() const { return dbg_; }
880 Tok::Tag tag() const { return tag_; }
881 const Ptrn* dom() const { return dom_.get(); }
882 const Expr* codom() const { return codom_.get(); }
883
884 void bind(Scopes&) const override;
885 void emit(Emitter&) const override;
886 std::ostream& stream(Tab&, std::ostream&) const override;
887
888private:
889 Tok::Tag tag_;
890 Dbg dbg_;
891 Ptr<Ptrn> dom_;
892 Ptr<Expr> codom_;
893};
894
895/*
896 * Module
897 */
898
899class Import : public Node {
900public:
902 : Node(loc)
903 , dbg_(dbg)
904 , tag_(tag)
905 , module_(std::move(module)) {}
906
907 Dbg dbg() const { return dbg_; }
908 Tok::Tag tag() const { return tag_; }
909 const Module* module() const { return module_.get(); }
910
911 void bind(Scopes&) const;
912 void emit(Emitter&) const;
913 std::ostream& stream(Tab&, std::ostream&) const;
914
915 friend void swap(Import& i1, Import& i2) noexcept {
916 using std::swap;
917 swap(i1.dbg_, i2.dbg_);
918 swap(i1.tag_, i2.tag_);
919 swap(i1.module_, i2.module_);
920 }
921
922private:
923 Dbg dbg_;
924 Tok::Tag tag_;
925 Ptr<Module> module_;
926};
927
928class Module : public Node {
929public:
931 : Node(loc)
932 , imports_(std::move(imports))
933 , decls_(std::move(decls)) {}
934
935 const auto& implicit_imports() const { return implicit_imports_; }
936 const auto& imports() const { return imports_; }
937 const auto& decls() const { return decls_; }
938
939 void add_implicit_imports(Ptrs<Import>&& imports) const { implicit_imports_ = std::move(imports); }
940
941 void compile(AST&) const;
942 void bind(AST&) const;
943 void bind(Scopes&) const;
944 void emit(AST&) const;
945 void emit(Emitter&) const;
946 std::ostream& stream(Tab&, std::ostream&) const override;
947
948private:
949 mutable Ptrs<Import> implicit_imports_;
950 Ptrs<Import> imports_;
951 Ptrs<ValDecl> decls_;
952};
953
956 return load_plugins(w, Vector<Sym>(plugins.size(), [&](size_t i) { return w.sym(plugins[i]); }));
957}
958inline AST load_plugins(World& w, Sym sym) { return load_plugins(w, View<Sym>({sym})); }
959inline AST load_plugins(World& w, const std::string& plugin) { return load_plugins(w, w.sym(plugin)); }
960
961} // namespace mim::ast
Some "global" variables needed all over the place.
Definition driver.h:17
Error & error(Loc loc, const char *s, Args &&... args)
Definition dbg.h:71
Error & note(Loc loc, const char *s, Args &&... args)
Definition dbg.h:73
Error & warn(Loc loc, const char *s, Args &&... args)
Definition dbg.h:72
A function.
Definition lam.h:103
A dependent function type.
Definition lam.h:11
Helper class to retrieve Infer::arg if present.
Definition def.h:86
This is a thin wrapper for std::span<T, N> with the following additional features:
Definition span.h:28
Keeps track of indentation level.
Definition print.h:195
This is a thin wrapper for absl::InlinedVector<T, N, / A> which in turn is a drop-in replacement for ...
Definition vector.h:16
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:33
const Driver & driver() const
Definition world.h:81
AST(AST &&other)
Definition ast.h:53
World & world()
Definition ast.h:61
friend void swap(AST &a1, AST &a2) noexcept
Definition ast.h:98
Driver & driver()
Definition ast.h:62
auto ptr(Args &&... args)
Definition ast.h:77
AST()=default
Error & error(Loc loc, const char *fmt, Args &&... args) const
Definition ast.h:84
AnnexInfo * name2annex(Dbg dbg, sub_t *)
Definition ast.cpp:14
Sym sym(std::string_view s)
Definition ast.h:70
const auto & plugin2annexes(Sym plugin)
Definition ast.h:93
void bootstrap(Sym plugin, std::ostream &h)
Definition ast.cpp:52
const Error & error() const
Definition ast.h:64
Sym sym_return()
"return".
Definition ast.h:73
Sym sym_anon()
"_".
Definition ast.h:72
Error & note(Loc loc, const char *fmt, Args &&... args) const
Definition ast.h:86
Error & error()
Definition ast.h:63
Sym sym(const char *s)
Definition ast.h:69
Error & warn(Loc loc, const char *fmt, Args &&... args) const
Definition ast.h:85
Sym sym_error()
"_error_".
Definition ast.h:74
Sym sym(const std::string &s)
Definition ast.h:71
AST(World &world)
Definition ast.h:51
callee arg
Definition ast.h:522
AppExpr(Loc loc, bool is_explicit, Ptr< Expr > &&callee, Ptr< Expr > &&arg)
Definition ast.h:524
void bind(Scopes &) const override
Definition bind.cpp:163
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:128
bool is_explicit() const
Definition ast.h:530
const Expr * arg() const
Definition ast.h:532
const Expr * callee() const
Definition ast.h:531
Ref emit_(Emitter &) const override
Definition emit.cpp:245
«dbg: shape; body» or ‹dbg: shape; body›
Definition ast.h:616
const Expr * body() const
Definition ast.h:624
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:140
ArrOrPackExpr(Loc loc, Ptr< IdPtrn > &&shape, Ptr< Expr > &&body)
Definition ast.h:618
const IdPtrn * shape() const
Definition ast.h:623
Ref emit_(Emitter &) const override
Definition emit.cpp:275
void bind(Scopes &) const override
Definition bind.cpp:185
dom -> codom
Definition ast.h:413
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:110
Ref emit_(Emitter &) const override
Definition emit.cpp:188
void emit_body(Emitter &, Ref decl) const override
Definition emit.cpp:183
void bind(Scopes &) const override
Definition bind.cpp:138
Ref emit_decl(Emitter &, Ref type) const override
Definition emit.cpp:181
ArrowExpr(Loc loc, Ptr< Expr > &&dom, Ptr< Expr > &&codom)
Definition ast.h:415
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:160
void bind(Scopes &, const AxiomDecl *) const
Definition bind.cpp:215
axm ptrn: type = value;
Definition ast.h:717
const auto & subs() const
Definition ast.h:747
Tok curry() const
Definition ast.h:752
size_t num_subs() const
Definition ast.h:748
AxiomDecl(Loc loc, Dbg dbg, std::deque< Ptrs< Alias > > &&subs, Ptr< Expr > &&type, Dbg normalizer, Tok curry, Tok trip)
Definition ast.h:737
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:162
void bind(Scopes &) const override
Definition bind.cpp:221
const Expr * type() const
Definition ast.h:750
void emit(Emitter &) const override
Definition emit.cpp:339
Dbg dbg() const
Definition ast.h:746
Dbg normalizer() const
Definition ast.h:751
Tok trip() const
Definition ast.h:753
const auto & sub(size_t i) const
Definition ast.h:749
cfun dbg dom -> codom
Definition ast.h:870
Tok::Tag tag() const
Definition ast.h:880
CDecl(Loc loc, Tok::Tag tag, Dbg dbg, Ptr< Ptrn > &&dom, Ptr< Expr > &&codom)
Definition ast.h:872
const Ptrn * dom() const
Definition ast.h:881
void emit(Emitter &) const override
Definition emit.cpp:458
const Expr * codom() const
Definition ast.h:882
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:213
Dbg dbg() const
Definition ast.h:879
void bind(Scopes &) const override
Definition bind.cpp:322
decls e or e where decls if where is true.
Definition ast.h:369
const Expr * expr() const
Definition ast.h:379
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:95
const auto & decls() const
Definition ast.h:377
Ref emit_(Emitter &) const override
Definition emit.cpp:173
void bind(Scopes &) const override
Definition bind.cpp:130
bool is_where() const
Definition ast.h:378
DeclExpr(Loc loc, Ptrs< ValDecl > &&decls, Ptr< Expr > &&expr, bool is_where)
Definition ast.h:371
Decl(Loc loc)
Definition ast.h:147
Ref def() const
Definition ast.h:151
Ref emit_(Emitter &) const override
Definition emit.cpp:117
void bind(Scopes &) const override
Definition bind.cpp:115
ErrorExpr(Loc loc)
Definition ast.h:284
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:77
void bind(Scopes &, bool quiet=false) const override
Definition bind.cpp:94
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:53
ErrorPtrn(Loc loc)
Definition ast.h:197
Ref emit_type(Emitter &) const override
Definition emit.cpp:68
virtual void emit_body(Emitter &, Ref) const
Definition ast.h:139
virtual void bind(Scopes &) const =0
Expr(Loc loc)
Definition ast.h:132
virtual Ref emit_decl(Emitter &, Ref) const
Definition ast.h:138
virtual Ref emit_(Emitter &) const =0
Ref emit(Emitter &) const
Definition emit.cpp:112
tuple#index
Definition ast.h:640
const Decl * decl() const
Definition ast.h:653
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:147
ExtractExpr(Loc loc, Ptr< Expr > &&tuple, Ptr< Expr > &&index)
Definition ast.h:642
const auto & index() const
Definition ast.h:652
const Expr * tuple() const
Definition ast.h:651
void bind(Scopes &) const override
Definition bind.cpp:195
ExtractExpr(Loc loc, Ptr< Expr > &&tuple, Dbg index)
Definition ast.h:646
Ref emit_(Emitter &) const override
Definition emit.cpp:307
dbg_0 ... dbg_n-2 id where id = dbg_n-1: type
Definition ast.h:232
GrpPtrn(Dbg dbg, const IdPtrn *id)
Definition ast.h:234
void bind(Scopes &, bool quiet=false) const override
Definition bind.cpp:106
Ref emit_type(Emitter &) const override
Definition emit.cpp:75
const IdPtrn * id() const
Definition ast.h:238
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:64
Dbg dbg() const
Definition ast.h:313
IdExpr(Dbg dbg)
Definition ast.h:309
void bind(Scopes &) const override
Definition bind.cpp:113
const Decl * decl() const
Definition ast.h:314
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:76
Ref emit_(Emitter &) const override
Definition emit.cpp:120
dbg: type
Definition ast.h:206
static Ptr< IdPtrn > mk_id(AST &ast, Dbg dbg, Ptr< Expr > &&type)
Definition ast.h:218
static Ptr< IdPtrn > mk_type(AST &ast, Ptr< Expr > &&type)
Definition ast.h:214
IdPtrn(Loc loc, bool rebind, Dbg dbg, Ptr< Expr > &&type)
Definition ast.h:208
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:55
void bind(Scopes &, bool quiet=false) const override
Definition bind.cpp:96
Ref emit_type(Emitter &) const override
Definition emit.cpp:70
const Expr * type() const
Definition ast.h:212
friend void swap(Import &i1, Import &i2) noexcept
Definition ast.h:915
Import(Loc loc, Tok::Tag tag, Dbg dbg, Ptr< Module > &&module)
Definition ast.h:901
void bind(Scopes &) const
Definition bind.cpp:88
Dbg dbg() const
Definition ast.h:907
void emit(Emitter &) const
Definition emit.cpp:47
Tok::Tag tag() const
Definition ast.h:908
const Module * module() const
Definition ast.h:909
std::ostream & stream(Tab &, std::ostream &) const
Definition stream.cpp:41
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:78
InferExpr(Loc loc)
Definition ast.h:296
Ref emit_(Emitter &) const override
Definition emit.cpp:118
void bind(Scopes &) const override
Definition bind.cpp:116
ins(tuple, index, value)
Definition ast.h:667
Ref emit_(Emitter &) const override
Definition emit.cpp:328
InsertExpr(Loc loc, Ptr< Expr > &&tuple, Ptr< Expr > &&index, Ptr< Expr > &&value)
Definition ast.h:669
const Expr * index() const
Definition ast.h:676
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:152
void bind(Scopes &) const override
Definition bind.cpp:205
const Expr * tuple() const
Definition ast.h:675
const Expr * value() const
Definition ast.h:677
Lam * emit_value(Emitter &) const
Definition emit.cpp:410
const Expr * filter() const
Definition ast.h:818
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:189
Dom(Loc loc, bool is_implicit, Ptr< Ptrn > &&ptrn, Ptr< Expr > &&filter)
Definition ast.h:814
void bind(Scopes &scopes, bool quiet=false) const override
Definition bind.cpp:280
One of:
Definition ast.h:810
Tok::Tag tag() const
Definition ast.h:847
void bind_body(Scopes &) const override
Definition bind.cpp:315
bool is_external() const
Definition ast.h:848
const Ptrs< Dom > & doms() const
Definition ast.h:849
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:196
const Expr * codom() const
Definition ast.h:852
void emit_decl(Emitter &) const override
Definition emit.cpp:424
size_t num_doms() const
Definition ast.h:851
void emit_body(Emitter &) const override
Definition emit.cpp:452
void bind_decl(Scopes &) const override
Definition bind.cpp:285
LamDecl(Loc loc, Tok::Tag tag, bool is_external, Dbg dbg, Ptrs< Dom > &&doms, Ptr< Expr > &&codom, Ptr< Expr > &&body, Ptr< RecDecl > &&next)
Definition ast.h:831
const Dom * dom(size_t i) const
Definition ast.h:850
Wraps a LamDecl as Expr.
Definition ast.h:504
Ref emit_decl(Emitter &, Ref type) const override
Definition emit.cpp:236
void emit_body(Emitter &, Ref decl) const override
Definition emit.cpp:237
void bind(Scopes &) const override
Definition bind.cpp:158
Ref emit_(Emitter &) const override
Definition emit.cpp:239
LamExpr(Ptr< LamDecl > &&lam)
Definition ast.cpp:159
const LamDecl * lam() const
Definition ast.h:508
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:126
let ptrn: type = value;
Definition ast.h:695
void bind(Scopes &) const override
Definition bind.cpp:252
const Expr * value() const
Definition ast.h:703
const Ptrn * ptrn() const
Definition ast.h:702
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:179
LetDecl(Loc loc, Ptr< Ptrn > &&ptrn, Ptr< Expr > &&value)
Definition ast.h:697
void emit(Emitter &) const override
Definition emit.cpp:387
tok:type
Definition ast.h:347
Tok tok() const
Definition ast.h:354
const Expr * type() const
Definition ast.h:356
LitExpr(Loc loc, Tok tok, Ptr< Expr > &&type)
Definition ast.h:349
Tok::Tag tag() const
Definition ast.h:355
void bind(Scopes &) const override
Definition bind.cpp:120
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:81
Ref emit_(Emitter &) const override
Definition emit.cpp:156
Module(Loc loc, Ptrs< Import > &&imports, Ptrs< ValDecl > &&decls)
Definition ast.h:930
const auto & decls() const
Definition ast.h:937
void emit(AST &) const
Definition emit.cpp:35
const auto & implicit_imports() const
Definition ast.h:935
void bind(AST &) const
Definition bind.cpp:77
const auto & imports() const
Definition ast.h:936
void compile(AST &) const
Definition ast.cpp:183
void add_implicit_imports(Ptrs< Import > &&imports) const
Definition ast.h:939
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:43
virtual std::ostream & stream(Tab &, std::ostream &) const =0
void dump() const
Definition stream.cpp:32
virtual ~Node()
Definition ast.h:118
Loc loc() const
Definition ast.h:121
Node(Loc loc)
Definition ast.h:116
virtual void emit_type(Emitter &) const
Definition emit.cpp:194
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:114
virtual void bind(Scopes &scopes, bool quiet=false) const
Definition bind.cpp:143
Dom(Loc loc, bool is_implicit, Ptr< Ptrn > &&ptrn)
Definition ast.h:445
const IdPtrn * ret() const
Definition ast.h:452
bool is_implicit() const
Definition ast.h:450
const Ptrn * ptrn() const
Definition ast.h:451
void add_ret(AST &ast, Ptr< Expr > &&type) const
Definition ast.h:454
One of:
Definition ast.h:441
void emit_body(Emitter &, Ref decl) const override
Definition emit.cpp:222
Ref emit_(Emitter &) const override
Definition emit.cpp:224
Ref emit_decl(Emitter &, Ref type) const override
Definition emit.cpp:217
void bind(Scopes &) const override
Definition bind.cpp:148
PiExpr(Loc loc, Tok::Tag tag, Ptrs< Dom > &&doms, Ptr< Expr > &&codom)
Definition ast.h:475
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:120
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:79
Tok::Tag tag() const
Definition ast.h:335
void bind(Scopes &) const override
Definition bind.cpp:117
PrimaryExpr(Loc loc, Tok::Tag tag)
Definition ast.h:329
Ref emit_(Emitter &) const override
Definition emit.cpp:130
PrimaryExpr(Tok tok)
Definition ast.h:332
Ref emit_value(Emitter &, Ref) const
Definition emit.cpp:53
static Ptr< Ptrn > to_ptrn(Ptr< Expr > &&)
Definition ast.cpp:177
virtual Ref emit_type(Emitter &) const =0
bool rebind() const
Definition ast.h:178
static Ptr< Expr > to_expr(AST &, Ptr< Ptrn > &&)
Definition ast.cpp:167
Dbg dbg() const
Definition ast.h:179
Ptrn(Loc loc, bool rebind, Dbg dbg)
Definition ast.h:173
virtual void emit_value_(Emitter &, Ref) const
Definition ast.h:189
virtual void bind(Scopes &, bool quiet=false) const =0
.rec dbg: type = body
Definition ast.h:770
void emit(Emitter &) const override
Definition emit.cpp:393
Dbg dbg() const
Definition ast.h:779
virtual void emit_body(Emitter &) const
Definition emit.cpp:404
virtual void bind_body(Scopes &) const
Definition bind.cpp:278
virtual void emit_decl(Emitter &) const
Definition emit.cpp:398
RecDecl(Loc loc, Dbg dbg, Ptr< Expr > &&type, Ptr< Expr > &&body, Ptr< RecDecl > &&next)
Definition ast.h:772
virtual void bind_decl(Scopes &) const
Definition bind.cpp:267
const Expr * body() const
Definition ast.h:781
const Expr * type() const
Definition ast.h:780
const RecDecl * next() const
Definition ast.h:782
void bind(Scopes &) const override
Definition bind.cpp:261
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:183
ret ptrn = callee $ arg; body
Definition ast.h:546
const Ptrn * ptrn() const
Definition ast.h:555
Ref emit_(Emitter &) const override
Definition emit.cpp:251
const Expr * arg() const
Definition ast.h:557
RetExpr(Loc loc, Ptr< Ptrn > &&ptrn, Ptr< Expr > &&callee, Ptr< Expr > &&arg, Ptr< Expr > body)
Definition ast.h:548
void bind(Scopes &) const override
Definition bind.cpp:168
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:132
const Expr * body() const
Definition ast.h:558
const Expr * callee() const
Definition ast.h:556
Just wraps TuplePtrn as Expr.
Definition ast.h:574
const TuplePtrn * ptrn() const
Definition ast.h:580
void emit_body(Emitter &, Ref decl) const override
Definition emit.cpp:267
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:137
Ref emit_(Emitter &) const override
Definition emit.cpp:268
Ref emit_decl(Emitter &, Ref type) const override
Definition emit.cpp:266
SigmaExpr(Ptr< TuplePtrn > &&ptrn)
Definition ast.h:576
void bind(Scopes &) const override
Definition bind.cpp:175
static constexpr Tok::Tag delim_l2r(Tag tag)
Definition tok.h:132
Tag tag() const
Definition tok.h:169
(elem_0, ..., elem_n-1)
Definition ast.h:596
const Expr * elem(size_t i) const
Definition ast.h:603
void bind(Scopes &) const override
Definition bind.cpp:181
TupleExpr(Loc loc, Ptrs< Expr > &&elems)
Definition ast.h:598
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:138
Ref emit_(Emitter &) const override
Definition emit.cpp:270
const auto & elems() const
Definition ast.h:602
size_t num_elems() const
Definition ast.h:604
dbg::(ptrn_0, ..., ptrn_n-1) or dbg::[ptrn_0, ..., ptrn_n-1]
Definition ast.h:249
void bind(Scopes &, bool quiet=false) const override
Definition bind.cpp:101
bool is_paren() const
Definition ast.h:258
const Ptrn * ptrn(size_t i) const
Definition ast.h:262
Tok::Tag delim_r() const
Definition ast.h:257
Ref emit_type(Emitter &) const override
Definition emit.cpp:77
TuplePtrn(Loc loc, Tok::Tag delim_l, Ptrs< Ptrn > &&ptrns, bool rebind, Dbg dbg)
Definition ast.h:251
Ref emit_decl(Emitter &, Ref type) const
Definition emit.cpp:102
const auto & ptrns() const
Definition ast.h:261
size_t num_ptrns() const
Definition ast.h:263
void emit_value_(Emitter &, Ref) const override
Definition emit.cpp:60
Tok::Tag delim_l() const
Definition ast.h:256
Ref emit_body(Emitter &, Ref decl) const
Definition emit.cpp:79
bool is_brckt() const
Definition ast.h:259
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:66
Type level
Definition ast.h:393
const Expr * level() const
Definition ast.h:399
TypeExpr(Loc loc, Ptr< Expr > &&level)
Definition ast.h:395
Ref emit_(Emitter &) const override
Definition emit.cpp:125
std::ostream & stream(Tab &, std::ostream &) const override
Definition stream.cpp:108
void bind(Scopes &) const override
Definition bind.cpp:114
virtual void bind(Scopes &) const =0
virtual void emit(Emitter &) const =0
ValDecl(Loc loc)
Definition ast.h:159
Definition ast.h:14
std::deque< Dbg > Dbgs
Definition ast.h:23
fe::Arena::Ptr< const T > Ptr
Definition ast.h:21
AST load_plugins(World &, View< Sym >)
Definition ast.cpp:190
std::deque< Ptr< T > > Ptrs
Definition ast.h:22
u8 sub_t
Definition types.h:48
std::string fmt(const char *s, Args &&... args)
Wraps mim::print to output a formatted std:string.
Definition print.h:155
u64 plugin_t
Definition types.h:46
u8 tag_t
Definition types.h:47
Definition span.h:104
static std::optional< plugin_t > mangle(Sym plugin)
Mangles s into a dense 48-bit representation.
Definition plugin.cpp:9
Loc loc() const
Definition dbg.h:146
bool is_pi() const
Definition ast.h:32
std::deque< std::deque< Sym > > subs
List of subs which is a list of aliases.
Definition ast.h:42
std::optional< const Pi * > pi
Definition ast.h:44
struct mim::ast::AnnexInfo::@0 sym
AnnexInfo(Sym sym_plugin, Sym sym_tag, plugin_t id_plugin, tag_t id_tag)
Definition ast.h:26
struct mim::ast::AnnexInfo::@1 id