pub struct Context {
    pub name: Str,
    pub kind: ContextKind,
    /* private fields */
}
Expand description

Represents the context of the current scope

Recursive functions/methods are highlighted with the prefix rec_, as performance may be significantly degraded.

Fields§

§name: Str§kind: ContextKind

Implementations§

source§

impl Context

source

pub fn subtype_of(&self, lhs: &Type, rhs: &Type) -> bool

lhs <: rhs ?

e.g.

Named :> Module
=> Module.super_types == [Named]

Seq(T) :> Range(T)
=> Range(T).super_types == [Eq, Mutate, Seq(T), Output(T)]
source

pub fn fields(&self, t: &Type) -> Dict<Field, Type>

source§

impl Context

source

pub const TOP_LEVEL: usize = 1usize

source

pub fn readable_type(&self, t: Type, is_parameter: bool) -> Type

source§

impl Context

source

pub fn new_module<S: Into<Str>>( name: S, cfg: ErgConfig, shared: SharedCompilerResource ) -> Self

source§

impl Context

source

pub fn get_singular_ctxs_by_hir_expr( &self, obj: &Expr, namespace: &Context ) -> SingleTyCheckResult<Vec<&Context>>

source

pub fn sort_types<'a>( &self, types: impl Iterator<Item = &'a Type> ) -> Vec<&'a Type>

Perform types linearization. TODO: Current implementation may be very inefficient.

C3 linearization requires prior knowledge of inter-type dependencies, and cannot be used for Erg structural subtype linearization

Algorithm:

[Int, Str, Nat, Never, Obj, Str!, Module]
=> [], [Int, Str, Nat, Never, Obj, Str!, Module]
=> [[Int]], [Str, Nat, Never, Obj, Str!, Module]
# 1. If related, put them in the same array; if not, put them in different arrays.
=> [[Int], [Str]], [Nat, Never, Obj, Str!, Module]
=> ...
=> [[Int, Nat, Never, Obj]], [Str, Str!], [Module]]
# 2. Then, perform sorting on the arrays
=> [[Never, Nat, Int, Obj], [Str!, Str], [Module]]
# 3. Concatenate the arrays
=> [Never, Nat, Int, Obj, Str!, Str, Module]
# 4. From the left, "slide" types as far as it can.
=> [Never, Nat, Int, Str!, Str, Module, Obj]
source

pub fn get_nominal_super_type_ctxs<'a>( &'a self, t: &Type ) -> Option<Vec<&'a Context>>

source

pub fn meta_type(&self, typ: &Type) -> Type

Int.meta_type() == ClassType (<: Type) Show.meta_type() == TraitType (<: Type) [Int; 3].meta_type() == [ClassType; 3] (<: Type)

source§

impl Context

source§

impl Context

source

pub fn del(&mut self, ident: &Identifier) -> CompileResult<()>

source

pub fn inc_ref<L: Locational>( &self, vi: &VarInfo, name: &L, namespace: &Context )

source§

impl Context

source§

impl Context

source

pub fn dir(&self) -> Dict<&VarName, &VarInfo>

source

pub fn get_receiver_ctx(&self, receiver_name: &str) -> Option<&Context>

source

pub fn get_receiver_ctxs(&self, receiver_name: &str) -> Vec<&Context>

source

pub fn get_var_info(&self, name: &str) -> Option<(&VarName, &VarInfo)>

source§

impl Context

source

pub fn new( name: Str, cfg: ErgConfig, kind: ContextKind, params: Vec<ParamSpec>, outer: Option<Context>, shared: Option<SharedCompilerResource>, level: usize ) -> Self

source

pub fn default_with_name(name: &'static str) -> Self

source

pub fn with_capacity( name: Str, cfg: ErgConfig, kind: ContextKind, params: Vec<ParamSpec>, outer: Option<Context>, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn mono( name: Str, cfg: ErgConfig, kind: ContextKind, outer: Option<Context>, shared: Option<SharedCompilerResource>, level: usize ) -> Self

source

pub fn poly( name: Str, cfg: ErgConfig, kind: ContextKind, params: Vec<ParamSpec>, outer: Option<Context>, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn poly_trait<S: Into<Str>>( name: S, params: Vec<ParamSpec>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn builtin_poly_trait<S: Into<Str>>( name: S, params: Vec<ParamSpec>, capacity: usize ) -> Self

source

pub fn poly_class<S: Into<Str>>( name: S, params: Vec<ParamSpec>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn builtin_poly_class<S: Into<Str>>( name: S, params: Vec<ParamSpec>, capacity: usize ) -> Self

source

pub fn poly_patch<S: Into<Str>>( name: S, base: Type, params: Vec<ParamSpec>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn mono_trait<S: Into<Str>>( name: S, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn builtin_mono_trait<S: Into<Str>>(name: S, capacity: usize) -> Self

source

pub fn mono_class<S: Into<Str>>( name: S, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn builtin_mono_class<S: Into<Str>>(name: S, capacity: usize) -> Self

source

pub fn mono_patch<S: Into<Str>>( name: S, base: Type, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn methods( impl_trait: Option<Type>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn builtin_methods(impl_trait: Option<Type>, capacity: usize) -> Self

source

pub fn poly_glue_patch<S: Into<Str>>( name: S, base: Type, impls: Type, params: Vec<ParamSpec>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self

source

pub fn builtin_poly_glue_patch<S: Into<Str>>( name: S, base: Type, impls: Type, params: Vec<ParamSpec>, capacity: usize ) -> Self

source

pub fn module( name: Str, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize ) -> Self

source

pub fn builtin_module<S: Into<Str>>( name: S, cfg: ErgConfig, shared: SharedCompilerResource, capacity: usize ) -> Self

source

pub fn instant( name: Str, cfg: ErgConfig, capacity: usize, shared: Option<SharedCompilerResource>, outer: Context ) -> Self

source

pub fn caused_by(&self) -> String

source

pub fn initialize(&mut self)

This method is intended to be called only in the top-level module. .cfg is not initialized and is used around.

source

pub fn pop(&mut self) -> Context

source

pub fn pop_mod(&mut self) -> Option<Context>

unlike pop, outer must be None.

source

pub fn local_dir(&self) -> Dict<&VarName, &VarInfo>

source

pub fn index(&self) -> &SharedModuleIndex

source

pub fn trait_impls(&self) -> &SharedTraitImpls

source

pub fn shared(&self) -> &SharedCompilerResource

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl ContextProvider for Context

source§

fn dir(&self) -> Dict<&VarName, &VarInfo>

source§

fn get_receiver_ctx(&self, receiver_name: &str) -> Option<&Context>

source§

fn get_var_info(&self, name: &str) -> Option<(&VarName, &VarInfo)>

source§

impl Debug for Context

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Context

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Context

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Context

§

impl !Send for Context

§

impl !Sync for Context

§

impl Unpin for Context

§

impl !UnwindSafe for Context

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.