Struct erg_compiler::context::Context
source · 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
impl Context
pub fn new_module<S: Into<Str>>( name: S, cfg: ErgConfig, shared: SharedCompilerResource ) -> Self
source§impl Context
impl Context
sourcepub fn sort_types<'a>(
&self,
types: impl Iterator<Item = &'a Type>
) -> Vec<&'a Type>
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]
pub fn get_nominal_super_type_ctxs<'a>( &'a self, t: &Type ) -> Option<Vec<&'a Context>>
source§impl Context
impl Context
pub fn del(&mut self, ident: &Identifier) -> CompileResult<()>
pub fn inc_ref<L: Locational>(&self, vi: &VarInfo, name: &L)
source§impl Context
impl Context
pub fn test_refinement_subtyping(&self) -> Result<(), ()>
pub fn test_resolve_trait_inner1(&self) -> Result<(), ()>
pub fn test_instantiation_and_generalization(&self) -> Result<(), ()>
source§impl Context
impl Context
pub fn new( name: Str, cfg: ErgConfig, kind: ContextKind, params: Vec<ParamSpec>, outer: Option<Context>, shared: Option<SharedCompilerResource>, level: usize ) -> Self
pub fn default_with_name(name: &'static str) -> Self
pub fn with_capacity( name: Str, cfg: ErgConfig, kind: ContextKind, params: Vec<ParamSpec>, outer: Option<Context>, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn mono( name: Str, cfg: ErgConfig, kind: ContextKind, outer: Option<Context>, shared: Option<SharedCompilerResource>, level: usize ) -> Self
pub fn poly( name: Str, cfg: ErgConfig, kind: ContextKind, params: Vec<ParamSpec>, outer: Option<Context>, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn poly_trait<S: Into<Str>>( name: S, params: Vec<ParamSpec>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn builtin_poly_trait<S: Into<Str>>( name: S, params: Vec<ParamSpec>, capacity: usize ) -> Self
pub fn poly_class<S: Into<Str>>( name: S, params: Vec<ParamSpec>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn builtin_poly_class<S: Into<Str>>( name: S, params: Vec<ParamSpec>, capacity: usize ) -> Self
pub fn poly_patch<S: Into<Str>>( name: S, base: Type, params: Vec<ParamSpec>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn mono_trait<S: Into<Str>>( name: S, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn builtin_mono_trait<S: Into<Str>>(name: S, capacity: usize) -> Self
pub fn mono_class<S: Into<Str>>( name: S, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn builtin_mono_class<S: Into<Str>>(name: S, capacity: usize) -> Self
pub fn mono_patch<S: Into<Str>>( name: S, base: Type, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn methods( impl_trait: Option<Type>, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize, level: usize ) -> Self
pub fn builtin_methods(impl_trait: Option<Type>, capacity: usize) -> Self
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
pub fn builtin_poly_glue_patch<S: Into<Str>>( name: S, base: Type, impls: Type, params: Vec<ParamSpec>, capacity: usize ) -> Self
pub fn module( name: Str, cfg: ErgConfig, shared: Option<SharedCompilerResource>, capacity: usize ) -> Self
pub fn builtin_module<S: Into<Str>>( name: S, cfg: ErgConfig, capacity: usize ) -> Self
pub fn instant( name: Str, cfg: ErgConfig, capacity: usize, shared: Option<SharedCompilerResource>, outer: Context ) -> Self
pub fn caused_by(&self) -> String
sourcepub fn initialize(&mut self)
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.