marianoguerra/pure-py/context does not have a README file

    Context

    Contexts, entries and the three operators of Figure 2.2 and Definition 3.1.

    A port of the reference's contexts.py. The context is an IMMUTABLE sorted map: immutable because contexts are threaded functionally through every rule and nothing may see a later branch's bindings, sorted because two messages -- the submodule clash and the mutual-region duplicate -- name sorted(...)[0], and an accidental order would name a different variable.

    VarContext

    A delta of variables only: what a statement's result type carries.

    ClassEntry

    pub(all) struct ClassEntry {
    context :
    SortedMap
    [String, Entry]
    name : String
    own_fields : Array[String]
    base : String?
    } derive(Eq,
    Debug
    )

    A class, with the context it was DECLARED in.

    The declaring context is the load-bearing part: fields and ancestors resolve the base class through it and not through whatever context is current, so a class that is imported keeps the meaning it had where it was written.

    ClassEntry::ancestors

    fn ClassEntry::ancestors(self : ClassEntry) -> Array[ClassEntry]

    The class and every class it inherits from, nearest first.

    ClassEntry::field_map

    fn[T] ClassEntry::field_map(self : ClassEntry, positional : Array[T], kwd_names : Array[String], kwd_values : Array[T]) -> Array[(String, T)]?

    Match a constructor's or a pattern's arguments to the class's fields.

    None when the call is over- or under-saturated, when a keyword is repeated, or when the keywords are not exactly the fields the positional arguments did not cover.

    ClassEntry::fields

    fn ClassEntry::fields(self : ClassEntry) -> Array[String]

    Every field, INHERITED FIRST -- which is the order a constructor's positional arguments are in and the order an object prints in.

    ClassEntry::short_name

    fn ClassEntry::short_name(self : ClassEntry) -> String

    The last segment of a class's qualified name -- what a message prints.

    Entry

    pub(all) enum Entry {
    Var(Status)
    ModuleStub(String)
    ModuleLoaded(String,
    SortedMap
    [String, Entry])
    Class(ClassEntry)
    } derive(Eq,
    Debug
    )

    What a name can stand for.

    ModuleContext

    pub(all) struct ModuleContext[M] {
    gamma :
    SortedMap
    [String, Entry]
    program : M
    q : String
    } derive(Eq,
    Debug
    )

    A module being checked: the context, the program it belongs to, and its own qualified name.

    ModuleContext::class_of

    fn[M] ModuleContext::class_of(self : ModuleContext[M], c : String) -> ClassEntry?

    ModuleContext::module_of

    fn[M] ModuleContext::module_of(self : ModuleContext[M], x : String) -> Entry?

    The module a name stands for, loaded or not.

    ModuleContext::override_gamma

    ModuleContext::override_var

    ModuleContext::var_status

    fn[M] ModuleContext::var_status(self : ModuleContext[M], x : String) -> Status?

    ResultType

    pub(all) enum ResultType {
    Returns
    Assigns(
    SortedMap
    [String, Status])
    } derive(Eq,
    Debug
    )

    Figure 3.1's result: a sequence either returns or assigns a delta.

    Status

    pub(all) enum Status {
    TT
    FF
    } derive(Compare, Eq,
    Debug
    )

    Whether a variable is definitely assigned. The spec writes tt and ff.

    assigns_empty

    fn assigns_empty() -> ResultType

    class_entry

    fn[M] class_entry(e :
    Expr
    , ctx : ModuleContext[M]) -> ClassEntry?

    context_of

    fn context_of(entries : Array[(String, Entry)]) ->
    SortedMap
    [String, Entry]

    empty_context

    entry_of

    fn[M] entry_of(e :
    Expr
    , ctx : ModuleContext[M]) -> Entry?

    What a qualified name stands for: a name in the context, or a member of a loaded module reached through it.

    extend_entry

    fn extend_entry(a : Entry, b : Entry) -> Entry

    Extending prefers a loaded module over a stub of the same module, and merges two loadings of the same module member by member. Anything else is simply replaced.

    extra_builtin_names

    let extra_builtin_names : Array[String]

    The names Feature::ExtraBuiltins adds to builtins, in a fixed order.

    The evaluator has a value for every one of them, and lib/eval/predefined_wbtest.mbt insists on it -- the two tables cannot BE one, because lib/check does not import lib/value and a bridge between them would put a runtime type on the checker's side of the layering.

    Everything here is pure, and everything here is TOTAL or cleanly partial: where Python would answer by coercing -- sum([True]), any([1]), int(True) -- PurePy has no rule and the call is undefined rather than guessing. bool is absent for that reason and not by oversight: it is Python's truthiness in a function, and PurePy has no truthiness at all.

    merge_delta

    The merge of two branches' deltas: a name assigned on one side only is present but not definitely assigned.

    merge_results

    fn merge_results(rs : Array[ResultType]) -> ResultType

    The merge of a match's or an if's branches. A branch that returns contributes nothing; if every branch returns, so does the whole.

    merge_status

    fn merge_status(a : Status, b : Status) -> Status

    tt only when both sides say so.

    override_results

    fn override_results(r1 : ResultType, r2 : ResultType) -> ResultType

    Sequencing: once anything returns, the sequence returns.

    own_fields

    fn own_fields(node :
    Stmt
    ) -> Array[String]

    The fields a class declares, from its declaration.

    predefined_context

    Every predefined module's members are definitely assigned, and so is __name__, which every module has.

    predefined_members

    fn predefined_members(q : String, profile? :
    Profile
    ) -> Array[String]?

    Figure 2.7's modules, and what each exports.

    typing exposes only Any here. Figure 2.7 of the spec also lists Callable; the reference does not, and the reference is the oracle. The divergence is recorded rather than reconciled, to be revisited when upstream settles it.

    predefined_modules

    let predefined_modules : Array[String]

    vars_of

    fn vars_of(entries : Array[(String, Status)]) ->
    SortedMap
    [String, Status]

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io