conlang: Remove "Identifier" node

It never carried any extra information, and got in the way everywhere it was used.
This commit is contained in:
John 2024-05-19 14:41:31 -05:00
parent f330a7eaa5
commit 0cc0cb5cfb
15 changed files with 115 additions and 139 deletions

View File

@ -29,11 +29,6 @@ pub enum Visibility {
Public, Public,
} }
// TODO: Capture token?
/// A name
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Identifier(pub Sym);
/// A [Literal]: 0x42, 1e123, 2.4, "Hello" /// A [Literal]: 0x42, 1e123, 2.4, "Hello"
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Literal { pub enum Literal {
@ -58,7 +53,7 @@ pub struct Attrs {
/// A metadata decorator /// A metadata decorator
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Meta { pub struct Meta {
pub name: Identifier, pub name: Sym,
pub kind: MetaKind, pub kind: MetaKind,
} }
@ -108,14 +103,14 @@ pub enum ItemKind {
/// An alias to another [Ty] /// An alias to another [Ty]
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Alias { pub struct Alias {
pub to: Identifier, pub to: Sym,
pub from: Option<Box<Ty>>, pub from: Option<Box<Ty>>,
} }
/// A compile-time constant /// A compile-time constant
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Const { pub struct Const {
pub name: Identifier, pub name: Sym,
pub ty: Box<Ty>, pub ty: Box<Ty>,
pub init: Box<Expr>, pub init: Box<Expr>,
} }
@ -124,7 +119,7 @@ pub struct Const {
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Static { pub struct Static {
pub mutable: Mutability, pub mutable: Mutability,
pub name: Identifier, pub name: Sym,
pub ty: Box<Ty>, pub ty: Box<Ty>,
pub init: Box<Expr>, pub init: Box<Expr>,
} }
@ -132,7 +127,7 @@ pub struct Static {
/// An ordered collection of [Items](Item) /// An ordered collection of [Items](Item)
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Module { pub struct Module {
pub name: Identifier, pub name: Sym,
pub kind: ModuleKind, pub kind: ModuleKind,
} }
@ -146,7 +141,7 @@ pub enum ModuleKind {
/// Code, and the interface to that code /// Code, and the interface to that code
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Function { pub struct Function {
pub name: Identifier, pub name: Sym,
pub sign: TyFn, pub sign: TyFn,
pub bind: Vec<Param>, pub bind: Vec<Param>,
pub body: Option<Block>, pub body: Option<Block>,
@ -156,13 +151,13 @@ pub struct Function {
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Param { pub struct Param {
pub mutability: Mutability, pub mutability: Mutability,
pub name: Identifier, pub name: Sym,
} }
/// A user-defined product type /// A user-defined product type
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Struct { pub struct Struct {
pub name: Identifier, pub name: Sym,
pub kind: StructKind, pub kind: StructKind,
} }
@ -174,18 +169,18 @@ pub enum StructKind {
Struct(Vec<StructMember>), Struct(Vec<StructMember>),
} }
/// The [Visibility], [Identifier], and [Ty]pe of a single [Struct] member /// The [Visibility], [Sym], and [Ty]pe of a single [Struct] member
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct StructMember { pub struct StructMember {
pub vis: Visibility, pub vis: Visibility,
pub name: Identifier, pub name: Sym,
pub ty: Ty, pub ty: Ty,
} }
/// A user-defined sum type /// A user-defined sum type
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Enum { pub struct Enum {
pub name: Identifier, pub name: Sym,
pub kind: EnumKind, pub kind: EnumKind,
} }
@ -200,7 +195,7 @@ pub enum EnumKind {
/// A single [Enum] variant /// A single [Enum] variant
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Variant { pub struct Variant {
pub name: Identifier, pub name: Sym,
pub kind: VariantKind, pub kind: VariantKind,
} }
@ -239,8 +234,8 @@ pub struct Use {
pub enum UseTree { pub enum UseTree {
Tree(Vec<UseTree>), Tree(Vec<UseTree>),
Path(PathPart, Box<UseTree>), Path(PathPart, Box<UseTree>),
Alias(Identifier, Identifier), Alias(Sym, Sym),
Name(Identifier), Name(Sym),
Glob, Glob,
} }
@ -297,7 +292,7 @@ pub struct Path {
pub enum PathPart { pub enum PathPart {
SuperKw, SuperKw,
SelfKw, SelfKw,
Ident(Identifier), Ident(Sym),
} }
/// An abstract statement, and associated metadata /// An abstract statement, and associated metadata
@ -328,7 +323,7 @@ pub enum Semi {
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Let { pub struct Let {
pub mutable: Mutability, pub mutable: Mutability,
pub name: Identifier, pub name: Sym,
pub ty: Option<Box<Ty>>, pub ty: Option<Box<Ty>>,
pub init: Option<Box<Expr>>, pub init: Option<Box<Expr>>,
} }
@ -483,8 +478,8 @@ pub struct Member {
/// The kind of [Member] access /// The kind of [Member] access
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum MemberKind { pub enum MemberKind {
Call(Identifier, Tuple), Call(Sym, Tuple),
Struct(Identifier), Struct(Sym),
Tuple(Literal), Tuple(Literal),
} }
@ -502,10 +497,10 @@ pub struct Structor {
pub init: Vec<Fielder>, pub init: Vec<Fielder>,
} }
/// A [Struct field initializer] expression: [Identifier] (`=` [Expr])? /// A [Struct field initializer] expression: [Sym] (`=` [Expr])?
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Fielder { pub struct Fielder {
pub name: Identifier, pub name: Sym,
pub init: Option<Box<Expr>>, pub init: Option<Box<Expr>>,
} }
@ -574,7 +569,7 @@ pub struct If {
/// A [For] expression: `for` Pattern `in` [`Expr`] [`Block`] [`Else`]? /// A [For] expression: `for` Pattern `in` [`Expr`] [`Block`] [`Else`]?
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct For { pub struct For {
pub bind: Identifier, // TODO: Patterns? pub bind: Sym, // TODO: Patterns?
pub cond: Box<Expr>, pub cond: Box<Expr>,
pub pass: Box<Block>, pub pass: Box<Block>,
pub fail: Else, pub fail: Else,

View File

@ -44,12 +44,6 @@ mod display {
} }
} }
impl Display for Identifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl Display for Literal { impl Display for Literal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
@ -691,11 +685,6 @@ mod convert {
//! Converts between major enums and enum variants //! Converts between major enums and enum variants
use super::*; use super::*;
impl<T: AsRef<str>> From<T> for Identifier {
fn from(value: T) -> Self {
Identifier(value.as_ref().into())
}
}
impl<T: AsRef<str>> From<T> for PathPart { impl<T: AsRef<str>> From<T> for PathPart {
fn from(value: T) -> Self { fn from(value: T) -> Self {
match value.as_ref() { match value.as_ref() {
@ -799,7 +788,7 @@ mod convert {
mod path { mod path {
//! Utils for [Path] //! Utils for [Path]
use crate::{ast::Path, Identifier, PathPart}; use crate::{ast::Path, PathPart, Sym};
impl Path { impl Path {
/// Appends a [PathPart] to this [Path] /// Appends a [PathPart] to this [Path]
@ -822,7 +811,7 @@ mod path {
} }
} }
impl PathPart { impl PathPart {
pub fn from_ident(ident: Identifier) -> Self { pub fn from_sym(ident: Sym) -> Self {
Self::Ident(ident) Self::Ident(ident)
} }
} }

View File

@ -22,7 +22,7 @@ pub trait Fold {
fn fold_visibility(&mut self, visibility: Visibility) -> Visibility { fn fold_visibility(&mut self, visibility: Visibility) -> Visibility {
visibility visibility
} }
fn fold_identifier(&mut self, ident: Identifier) -> Identifier { fn fold_sym(&mut self, ident: Sym) -> Sym {
ident ident
} }
fn fold_literal(&mut self, lit: Literal) -> Literal { fn fold_literal(&mut self, lit: Literal) -> Literal {
@ -50,7 +50,7 @@ pub trait Fold {
} }
fn fold_meta(&mut self, m: Meta) -> Meta { fn fold_meta(&mut self, m: Meta) -> Meta {
let Meta { name, kind } = m; let Meta { name, kind } = m;
Meta { name: self.fold_identifier(name), kind: self.fold_meta_kind(kind) } Meta { name: self.fold_sym(name), kind: self.fold_meta_kind(kind) }
} }
fn fold_meta_kind(&mut self, kind: MetaKind) -> MetaKind { fn fold_meta_kind(&mut self, kind: MetaKind) -> MetaKind {
or_fold_meta_kind(self, kind) or_fold_meta_kind(self, kind)
@ -69,12 +69,12 @@ pub trait Fold {
} }
fn fold_alias(&mut self, a: Alias) -> Alias { fn fold_alias(&mut self, a: Alias) -> Alias {
let Alias { to, from } = a; let Alias { to, from } = a;
Alias { to: self.fold_identifier(to), from: from.map(|from| Box::new(self.fold_ty(*from))) } Alias { to: self.fold_sym(to), from: from.map(|from| Box::new(self.fold_ty(*from))) }
} }
fn fold_const(&mut self, c: Const) -> Const { fn fold_const(&mut self, c: Const) -> Const {
let Const { name, ty, init } = c; let Const { name, ty, init } = c;
Const { Const {
name: self.fold_identifier(name), name: self.fold_sym(name),
ty: Box::new(self.fold_ty(*ty)), ty: Box::new(self.fold_ty(*ty)),
init: Box::new(self.fold_expr(*init)), init: Box::new(self.fold_expr(*init)),
} }
@ -83,14 +83,14 @@ pub trait Fold {
let Static { mutable, name, ty, init } = s; let Static { mutable, name, ty, init } = s;
Static { Static {
mutable: self.fold_mutability(mutable), mutable: self.fold_mutability(mutable),
name: self.fold_identifier(name), name: self.fold_sym(name),
ty: Box::new(self.fold_ty(*ty)), ty: Box::new(self.fold_ty(*ty)),
init: Box::new(self.fold_expr(*init)), init: Box::new(self.fold_expr(*init)),
} }
} }
fn fold_module(&mut self, m: Module) -> Module { fn fold_module(&mut self, m: Module) -> Module {
let Module { name, kind } = m; let Module { name, kind } = m;
Module { name: self.fold_identifier(name), kind: self.fold_module_kind(kind) } Module { name: self.fold_sym(name), kind: self.fold_module_kind(kind) }
} }
fn fold_module_kind(&mut self, m: ModuleKind) -> ModuleKind { fn fold_module_kind(&mut self, m: ModuleKind) -> ModuleKind {
match m { match m {
@ -101,7 +101,7 @@ pub trait Fold {
fn fold_function(&mut self, f: Function) -> Function { fn fold_function(&mut self, f: Function) -> Function {
let Function { name, sign, bind, body } = f; let Function { name, sign, bind, body } = f;
Function { Function {
name: self.fold_identifier(name), name: self.fold_sym(name),
sign: self.fold_ty_fn(sign), sign: self.fold_ty_fn(sign),
bind: bind.into_iter().map(|p| self.fold_param(p)).collect(), bind: bind.into_iter().map(|p| self.fold_param(p)).collect(),
body: body.map(|b| self.fold_block(b)), body: body.map(|b| self.fold_block(b)),
@ -109,11 +109,11 @@ pub trait Fold {
} }
fn fold_param(&mut self, p: Param) -> Param { fn fold_param(&mut self, p: Param) -> Param {
let Param { mutability, name } = p; let Param { mutability, name } = p;
Param { mutability: self.fold_mutability(mutability), name: self.fold_identifier(name) } Param { mutability: self.fold_mutability(mutability), name: self.fold_sym(name) }
} }
fn fold_struct(&mut self, s: Struct) -> Struct { fn fold_struct(&mut self, s: Struct) -> Struct {
let Struct { name, kind } = s; let Struct { name, kind } = s;
Struct { name: self.fold_identifier(name), kind: self.fold_struct_kind(kind) } Struct { name: self.fold_sym(name), kind: self.fold_struct_kind(kind) }
} }
fn fold_struct_kind(&mut self, kind: StructKind) -> StructKind { fn fold_struct_kind(&mut self, kind: StructKind) -> StructKind {
match kind { match kind {
@ -132,13 +132,13 @@ pub trait Fold {
let StructMember { vis, name, ty } = m; let StructMember { vis, name, ty } = m;
StructMember { StructMember {
vis: self.fold_visibility(vis), vis: self.fold_visibility(vis),
name: self.fold_identifier(name), name: self.fold_sym(name),
ty: self.fold_ty(ty), ty: self.fold_ty(ty),
} }
} }
fn fold_enum(&mut self, e: Enum) -> Enum { fn fold_enum(&mut self, e: Enum) -> Enum {
let Enum { name, kind } = e; let Enum { name, kind } = e;
Enum { name: self.fold_identifier(name), kind: self.fold_enum_kind(kind) } Enum { name: self.fold_sym(name), kind: self.fold_enum_kind(kind) }
} }
fn fold_enum_kind(&mut self, kind: EnumKind) -> EnumKind { fn fold_enum_kind(&mut self, kind: EnumKind) -> EnumKind {
or_fold_enum_kind(self, kind) or_fold_enum_kind(self, kind)
@ -146,7 +146,7 @@ pub trait Fold {
fn fold_variant(&mut self, v: Variant) -> Variant { fn fold_variant(&mut self, v: Variant) -> Variant {
let Variant { name, kind } = v; let Variant { name, kind } = v;
Variant { name: self.fold_identifier(name), kind: self.fold_variant_kind(kind) } Variant { name: self.fold_sym(name), kind: self.fold_variant_kind(kind) }
} }
fn fold_variant_kind(&mut self, kind: VariantKind) -> VariantKind { fn fold_variant_kind(&mut self, kind: VariantKind) -> VariantKind {
or_fold_variant_kind(self, kind) or_fold_variant_kind(self, kind)
@ -200,7 +200,7 @@ pub trait Fold {
match p { match p {
PathPart::SuperKw => PathPart::SuperKw, PathPart::SuperKw => PathPart::SuperKw,
PathPart::SelfKw => PathPart::SelfKw, PathPart::SelfKw => PathPart::SelfKw,
PathPart::Ident(i) => PathPart::Ident(self.fold_identifier(i)), PathPart::Ident(i) => PathPart::Ident(self.fold_sym(i)),
} }
} }
fn fold_stmt(&mut self, s: Stmt) -> Stmt { fn fold_stmt(&mut self, s: Stmt) -> Stmt {
@ -221,7 +221,7 @@ pub trait Fold {
let Let { mutable, name, ty, init } = l; let Let { mutable, name, ty, init } = l;
Let { Let {
mutable: self.fold_mutability(mutable), mutable: self.fold_mutability(mutable),
name: self.fold_identifier(name), name: self.fold_sym(name),
ty: ty.map(|t| Box::new(self.fold_ty(*t))), ty: ty.map(|t| Box::new(self.fold_ty(*t))),
init: init.map(|e| Box::new(self.fold_expr(*e))), init: init.map(|e| Box::new(self.fold_expr(*e))),
} }
@ -292,10 +292,7 @@ pub trait Fold {
fn fold_fielder(&mut self, f: Fielder) -> Fielder { fn fold_fielder(&mut self, f: Fielder) -> Fielder {
let Fielder { name, init } = f; let Fielder { name, init } = f;
Fielder { Fielder { name: self.fold_sym(name), init: init.map(|e| Box::new(self.fold_expr(*e))) }
name: self.fold_identifier(name),
init: init.map(|e| Box::new(self.fold_expr(*e))),
}
} }
fn fold_array(&mut self, a: Array) -> Array { fn fold_array(&mut self, a: Array) -> Array {
let Array { values } = a; let Array { values } = a;
@ -351,7 +348,7 @@ pub trait Fold {
fn fold_for(&mut self, f: For) -> For { fn fold_for(&mut self, f: For) -> For {
let For { bind, cond, pass, fail } = f; let For { bind, cond, pass, fail } = f;
For { For {
bind: self.fold_identifier(bind), bind: self.fold_sym(bind),
cond: Box::new(self.fold_expr(*cond)), cond: Box::new(self.fold_expr(*cond)),
pass: Box::new(self.fold_block(*pass)), pass: Box::new(self.fold_block(*pass)),
fail: self.fold_else(fail), fail: self.fold_else(fail),
@ -489,10 +486,8 @@ pub fn or_fold_use_tree<F: Fold + ?Sized>(folder: &mut F, tree: UseTree) -> UseT
folder.fold_path_part(path), folder.fold_path_part(path),
Box::new(folder.fold_use_tree(*rest)), Box::new(folder.fold_use_tree(*rest)),
), ),
UseTree::Alias(path, name) => { UseTree::Alias(path, name) => UseTree::Alias(folder.fold_sym(path), folder.fold_sym(name)),
UseTree::Alias(folder.fold_identifier(path), folder.fold_identifier(name)) UseTree::Name(name) => UseTree::Name(folder.fold_sym(name)),
}
UseTree::Name(name) => UseTree::Name(folder.fold_identifier(name)),
UseTree::Glob => UseTree::Glob, UseTree::Glob => UseTree::Glob,
} }
} }
@ -553,9 +548,9 @@ pub fn or_fold_expr_kind<F: Fold + ?Sized>(folder: &mut F, kind: ExprKind) -> Ex
pub fn or_fold_member_kind<F: Fold + ?Sized>(folder: &mut F, kind: MemberKind) -> MemberKind { pub fn or_fold_member_kind<F: Fold + ?Sized>(folder: &mut F, kind: MemberKind) -> MemberKind {
match kind { match kind {
MemberKind::Call(name, args) => { MemberKind::Call(name, args) => {
MemberKind::Call(folder.fold_identifier(name), folder.fold_tuple(args)) MemberKind::Call(folder.fold_sym(name), folder.fold_tuple(args))
} }
MemberKind::Struct(name) => MemberKind::Struct(folder.fold_identifier(name)), MemberKind::Struct(name) => MemberKind::Struct(folder.fold_sym(name)),
MemberKind::Tuple(name) => MemberKind::Tuple(folder.fold_literal(name)), MemberKind::Tuple(name) => MemberKind::Tuple(folder.fold_literal(name)),
} }
} }

View File

@ -16,7 +16,7 @@ pub trait Visit<'a>: Sized {
fn visit_span(&mut self, _extents: &'a Span) {} fn visit_span(&mut self, _extents: &'a Span) {}
fn visit_mutability(&mut self, _mutable: &'a Mutability) {} fn visit_mutability(&mut self, _mutable: &'a Mutability) {}
fn visit_visibility(&mut self, _vis: &'a Visibility) {} fn visit_visibility(&mut self, _vis: &'a Visibility) {}
fn visit_identifier(&mut self, _name: &'a Identifier) {} fn visit_sym(&mut self, _name: &'a Sym) {}
fn visit_literal(&mut self, l: &'a Literal) { fn visit_literal(&mut self, l: &'a Literal) {
or_visit_literal(self, l) or_visit_literal(self, l)
} }
@ -34,7 +34,7 @@ pub trait Visit<'a>: Sized {
} }
fn visit_meta(&mut self, m: &'a Meta) { fn visit_meta(&mut self, m: &'a Meta) {
let Meta { name, kind } = m; let Meta { name, kind } = m;
self.visit_identifier(name); self.visit_sym(name);
self.visit_meta_kind(kind); self.visit_meta_kind(kind);
} }
fn visit_meta_kind(&mut self, kind: &'a MetaKind) { fn visit_meta_kind(&mut self, kind: &'a MetaKind) {
@ -52,27 +52,27 @@ pub trait Visit<'a>: Sized {
} }
fn visit_alias(&mut self, a: &'a Alias) { fn visit_alias(&mut self, a: &'a Alias) {
let Alias { to, from } = a; let Alias { to, from } = a;
self.visit_identifier(to); self.visit_sym(to);
if let Some(t) = from { if let Some(t) = from {
self.visit_ty(t) self.visit_ty(t)
} }
} }
fn visit_const(&mut self, c: &'a Const) { fn visit_const(&mut self, c: &'a Const) {
let Const { name, ty, init } = c; let Const { name, ty, init } = c;
self.visit_identifier(name); self.visit_sym(name);
self.visit_ty(ty); self.visit_ty(ty);
self.visit_expr(init); self.visit_expr(init);
} }
fn visit_static(&mut self, s: &'a Static) { fn visit_static(&mut self, s: &'a Static) {
let Static { mutable, name, ty, init } = s; let Static { mutable, name, ty, init } = s;
self.visit_mutability(mutable); self.visit_mutability(mutable);
self.visit_identifier(name); self.visit_sym(name);
self.visit_ty(ty); self.visit_ty(ty);
self.visit_expr(init); self.visit_expr(init);
} }
fn visit_module(&mut self, m: &'a Module) { fn visit_module(&mut self, m: &'a Module) {
let Module { name, kind } = m; let Module { name, kind } = m;
self.visit_identifier(name); self.visit_sym(name);
self.visit_module_kind(kind); self.visit_module_kind(kind);
} }
fn visit_module_kind(&mut self, kind: &'a ModuleKind) { fn visit_module_kind(&mut self, kind: &'a ModuleKind) {
@ -80,7 +80,7 @@ pub trait Visit<'a>: Sized {
} }
fn visit_function(&mut self, f: &'a Function) { fn visit_function(&mut self, f: &'a Function) {
let Function { name, sign, bind, body } = f; let Function { name, sign, bind, body } = f;
self.visit_identifier(name); self.visit_sym(name);
self.visit_ty_fn(sign); self.visit_ty_fn(sign);
bind.iter().for_each(|p| self.visit_param(p)); bind.iter().for_each(|p| self.visit_param(p));
if let Some(b) = body { if let Some(b) = body {
@ -90,11 +90,11 @@ pub trait Visit<'a>: Sized {
fn visit_param(&mut self, p: &'a Param) { fn visit_param(&mut self, p: &'a Param) {
let Param { mutability, name } = p; let Param { mutability, name } = p;
self.visit_mutability(mutability); self.visit_mutability(mutability);
self.visit_identifier(name); self.visit_sym(name);
} }
fn visit_struct(&mut self, s: &'a Struct) { fn visit_struct(&mut self, s: &'a Struct) {
let Struct { name, kind } = s; let Struct { name, kind } = s;
self.visit_identifier(name); self.visit_sym(name);
self.visit_struct_kind(kind); self.visit_struct_kind(kind);
} }
fn visit_struct_kind(&mut self, kind: &'a StructKind) { fn visit_struct_kind(&mut self, kind: &'a StructKind) {
@ -103,12 +103,12 @@ pub trait Visit<'a>: Sized {
fn visit_struct_member(&mut self, m: &'a StructMember) { fn visit_struct_member(&mut self, m: &'a StructMember) {
let StructMember { vis, name, ty } = m; let StructMember { vis, name, ty } = m;
self.visit_visibility(vis); self.visit_visibility(vis);
self.visit_identifier(name); self.visit_sym(name);
self.visit_ty(ty); self.visit_ty(ty);
} }
fn visit_enum(&mut self, e: &'a Enum) { fn visit_enum(&mut self, e: &'a Enum) {
let Enum { name, kind } = e; let Enum { name, kind } = e;
self.visit_identifier(name); self.visit_sym(name);
self.visit_enum_kind(kind); self.visit_enum_kind(kind);
} }
fn visit_enum_kind(&mut self, kind: &'a EnumKind) { fn visit_enum_kind(&mut self, kind: &'a EnumKind) {
@ -116,7 +116,7 @@ pub trait Visit<'a>: Sized {
} }
fn visit_variant(&mut self, v: &'a Variant) { fn visit_variant(&mut self, v: &'a Variant) {
let Variant { name, kind } = v; let Variant { name, kind } = v;
self.visit_identifier(name); self.visit_sym(name);
self.visit_variant_kind(kind); self.visit_variant_kind(kind);
} }
fn visit_variant_kind(&mut self, kind: &'a VariantKind) { fn visit_variant_kind(&mut self, kind: &'a VariantKind) {
@ -169,7 +169,7 @@ pub trait Visit<'a>: Sized {
match p { match p {
PathPart::SuperKw => {} PathPart::SuperKw => {}
PathPart::SelfKw => {} PathPart::SelfKw => {}
PathPart::Ident(i) => self.visit_identifier(i), PathPart::Ident(i) => self.visit_sym(i),
} }
} }
fn visit_stmt(&mut self, s: &'a Stmt) { fn visit_stmt(&mut self, s: &'a Stmt) {
@ -185,7 +185,7 @@ pub trait Visit<'a>: Sized {
fn visit_let(&mut self, l: &'a Let) { fn visit_let(&mut self, l: &'a Let) {
let Let { mutable, name, ty, init } = l; let Let { mutable, name, ty, init } = l;
self.visit_mutability(mutable); self.visit_mutability(mutable);
self.visit_identifier(name); self.visit_sym(name);
if let Some(ty) = ty { if let Some(ty) = ty {
self.visit_ty(ty); self.visit_ty(ty);
} }
@ -249,7 +249,7 @@ pub trait Visit<'a>: Sized {
} }
fn visit_fielder(&mut self, f: &'a Fielder) { fn visit_fielder(&mut self, f: &'a Fielder) {
let Fielder { name, init } = f; let Fielder { name, init } = f;
self.visit_identifier(name); self.visit_sym(name);
if let Some(init) = init { if let Some(init) = init {
self.visit_expr(init); self.visit_expr(init);
} }
@ -298,7 +298,7 @@ pub trait Visit<'a>: Sized {
} }
fn visit_for(&mut self, f: &'a For) { fn visit_for(&mut self, f: &'a For) {
let For { bind, cond, pass, fail } = f; let For { bind, cond, pass, fail } = f;
self.visit_identifier(bind); self.visit_sym(bind);
self.visit_expr(cond); self.visit_expr(cond);
self.visit_block(pass); self.visit_block(pass);
self.visit_else(fail); self.visit_else(fail);
@ -408,11 +408,11 @@ pub fn or_visit_use_tree<'a, V: Visit<'a>>(visitor: &mut V, tree: &'a UseTree) {
visitor.visit_use_tree(rest) visitor.visit_use_tree(rest)
} }
UseTree::Alias(path, name) => { UseTree::Alias(path, name) => {
visitor.visit_identifier(path); visitor.visit_sym(path);
visitor.visit_identifier(name); visitor.visit_sym(name);
} }
UseTree::Name(name) => { UseTree::Name(name) => {
visitor.visit_identifier(name); visitor.visit_sym(name);
} }
UseTree::Glob => {} UseTree::Glob => {}
} }
@ -469,10 +469,10 @@ pub fn or_visit_expr_kind<'a, V: Visit<'a>>(visitor: &mut V, e: &'a ExprKind) {
pub fn or_visit_member_kind<'a, V: Visit<'a>>(visitor: &mut V, kind: &'a MemberKind) { pub fn or_visit_member_kind<'a, V: Visit<'a>>(visitor: &mut V, kind: &'a MemberKind) {
match kind { match kind {
MemberKind::Call(field, args) => { MemberKind::Call(field, args) => {
visitor.visit_identifier(field); visitor.visit_sym(field);
visitor.visit_tuple(args); visitor.visit_tuple(args);
} }
MemberKind::Struct(field) => visitor.visit_identifier(field), MemberKind::Struct(field) => visitor.visit_sym(field),
MemberKind::Tuple(field) => visitor.visit_literal(field), MemberKind::Tuple(field) => visitor.visit_literal(field),
} }
} }

View File

@ -24,9 +24,9 @@ impl Default for NormalizePaths {
impl Fold for NormalizePaths { impl Fold for NormalizePaths {
fn fold_module(&mut self, m: Module) -> Module { fn fold_module(&mut self, m: Module) -> Module {
let Module { name, kind } = m; let Module { name, kind } = m;
self.path.push(PathPart::Ident(name.clone())); self.path.push(PathPart::Ident(name));
let (name, kind) = (self.fold_identifier(name), self.fold_module_kind(kind)); let (name, kind) = (self.fold_sym(name), self.fold_module_kind(kind));
self.path.pop(); self.path.pop();
Module { name, kind } Module { name, kind }

View File

@ -110,7 +110,7 @@ impl Interpret for Stmt {
} }
impl Interpret for Let { impl Interpret for Let {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> { fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
let Let { mutable: _, name: Identifier(name), ty: _, init } = self; let Let { mutable: _, name, ty: _, init } = self;
let init = init.as_ref().map(|i| i.interpret(env)).transpose()?; let init = init.as_ref().map(|i| i.interpret(env)).transpose()?;
env.insert(*name, init); env.insert(*name, init);
Ok(ConValue::Empty) Ok(ConValue::Empty)
@ -162,7 +162,7 @@ fn evaluate_place_expr<'e>(
match parts.last().expect("parts should not be empty") { match parts.last().expect("parts should not be empty") {
PathPart::SuperKw => Err(Error::NotAssignable), PathPart::SuperKw => Err(Error::NotAssignable),
PathPart::SelfKw => todo!("Assignment to `self`"), PathPart::SelfKw => todo!("Assignment to `self`"),
PathPart::Ident(Identifier(s)) => env.get_mut(*s).map(|v| (v, *s)), PathPart::Ident(s) => env.get_mut(*s).map(|v| (v, *s)),
} }
} }
ExprKind::Index(_) => todo!("Assignment to an index operation"), ExprKind::Index(_) => todo!("Assignment to an index operation"),
@ -340,7 +340,7 @@ impl Interpret for Member {
for arg in &args.exprs { for arg in &args.exprs {
values.push(arg.interpret(env)?); values.push(arg.interpret(env)?);
} }
env.call(name.0, &values) env.call(*name, &values)
} }
_ => Err(Error::TypeError)?, _ => Err(Error::TypeError)?,
} }
@ -368,7 +368,7 @@ impl Interpret for Path {
if parts.len() == 1 { if parts.len() == 1 {
match parts.last().expect("parts should not be empty") { match parts.last().expect("parts should not be empty") {
PathPart::SuperKw | PathPart::SelfKw => todo!("Path navigation"), PathPart::SuperKw | PathPart::SelfKw => todo!("Path navigation"),
PathPart::Ident(Identifier(name)) => env.get(*name), PathPart::Ident(name) => env.get(*name),
} }
} else { } else {
todo!("Path navigation!") todo!("Path navigation!")
@ -413,7 +413,7 @@ impl Interpret for AddrOf {
match expr.as_ref() { match expr.as_ref() {
ExprKind::Index(_) => todo!("AddrOf array index"), ExprKind::Index(_) => todo!("AddrOf array index"),
// ExprKind::Path(Path { absolute: false, parts }) => match parts.as_slice() { // ExprKind::Path(Path { absolute: false, parts }) => match parts.as_slice() {
// [PathPart::Ident(Identifier(id))] => env.get_ref(id), // [PathPart::Ident(id)] => env.get_ref(id),
// _ => todo!("Path traversal in addrof"), // _ => todo!("Path traversal in addrof"),
// }, // },
ExprKind::Path(_) => todo!("Path traversal in addrof"), ExprKind::Path(_) => todo!("Path traversal in addrof"),
@ -492,7 +492,7 @@ impl Interpret for If {
} }
impl Interpret for For { impl Interpret for For {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> { fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
let Self { bind: Identifier(name), cond, pass, fail } = self; let Self { bind: name, cond, pass, fail } = self;
// TODO: A better iterator model // TODO: A better iterator model
let mut bounds = match cond.interpret(env)? { let mut bounds = match cond.interpret(env)? {
ConValue::RangeExc(a, b) => a..=b, ConValue::RangeExc(a, b) => a..=b,

View File

@ -311,7 +311,7 @@ pub mod function {
//! Represents a block of code which lives inside the Interpreter //! Represents a block of code which lives inside the Interpreter
use super::{Callable, ConValue, Environment, Error, IResult, Interpret}; use super::{Callable, ConValue, Environment, Error, IResult, Interpret};
use cl_ast::{Function as FnDecl, Identifier, Param, Sym}; use cl_ast::{Function as FnDecl, Param, Sym};
use std::rc::Rc; use std::rc::Rc;
/// Represents a block of code which persists inside the Interpreter /// Represents a block of code which persists inside the Interpreter
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -333,11 +333,11 @@ pub mod function {
impl Callable for Function { impl Callable for Function {
fn name(&self) -> Sym { fn name(&self) -> Sym {
let FnDecl { name: Identifier(name), .. } = *self.decl; let FnDecl { name, .. } = *self.decl;
name name
} }
fn call(&self, env: &mut Environment, args: &[ConValue]) -> IResult<ConValue> { fn call(&self, env: &mut Environment, args: &[ConValue]) -> IResult<ConValue> {
let FnDecl { name: Identifier(name), bind, body, sign: _ } = &*self.decl; let FnDecl { name, bind, body, sign: _ } = &*self.decl;
// Check arg mapping // Check arg mapping
if args.len() != bind.len() { if args.len() != bind.len() {
return Err(Error::ArgNumber { want: bind.len(), got: args.len() }); return Err(Error::ArgNumber { want: bind.len(), got: args.len() });
@ -347,7 +347,7 @@ pub mod function {
}; };
// TODO: completely refactor data storage // TODO: completely refactor data storage
let mut frame = env.frame("fn args"); let mut frame = env.frame("fn args");
for (Param { mutability: _, name: Identifier(name) }, value) in bind.iter().zip(args) { for (Param { mutability: _, name }, value) in bind.iter().zip(args) {
frame.insert(*name, Some(value.clone())); frame.insert(*name, Some(value.clone()));
} }
match body.interpret(&mut frame) { match body.interpret(&mut frame) {
@ -370,7 +370,7 @@ pub mod env {
temp_type_impl::ConValue, temp_type_impl::ConValue,
BuiltIn, Callable, Interpret, BuiltIn, Callable, Interpret,
}; };
use cl_ast::{Function as FnDecl, Identifier, Sym}; use cl_ast::{Function as FnDecl, Sym};
use std::{ use std::{
collections::HashMap, collections::HashMap,
fmt::Display, fmt::Display,
@ -475,7 +475,7 @@ pub mod env {
} }
/// A convenience function for registering a [FnDecl] as a [Function] /// A convenience function for registering a [FnDecl] as a [Function]
pub fn insert_fn(&mut self, decl: &FnDecl) { pub fn insert_fn(&mut self, decl: &FnDecl) {
let FnDecl { name: Identifier(name), .. } = decl; let FnDecl { name, .. } = decl;
let (name, function) = (name, Some(Function::new(decl).into())); let (name, function) = (name, Some(Function::new(decl).into()));
if let Some((frame, _)) = self.frames.last_mut() { if let Some((frame, _)) = self.frames.last_mut() {
frame.insert(*name, function); frame.insert(*name, function);

View File

@ -64,8 +64,7 @@ impl Fold for ModuleInliner {
/// Traverses down the module tree, entering ever nested directories /// Traverses down the module tree, entering ever nested directories
fn fold_module(&mut self, m: Module) -> Module { fn fold_module(&mut self, m: Module) -> Module {
let Module { name, kind } = m; let Module { name, kind } = m;
let sym = name.0; self.path.push(&*name); // cd ./name
self.path.push(&*sym); // cd ./name
let kind = self.fold_module_kind(kind); let kind = self.fold_module_kind(kind);

View File

@ -769,8 +769,8 @@ impl<'t> Parser<'t> {
self.consume_peeked(); self.consume_peeked();
Ok(out) Ok(out)
} }
/// [Identifier] = [`Identifier`](TokenKind::Identifier) /// [Sym] = [`Identifier`](TokenKind::Identifier)
pub fn identifier(&mut self) -> PResult<Identifier> { pub fn identifier(&mut self) -> PResult<Sym> {
let tok = self.match_type(TokenKind::Identifier, Parsing::Identifier)?; let tok = self.match_type(TokenKind::Identifier, Parsing::Identifier)?;
match tok.data() { match tok.data() {
TokenData::String(ident) => Ok(ident.into()), TokenData::String(ident) => Ok(ident.into()),

View File

@ -588,10 +588,9 @@ pub mod yamlify {
y.value(format_args!("\"{self}\"")); y.value(format_args!("\"{self}\""));
} }
} }
impl Yamlify for Identifier { impl Yamlify for Sym {
fn yaml(&self, y: &mut Yamler) { fn yaml(&self, y: &mut Yamler) {
let Self(name) = self; y.value(self);
y.value(name);
} }
} }
impl Yamlify for Param { impl Yamlify for Param {

View File

@ -51,7 +51,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_module(&mut self, m: &'a Module) { fn visit_module(&mut self, m: &'a Module) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Module { name: Identifier(name), kind } = m; let Module { name, kind } = m;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -60,14 +60,14 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
}; };
let id = prj.pool.insert(def); let id = prj.pool.insert(def);
prj[*parent].module.insert_type(*name, id); prj[*parent].module.insert_type(*name, id);
self.path.push(PathPart::Ident(Identifier(*name))); self.path.push(PathPart::Ident(*name));
self.with_parent(id, kind, Self::visit_module_kind); self.with_parent(id, kind, Self::visit_module_kind);
self.path.pop(); self.path.pop();
self.retval = Some(id); self.retval = Some(id);
} }
fn visit_alias(&mut self, a: &'a Alias) { fn visit_alias(&mut self, a: &'a Alias) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Alias { to: Identifier(name), from: _ } = a; let Alias { to: name, from: _ } = a;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -81,7 +81,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_enum(&mut self, e: &'a Enum) { fn visit_enum(&mut self, e: &'a Enum) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Enum { name: Identifier(name), kind } = e; let Enum { name, kind } = e;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -96,7 +96,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_variant(&mut self, v: &'a Variant) { fn visit_variant(&mut self, v: &'a Variant) {
let Self { path, prj, parent, retval: _ } = self; let Self { path, prj, parent, retval: _ } = self;
let Variant { name: Identifier(name), kind } = v; let Variant { name, kind } = v;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -111,7 +111,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_struct(&mut self, s: &'a Struct) { fn visit_struct(&mut self, s: &'a Struct) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Struct { name: Identifier(name), kind } = s; let Struct { name, kind } = s;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -126,7 +126,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_const(&mut self, c: &'a Const) { fn visit_const(&mut self, c: &'a Const) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Const { name: Identifier(name), ty: _, init } = c; let Const { name, ty: _, init } = c;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -141,7 +141,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_static(&mut self, s: &'a Static) { fn visit_static(&mut self, s: &'a Static) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Static { name: Identifier(name), mutable: _, ty: _, init } = s; let Static { name, mutable: _, ty: _, init } = s;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -156,7 +156,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_function(&mut self, f: &'a Function) { fn visit_function(&mut self, f: &'a Function) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Function { name: Identifier(name), body, .. } = f; let Function { name, body, .. } = f;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
@ -201,7 +201,7 @@ impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
} }
fn visit_let(&mut self, l: &'a Let) { fn visit_let(&mut self, l: &'a Let) {
let Self { prj, parent, path, retval: _ } = self; let Self { prj, parent, path, retval: _ } = self;
let Let { name: Identifier(name), init, .. } = l; let Let { name, init, .. } = l;
let def = Def { let def = Def {
module: Mod::new(*parent), module: Mod::new(*parent),
kind: DefKind::Undecided, kind: DefKind::Undecided,

View File

@ -47,15 +47,15 @@ impl<'a> NodeSource<'a> {
pub fn name(&self) -> Option<Sym> { pub fn name(&self) -> Option<Sym> {
match self { match self {
NodeSource::Root => None, NodeSource::Root => None,
NodeSource::Module(v) => Some(v.name.0), NodeSource::Module(v) => Some(v.name),
NodeSource::Alias(v) => Some(v.to.0), NodeSource::Alias(v) => Some(v.to),
NodeSource::Enum(v) => Some(v.name.0), NodeSource::Enum(v) => Some(v.name),
NodeSource::Variant(v) => Some(v.name.0), NodeSource::Variant(v) => Some(v.name),
NodeSource::Struct(v) => Some(v.name.0), NodeSource::Struct(v) => Some(v.name),
NodeSource::Const(v) => Some(v.name.0), NodeSource::Const(v) => Some(v.name),
NodeSource::Static(v) => Some(v.name.0), NodeSource::Static(v) => Some(v.name),
NodeSource::Function(v) => Some(v.name.0), NodeSource::Function(v) => Some(v.name),
NodeSource::Local(l) => Some(l.name.0), NodeSource::Local(l) => Some(l.name),
NodeSource::Impl(_) | NodeSource::Use(_) | NodeSource::Ty(_) => None, NodeSource::Impl(_) | NodeSource::Use(_) | NodeSource::Ty(_) => None,
} }
} }
@ -166,7 +166,7 @@ pub mod sorcerer {
impl<'a> Visit<'a> for NodeSorcerer<'a> { impl<'a> Visit<'a> for NodeSorcerer<'a> {
fn visit_module(&mut self, m: &'a Module) { fn visit_module(&mut self, m: &'a Module) {
let Module { name, kind } = m; let Module { name, kind } = m;
self.path.push(PathPart::Ident(name.clone())); self.path.push(PathPart::Ident(*name));
self.visit_module_kind(kind); self.visit_module_kind(kind);
self.path.pop(); self.path.pop();
} }

View File

@ -6,7 +6,7 @@ use crate::{
node::{Node, NodeSource}, node::{Node, NodeSource},
path::Path, path::Path,
}; };
use cl_ast::{Identifier, PathPart}; use cl_ast::PathPart;
use cl_structures::deprecated_intern_pool::Pool; use cl_structures::deprecated_intern_pool::Pool;
use std::{ use std::{
collections::HashMap, collections::HashMap,
@ -85,11 +85,11 @@ impl<'a> Project<'a> {
} }
match path.as_ref() { match path.as_ref() {
[] => Some((Some(within), None, path)), [] => Some((Some(within), None, path)),
[PathPart::Ident(Identifier(name))] => { [PathPart::Ident(name)] => {
let (ty, val) = self[within].module.get(*name); let (ty, val) = self[within].module.get(*name);
Some((ty, val, path.pop_front()?)) Some((ty, val, path.pop_front()?))
} }
[PathPart::Ident(Identifier(name)), ..] => { [PathPart::Ident(name), ..] => {
let ty = self[within].module.get_type(*name)?; let ty = self[within].module.get_type(*name)?;
self.get(path.pop_front()?, ty) self.get(path.pop_front()?, ty)
} }
@ -108,7 +108,7 @@ impl<'a> Project<'a> {
match front { match front {
PathPart::SelfKw => self.get_type(path.pop_front()?, within), PathPart::SelfKw => self.get_type(path.pop_front()?, within),
PathPart::SuperKw => self.get_type(path.pop_front()?, module.parent?), PathPart::SuperKw => self.get_type(path.pop_front()?, module.parent?),
PathPart::Ident(Identifier(name)) => match module.types.get(name) { PathPart::Ident(name) => match module.types.get(name) {
Some(&submodule) => self.get_type(path.pop_front()?, submodule), Some(&submodule) => self.get_type(path.pop_front()?, submodule),
None => Some((within, path)), None => Some((within, path)),
}, },
@ -120,7 +120,7 @@ impl<'a> Project<'a> {
pub fn get_value<'p>(&self, path: Path<'p>, within: DefID) -> Option<(DefID, Path<'p>)> { pub fn get_value<'p>(&self, path: Path<'p>, within: DefID) -> Option<(DefID, Path<'p>)> {
match path.front()? { match path.front()? {
PathPart::Ident(Identifier(name)) => Some(( PathPart::Ident(name) => Some((
self[within].module.values.get(name).copied()?, self[within].module.values.get(name).copied()?,
path.pop_front()?, path.pop_front()?,
)), )),
@ -280,7 +280,7 @@ pub mod evaluate {
.parent_of(parent) .parent_of(parent)
.ok_or_else(|| "Attempt to get super of root".into()), .ok_or_else(|| "Attempt to get super of root".into()),
PathPart::SelfKw => Ok(parent), PathPart::SelfKw => Ok(parent),
PathPart::Ident(Identifier(name)) => name.evaluate(prj, parent), PathPart::Ident(name) => name.evaluate(prj, parent),
} }
} }
} }

View File

@ -34,7 +34,7 @@ pub fn resolve(prj: &mut Prj, id: DefID) -> Result<(), &'static str> {
eprintln!("Resolver: \x1b[32mEvaluating\x1b[0m \"\x1b[36m{kind} {name}\x1b[0m\" (`{id:?}`)"); eprintln!("Resolver: \x1b[32mEvaluating\x1b[0m \"\x1b[36m{kind} {name}\x1b[0m\" (`{id:?}`)");
for Meta { name: Identifier(name), kind } in meta { for Meta { name, kind } in meta {
if let ("intrinsic", MetaKind::Equals(Literal::String(s))) = (&**name, kind) { if let ("intrinsic", MetaKind::Equals(Literal::String(s))) = (&**name, kind) {
prj[id].kind = DefKind::Type(TypeKind::Intrinsic( prj[id].kind = DefKind::Type(TypeKind::Intrinsic(
s.parse().map_err(|_| "Failed to parse intrinsic")?, s.parse().map_err(|_| "Failed to parse intrinsic")?,
@ -85,7 +85,7 @@ impl<'a> TypeResolvable<'a> for &'a Meta {
#[allow(unused_variables)] #[allow(unused_variables)]
fn resolve_type(self, prj: &mut Prj<'a>, id: DefID) -> Result<Self::Out, &'static str> { fn resolve_type(self, prj: &mut Prj<'a>, id: DefID) -> Result<Self::Out, &'static str> {
let Meta { name: Identifier(name), kind } = self; let Meta { name, kind } = self;
match (name.as_ref(), kind) { match (name.as_ref(), kind) {
("intrinsic", MetaKind::Equals(Literal::String(intrinsic))) => Ok(DefKind::Type( ("intrinsic", MetaKind::Equals(Literal::String(intrinsic))) => Ok(DefKind::Type(
TypeKind::Intrinsic(intrinsic.parse().map_err(|_| "unknown intrinsic type")?), TypeKind::Intrinsic(intrinsic.parse().map_err(|_| "unknown intrinsic type")?),
@ -134,7 +134,7 @@ impl<'a> TypeResolvable<'a> for &'a Enum {
return Ok(DefKind::Type(TypeKind::Adt(Adt::FieldlessEnum))); return Ok(DefKind::Type(TypeKind::Adt(Adt::FieldlessEnum)));
}; };
let mut fields = vec![]; let mut fields = vec![];
for Variant { name: Identifier(name), kind: _ } in v { for Variant { name, kind: _ } in v {
let id = prj[id].module.get_type(*name); let id = prj[id].module.get_type(*name);
fields.push((*name, id)) fields.push((*name, id))
} }
@ -201,7 +201,7 @@ impl<'a> TypeResolvable<'a> for &'a StructMember {
fn resolve_type(self, prj: &mut Prj<'a>, id: DefID) -> Result<Self::Out, &'static str> { fn resolve_type(self, prj: &mut Prj<'a>, id: DefID) -> Result<Self::Out, &'static str> {
let parent = prj.parent_of(id).unwrap_or(id); let parent = prj.parent_of(id).unwrap_or(id);
let StructMember { name: Identifier(name), vis, ty } = self; let StructMember { name, vis, ty } = self;
let ty = ty let ty = ty
.evaluate(prj, parent) .evaluate(prj, parent)

View File

@ -58,7 +58,7 @@ impl<'a> Project<'a> {
} }
UseTree::Name(name) => self.visit_use_leaf(name, parent, c)?, UseTree::Name(name) => self.visit_use_leaf(name, parent, c)?,
UseTree::Alias(Identifier(from), Identifier(to)) => { UseTree::Alias(from, to) => {
self.visit_use_alias(from, to, parent, c)? self.visit_use_alias(from, to, parent, c)?
} }
UseTree::Glob => self.visit_use_glob(parent, c)?, UseTree::Glob => self.visit_use_glob(parent, c)?,
@ -70,8 +70,7 @@ impl<'a> Project<'a> {
Ok(()) Ok(())
} }
pub fn visit_use_leaf(&mut self, part: &'a Identifier, parent: DefID, c: DefID) -> UseResult { pub fn visit_use_leaf(&mut self, name: &'a Sym, parent: DefID, c: DefID) -> UseResult {
let Identifier(name) = part;
self.visit_use_alias(name, name, parent, c) self.visit_use_alias(name, name, parent, c)
} }