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; or a family axm (name, ...): 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_i of a group dbg_0 ... dbg_n-1: type for i > 0; the leading IdPtrn::id owns type. More...
class  HoleExpr
 ? More...
class  IdDecl
 dbg bound to a Def whose type the binding construct dictates; hence, it carries no annotation. 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 end; 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  MutualDecl
 mutual decl* end groups RecDecls that may refer to each other. More...
class  Node
 Base class of all AST nodes. More...
class  NomDecl
 nom dbg = body; - a nominal newtype. 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  PrefixExpr
 op rhs; PrefixExpr::op picks the meaning - see MIM_PREFIX. More...
class  PrimaryExpr
 tag More...
class  Ptrn
 Base class of all patterns. More...
struct  R
class  RecDecl
 rec dbg = body; 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
 «index: shape; body» or ‹index: shape; body› if SeqExpr::is_pack; index: is optional. More...
class  SigmaExpr
 Wraps a TuplePtrn as Expr. More...
class  SingleExpr
 «body» or ‹body› if SingleExpr::is_wrap. 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  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...
class  VariantExpr
 | ctor_0: type_0 | ... | ctor_n-1: type_n-1; a constructor without a type carries []. 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 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 Sym loc2plugin (AST &ast, Loc loc)
static void add_names (AnnexInfo &annex, const Expr *type)
 Records the constructor or field names that type - the body of an annex declaration - spells out.
static void add_alias (AnnexInfo *annex, sub_t sub, Sym target, Sym alias)
 Registers alias as a further name of the annex slot target introduced.
static bool is_wildcard (const Ptrn *ptrn)
 A wildcard binds nothing, so the Def it would name need not exist - and a dump would then have to name it.
static const Def * assign (Emitter &e, const Ptrn *ptrn, const Def *type, const Def *def)
static void emit_var (Emitter &e, const Ptrn *ptrn, Def *mut)
 Binds ptrn to the Var of mut - which a wildcard does not create.
static std::optional< nat_t > isa_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 void check_nom_scope (Emitter &e, Loc loc, const Nom *nom)
 A private nom's representation is confined to the mod that declared it; the type itself is not.
static void open_nom (Emitter &e, Loc loc, const Nom *nom)
 Checks and prepares access to nom's representation.
static const Def * unwrap_field (Emitter &e, const InfixExpr *ex, const Def *tup)
 Unwraps tup if it is a value of a nom and ex names one of its fields; nullptr otherwise.
static const Def * emit_ctor (Emitter &e, const Variant *variant, const Expr *index, const Nom *nom=nullptr)
 T#C or T#i selects case C or i of the Variant T: a constructor function - or its value for a [] payload.
static Tok negate (Tok tok)
 Applies a leading - to a numeric literal Tok.
static void stream_decls (fe::Tab &tab, std::ostream &os, fe::View< Ptr< ValDecl > > decls)
static std::string escape_char (char8_t c)
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.
static bool is_block (const Expr *expr)
 Does expr span several statements and hence deserve an indented block of its own?
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) + 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 46 of file ast.h.

Class Members
const Decl * decl
Vis vis

Typedef Documentation

◆ Dbgs

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

Definition at line 35 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 27 of file ast.h.

◆ Ptrs

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

Definition at line 34 of file ast.h.

◆ Scope

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

Maps a name to the Binding introducing it.

Definition at line 51 of file ast.h.

◆ Tag

Definition at line 11 of file bind.cpp.

Enumeration Type Documentation

◆ Assoc

enum class mim::ast::Assoc
strong

Associativity of an infix expression.

Enumerator
N 
L 
R 

Definition at line 48 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 51 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 42 of file ast.h.

Function Documentation

◆ add_alias()

void mim::ast::add_alias ( AnnexInfo * annex,
sub_t sub,
Sym target,
Sym alias )
static

Registers alias as a further name of the annex slot target introduced.

Definition at line 403 of file bind.cpp.

References add_alias(), and mim::ast::AnnexInfo::subs.

Referenced by add_alias(), mim::ast::AliasDecl::bind(), and mim::ast::AxmDecl::bind().

◆ add_names()

void mim::ast::add_names ( AnnexInfo & annex,
const Expr * type )
static

Records the constructor or field names that type - the body of an annex declaration - spells out.

Definition at line 348 of file bind.cpp.

References add_names(), mim::ast::AnnexInfo::fields, and mim::ast::AnnexInfo::names.

Referenced by add_names(), and mim::ast::AST::name2annex().

◆ assign()

const Def * mim::ast::assign ( Emitter & e,
const Ptrn * ptrn,
const Def * type,
const Def * def )
static

◆ check_nom_scope()

void mim::ast::check_nom_scope ( Emitter & e,
Loc loc,
const Nom * nom )
static

A private nom's representation is confined to the mod that declared it; the type itself is not.

Definition at line 495 of file emit.cpp.

References check_nom_scope(), and mim::Def::loc().

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

◆ emit_ctor()

const Def * mim::ast::emit_ctor ( Emitter & e,
const Variant * variant,
const Expr * index,
const Nom * nom = nullptr )
static

T#C or T#i selects case C or i of the Variant T: a constructor function - or its value for a [] payload.

If nom is given, T is its body and the constructor yields nom.

Definition at line 545 of file emit.cpp.

References mim::Def::dbg(), mim::ast::Path::dbgs(), mim::ast::Expr::emit(), emit_ctor(), mim::Lit::isa(), mim::ast::Node::loc(), mim::Def::num_ops(), mim::Def::op(), and mim::ast::PathExpr::path().

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

◆ 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 466 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().

◆ emit_var()

void mim::ast::emit_var ( Emitter & e,
const Ptrn * ptrn,
Def * mut )
static

Binds ptrn to the Var of mut - which a wildcard does not create.

Definition at line 253 of file emit.cpp.

References mim::ast::Ptrn::emit_type(), mim::ast::Ptrn::emit_value(), emit_var(), is_wildcard(), and mim::Def::var().

Referenced by mim::ast::PiExpr::Dom::emit_type(), mim::ast::LamDecl::Dom::emit_value(), and emit_var().

◆ 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 407 of file emit.cpp.

References encode_f(), and isa_math_f().

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

◆ escape_char()

std::string mim::ast::escape_char ( char8_t c)
static

Definition at line 116 of file stream.cpp.

References mim::ast::Lexer::escape(), and escape_char().

Referenced by escape_char(), and mim::ast::LitExpr::stream().

◆ is_block()

bool mim::ast::is_block ( const Expr * expr)
static

Does expr span several statements and hence deserve an indented block of its own?

Definition at line 347 of file stream.cpp.

References is_block().

Referenced by is_block(), and mim::ast::LamDecl::stream_().

◆ is_rassoc()

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

Definition at line 68 of file tok.h.

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

Referenced by is_rassoc(), and should_reduce().

◆ is_wildcard()

bool mim::ast::is_wildcard ( const Ptrn * ptrn)
static

A wildcard binds nothing, so the Def it would name need not exist - and a dump would then have to name it.

Definition at line 216 of file emit.cpp.

References is_wildcard().

Referenced by mim::ast::Ptrn::emit_proj(), emit_var(), and is_wildcard().

◆ 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 394 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 1379 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 )

◆ loc2plugin()

Sym mim::ast::loc2plugin ( AST & ast,
Loc loc )
static

Definition at line 343 of file bind.cpp.

References mim::ast::Node::loc(), and loc2plugin().

Referenced by mim::ast::AliasDecl::bind(), loc2plugin(), and mim::ast::AST::name2annex().

◆ negate()

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

Applies a leading - to a numeric literal Tok.

Definition at line 405 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().

◆ open_nom()

void mim::ast::open_nom ( Emitter & e,
Loc loc,
const Nom * nom )
static

Checks and prepares access to nom's representation.

Definition at line 507 of file emit.cpp.

References check_nom_scope(), and open_nom().

Referenced by mim::ast::InfixExpr::emit_(), mim::ast::MatchExpr::emit_(), mim::ast::PrefixExpr::emit_(), open_nom(), and unwrap_field().

◆ 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 247 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 58 of file tok.h.

References CODE, MIM_PREC, and prec_assoc().

Referenced by 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()

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

◆ unwrap_field()

const Def * mim::ast::unwrap_field ( Emitter & e,
const InfixExpr * ex,
const Def * tup )
static

Unwraps tup if it is a value of a nom and ex names one of its fields; nullptr otherwise.

Definition at line 513 of file emit.cpp.

References mim::Def::isa_type(), mim::ast::Node::loc(), open_nom(), mim::ast::InfixExpr::rhs(), and unwrap_field().

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

◆ vis2str()

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

Definition at line 238 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) + size_t(1)
constexpr

Definition at line 126 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 231 of file tok.h.