跳转到内容
查看源码

entelechy-compiler自动生成

层:前端层 · 代码行数:6,599 · 集成测试文件:4

把 .ent 源码编译为经过校验的 Entelechy IR。

Compiles .ent sources into validated Entelechy IR

Compiler: .ent source → AST → semantic analysis → validated Entelechy IR.

Every diagnostic carries a source position. The compiler executes nothing.

内部依赖 entelechy-ir, entelechy-language
外部依赖 —
源码 crates/frontend/compiler
名称 简述
help What help lists: every builtin with its signatures, sentence and capability, and every language and document form. Math intrinsics come from the IR’s table and typing rules; the other builtins are the ones the lowering dispatches.
名称 简述
help::Builtin One builtin as help shows it.
help::Form One form of the language, as help shows it.
SourcePlaces Where the values of an unoptimized module are written: its entry, its merge or init, and each function by its index. Kept beside the IR, never in it, so where a Kernel is written changes nothing it computes.
名称 简述
CompileError Why compilation failed.
函数 简述
fn builtins() -> Vec<Builtin> Every builtin, the math ones first in the IR’s order, then the Field, memory, context and construction builtins.
fn forms() -> Vec<Form> Every form, grouped by where it is written.
fn form_named(name: &str) -> Option<Form> The form named name, if any.
fn builtin(name: &str) -> Option<Builtin> The builtin named name, if any.
fn similar(name: &str) -> Vec<&'static str> Builtins and forms whose names are close to name, for a miss.
fn compile(source: &str) -> Result<Validated, CompileError> Compiles one Kernel source into validated IR.
fn compile_kernel(kernel: &Kernel, id: Option<&KernelId>) -> Result<Validated, CompileError> Compiles a parsed Kernel. id names an anonymous inline Kernel; a Kernel that declares its own id keeps it.
fn check_functions(document: &Document, inherited: (&[StructDecl], &[TypeAlias], &[FnDecl])) -> Result<(), CompileError> Checks the functions a document declares, each lowered once whether a Kernel calls it or not, against what the document declares and inherited, the structs, types and functions of the documents it uses. A Kernel lowers only the functions it calls; this is where the others are held to the language, a template with its Field parameters bound to ports of their declared types. A function’s capabilities are its callers’ to hold, so none is refused here.
fn check_functions_each(document: &Document, inherited: (&[StructDecl], &[TypeAlias], &[FnDecl])) -> Vec<CompileError> check_functions, saying every fault its functions hold, each once: what a check lists, so one run shows all a document must mend.
fn compile_kernel_unoptimized(kernel: &Kernel, id: Option<&KernelId>) -> Result<(Validated, SourcePlaces), CompileError> compile_kernel without optimization: the IR a trace walks, with its calls and the source’s own lets, and where each value is written.
fn compile_unoptimized(source: &str) -> Result<Validated, CompileError> compile without optimization: the reference the optimizer is held to.
fn literal(expr: &Expr) -> Result<Value, CompileError> Evaluates a literal as a plain value: numbers, booleans, negation, and vec2/vec3/vec4 of floats. Parameter defaults and graph documents share this grammar.
fn literal_of_type(expr: &Expr, ty: &Spanned<String>, structs: &[StructDecl]) -> Result<Value, CompileError> A literal read exact and shaped into the type ty names (Double, [DVec2; 4], a struct), over a document’s struct declarations.
fn literal_exact(expr: &Expr, fields_of: &dyn Fn(&str) -> Option<Vec<String>>) -> Result<Value, CompileError> literal_in for a place that knows its type: written floats stay exact until the type sets their width.
fn literal_in(expr: &Expr, fields_of: &dyn Fn(&str) -> Option<Vec<String>>) -> Result<Value, CompileError> Evaluates an untyped literal of any Kernel value: a struct’s fields in the order fields_of gives, an array or struct as a record. entelechy_ir::value_as shapes it into a type.
fn with_variants(expr: &Expr, variants_of: &dyn Fn(&str) -> Option<Variants>) -> Result<Expr, CompileError> expr with each enum variant it names (Mode.Walk) written as its Int, for a literal outside a Kernel (a scene’s); variants_of gives an enum’s variants, each with its number, by the enum’s name.
名称 类型 简述
Places HashMap<ValueId, Span> Where each value of a Kernel’s function is written in its document.
Variants Vec<(String, i32)> An enum’s variants in order, each with the Int it is.

Validated

crates/frontend/compiler/src/help.rs#L10

One builtin as help shows it.

属性

名称 类型 说明
name &'static str The name a Kernel calls.
kind &'static str What kind of builtin: “math”, “field”, “memory”, “scatter”, “group”, “context”, “construction”.
signatures Vec<String> Every accepted signature, name(arg: Type, ...) -> Type; a generic element type is written T.
doc &'static str One sentence.
requires Option<Capability> The capability a Kernel must declare to call it, if any.
entry_only bool Whether only the entry (compute, scan, scatter, group) may call it.

实现的 Trait: Clone, Debug, Eq, PartialEq, StructuralPartialEq


crates/frontend/compiler/src/help.rs#L201

One form of the language, as help shows it.

属性

名称 类型 说明
name &'static str The word to ask for: loop, each, scatter, node.
kind &'static str Where it is written: “type”, “expression”, “kernel”, “graph” or “document”.
shape &'static str The shape, as one writes it.
doc &'static str One sentence.

实现的 Trait: Clone, Debug, Eq, PartialEq, StructuralPartialEq


crates/frontend/compiler/src/lib.rs#L231

Where the values of an unoptimized module are written: its entry, its merge or init, and each function by its index. Kept beside the IR, never in it, so where a Kernel is written changes nothing it computes.

属性

名称 类型 说明
entry Places The entry’s values.
others Vec<Places> A reduction’s merge or a scan’s init.
functions Vec<Places> Each function’s values, by its index in the module.

实现的 Trait: Clone, Debug, Default


crates/frontend/compiler/src/lib.rs#L17

Why compilation failed.

变体

名称 说明
Parse(ParseError) The source does not parse.
Semantic { span: Span, message: String, declaration: Option<String> } The source parses but is not meaningful.
Validation(ValidationError) The produced IR failed validation: a compiler bug.

方法

函数 说明
fn span(&self) -> Option<Span> Source position, when the error has one.
fn declaration(&self) -> Option<&str> The declaration the error is in, when one holds it: a function, a struct or a type, by the name the Kernel knows it by.

实现的 Trait: Clone, Debug, Display, Eq, Error, From, PartialEq, StructuralPartialEq