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