MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::ast Namespace Reference

Classes

class  AliasDecl
 anx dbg = path; - a compiler-exposed alias sharing its target's annex slot. More...
class  AliasPtrn
 ptrn as dbg More...
struct  AnnexInfo
 Bookkeeping of an annex introduced by an AxmDecl. More...
class  AppExpr
 callee arg More...
class  AST
 Owns the arena all AST nodes live in as well as the AnnexInfos of all plugins. More...
class  AxmDecl
 axm dbg: type, normalizer, curry, trip; More...
struct  Bind
 One name in a Scope: the Decl it introduces and the Vis of this binding. More...
class  Decl
 Base class of all declarations; caches the emitted Decl::def. More...
class  DeclExpr
 decls expr or expr where decls if DeclExpr::is_where. More...
class  DummyDecl
class  Emitter
class  ErrorExpr
 Erroneous expression. More...
class  ErrorPtrn
 Erroneous pattern. More...
class  Expr
 Base class of all expressions. More...
class  File
 The AST of one source file: an anonymous ModDecl that a UseDecl binds under a name of its own. More...
class  GrpPtrn
 dbg of a group dbg_0 ... dbg_n-1: type that refers to the trailing IdPtrn::id. More...
class  HoleExpr
 ? More...
class  IdPtrn
 dbg: type More...
class  InfixExpr
 lhs op rhs; InfixExpr::op picks the meaning - see MIM_INFIX. More...
class  LamDecl
 tag dbg dom_0 ... dom_n-1: codom = body; with LamDecl::tag lam/con/fun or anonymous λ/cn/fn. More...
class  LamExpr
 Wraps a LamDecl as Expr. More...
class  LetDecl
 let ptrn = value; More...
class  Lexer
class  LitExpr
 tok:type More...
class  MatchExpr
 match scrutinee with | arm_0 | ... | arm_n-1 More...
class  ModDecl
 mod dbg { decls }; also the base of the anonymous File. More...
struct  Mods
 Raw, unvalidated combination of priv/pub/extern/anx modifiers written before a declaration. More...
class  Node
 Base class of all AST nodes. More...
class  Parser
 Parses Mim code as AST. More...
class  Path
 dbg_0.....dbg_n-1. More...
class  PathExpr
 path More...
class  PiExpr
 dom → codom, Cn dom, or Fn dom → codom depending on PiExpr::tag. More...
class  PrimaryExpr
 tag More...
class  Ptrn
 Base class of all patterns. More...
struct  R
class  RecDecl
 rec dbg = body; with an optional and RecDecl::next. More...
class  RetExpr
 ret ptrn = callee $ arg; body More...
class  RuleDecl
 rule dbg var: lhs when guard => rhs; or norm instead of rule if RuleDecl::is_normalizer. More...
class  RuleExpr
 Rule dom More...
struct  S
class  Scopes
class  SeqExpr
 «arity; body» or ‹arity; body› if SeqExpr::is_pack. More...
class  SigmaExpr
 Wraps a TuplePtrn as Expr. More...
class  Tok
class  TupleExpr
 (elem_0, ..., elem_n-1) More...
class  TuplePtrn
 (ptrn_0, ..., ptrn_n-1), [ptrn_0, ..., ptrn_n-1], or {ptrn_0, ..., ptrn_n-1} More...
class  TypeExpr
 Type level More...
class  UniqExpr
 ⦃inhabitant⦄ More...
class  UseDecl
 import "file"|name [as alias|*];, plugin name [as alias|*];, or use path [as alias|*]; as * splices instead of naming; a use without an as is sugar for as *. More...
class  ValDecl
 Base class of all declarations that bind values. More...

Typedefs

template<class T>
using Ptr = fe::Arena::Ref<const T>
 Nodes live in the AST's Arena and are never destroyed, so this merely points at one.
using Scope = fe::SymMap<Bind>
 Maps a name to the Binding introducing it.
using Tag = Tok::Tag
Ptrs/Dbgs

Scratch buffers the Parser fills before it creates a node; a node keeps its own lists right behind itself - see fe::VLA - and hands them out as a fe::View.

template<class T>
using Ptrs = fe::Vector<Ptr<T>>
using Dbgs = fe::Vector<Dbg>

Enumerations

enum class  Vis {
  Priv ,
  Pub
}
 Visibility tier of a ValDecl. More...
enum class  Assoc {
  N ,
  L ,
  R
}
 Associativity of an infix expression. More...
enum class  Prec
 Expression precedences used by the parser and the dumper; ordered low to high. More...

Functions

AST load_plugins (World &, fe::View< std::string >)
AST load_plugin (World &w, std::string_view plugin)
constexpr Assoc prec_assoc (Prec p)
 Associativity of precedence level p.
constexpr bool is_rassoc (Prec p)
constexpr bool is_lassoc (Prec p)
constexpr bool should_reduce (Prec curr, Prec op)
 Should a Pratt parser reduce when the current binding power is curr and the infix operator has precedence op?
static std::optional< nat_tisa_math_f (Emitter &e, const Def *type)
 If type is a math.F type of known precision/exponent, yields its bit width.
static u64 encode_f (Emitter &e, Loc loc, const Def *t, u64 bits)
 A float Tok stores its value as mim::f64 bits; re-encode them for the width of the annotated type t.
static void emit_union (Emitter &e, const Expr *expr, DefVec &types)
 a ∪ b ∪ c is one n-ary Join, so flatten the left spine the left-associative parse built.
static Tok negate (Tok tok)
 Applies a leading - to a numeric literal Tok.
template<class T>
static void stream_decls (fe::Tab &tab, std::ostream &os, fe::View< Ptr< T > > decls)
static std::string_view vis2str (Vis vis)
static std::ostream & operator<< (std::ostream &os, const Mods &mods)
 Prints vis/extern/anx, skipping vis if it's the modifier-nudged Mods::default_vis.
std::ostream operator
std::ostream & operator<< (std::ostream &os, Tok tok)

Variables

constexpr size_t Look_Ahead = 2
constexpr auto Num_Keys = size_t(0) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1)
constexpr auto Num_Subst = size_t(0) + size_t(1) + size_t(1) + size_t(1)

Class Documentation

◆ mim::ast::Bind

struct mim::ast::Bind

One name in a Scope: the Decl it introduces and the Vis of this binding.

A splicing UseDecl re-binds someone else's Decl under its own Vis, so Vis belongs here and not to the Decl.

Definition at line 45 of file ast.h.

Class Members
const Decl * decl
Vis vis

Typedef Documentation

◆ Dbgs

using mim::ast::Dbgs = fe::Vector<Dbg>

Definition at line 34 of file ast.h.

◆ Ptr

template<class T>
using mim::ast::Ptr = fe::Arena::Ref<const T>

Nodes live in the AST's Arena and are never destroyed, so this merely points at one.

Definition at line 26 of file ast.h.

◆ Ptrs

template<class T>
using mim::ast::Ptrs = fe::Vector<Ptr<T>>

Definition at line 33 of file ast.h.

◆ Scope

using mim::ast::Scope = fe::SymMap<Bind>

Maps a name to the Binding introducing it.

Definition at line 50 of file ast.h.

◆ Tag

Definition at line 9 of file bind.cpp.

Enumeration Type Documentation

◆ Assoc

enum class mim::ast::Assoc
strong

Associativity of an infix expression.

Enumerator

Definition at line 47 of file tok.h.

◆ Prec

enum class mim::ast::Prec
strong

Expression precedences used by the parser and the dumper; ordered low to high.

Definition at line 50 of file tok.h.

◆ Vis

enum class mim::ast::Vis
strong

Visibility tier of a ValDecl.

Priv is only visible inside its enclosing mod; Pub is visible via a path/use from outside. Orthogonal to this, a ValDecl may independently be extern (Decl::is_extern) and/or anx (Decl::is_anx); either one nudges the default visibility to Pub unless priv is given explicitly.

Enumerator
Priv 
Pub 

Definition at line 41 of file ast.h.

Function Documentation

◆ emit_union()

void mim::ast::emit_union ( Emitter & e,
const Expr * expr,
DefVec & types )
static

a ∪ b ∪ c is one n-ary Join, so flatten the left spine the left-associative parse built.

Definition at line 271 of file emit.cpp.

References mim::ast::Expr::emit(), emit_union(), and mim::ast::InfixExpr::isa_op().

Referenced by mim::ast::InfixExpr::emit_(), and emit_union().

◆ encode_f()

u64 mim::ast::encode_f ( Emitter & e,
Loc loc,
const Def * t,
u64 bits )
static

A float Tok stores its value as mim::f64 bits; re-encode them for the width of the annotated type t.

Definition at line 217 of file emit.cpp.

References encode_f(), and isa_math_f().

Referenced by mim::ast::LitExpr::emit_(), and encode_f().

◆ is_lassoc()

bool mim::ast::is_lassoc ( Prec p)
constexpr

Definition at line 68 of file tok.h.

References is_lassoc(), L, and prec_assoc().

Referenced by is_lassoc().

◆ is_rassoc()

bool mim::ast::is_rassoc ( Prec p)
constexpr

Definition at line 67 of file tok.h.

References is_rassoc(), prec_assoc(), and R.

Referenced by is_rassoc(), and should_reduce().

◆ isa_math_f()

std::optional< nat_t > mim::ast::isa_math_f ( Emitter & e,
const Def * type )
static

If type is a math.F type of known precision/exponent, yields its bit width.

Note that libmim must not depend on the generated math plugin header, so lookup the Axm at runtime instead.

Definition at line 204 of file emit.cpp.

References mim::App::callee(), and isa_math_f().

Referenced by encode_f(), and isa_math_f().

◆ load_plugin()

AST mim::ast::load_plugin ( World & w,
std::string_view plugin )
inline

Definition at line 1228 of file ast.h.

References load_plugin(), and load_plugins().

Referenced by load_plugin().

◆ load_plugins()

AST mim::ast::load_plugins ( World & world,
fe::View< std::string > plugins )

◆ negate()

Tok mim::ast::negate ( Tok tok)
static

Applies a leading - to a numeric literal Tok.

Definition at line 369 of file parser.cpp.

References mim::ast::Tok::lit_i(), mim::ast::Tok::lit_u(), mim::ast::Tok::loc(), negate(), and mim::ast::Tok::tag().

Referenced by negate().

◆ operator<<() [1/2]

std::ostream & mim::ast::operator<< ( std::ostream & os,
const Mods & mods )
static

Prints vis/extern/anx, skipping vis if it's the modifier-nudged Mods::default_vis.

Definition at line 203 of file stream.cpp.

References mim::ast::Mods::default_vis(), mim::ast::Mods::is_anx, mim::ast::Mods::is_extern, operator<<(), mim::ast::Mods::resolved_vis(), and vis2str().

◆ operator<<() [2/2]

std::ostream & mim::ast::operator<< ( std::ostream & os,
Tok tok )

Definition at line 30 of file tok.cpp.

Referenced by operator<<().

◆ prec_assoc()

Assoc mim::ast::prec_assoc ( Prec p)
constexpr

Associativity of precedence level p.

Definition at line 57 of file tok.h.

References CODE, MIM_PREC, and prec_assoc().

Referenced by is_lassoc(), is_rassoc(), and prec_assoc().

◆ should_reduce()

bool mim::ast::should_reduce ( Prec curr,
Prec op )
constexpr

Should a Pratt parser reduce when the current binding power is curr and the infix operator has precedence op?

Definition at line 72 of file tok.h.

References is_rassoc(), and should_reduce().

Referenced by should_reduce().

◆ stream_decls()

template<class T>
void mim::ast::stream_decls ( fe::Tab & tab,
std::ostream & os,
fe::View< Ptr< T > > decls )
static

◆ vis2str()

std::string_view mim::ast::vis2str ( Vis vis)
static

Definition at line 194 of file stream.cpp.

References Priv, Pub, and vis2str().

Referenced by operator<<(), and vis2str().

Variable Documentation

◆ Look_Ahead

size_t mim::ast::Look_Ahead = 2
constexpr

Definition at line 10 of file parser.h.

◆ Num_Keys

auto mim::ast::Num_Keys = size_t(0) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1) + size_t(1)
constexpr

Definition at line 125 of file tok.h.

Referenced by mim::ast::Tok::is_key().

◆ Num_Subst

auto mim::ast::Num_Subst = size_t(0) + size_t(1) + size_t(1) + size_t(1)
constexpr

Definition at line 222 of file tok.h.