Struct erg_compiler::hir::HIR
source · Expand description
High-level Intermediate Representation AST with type information added
Fields§
§name: Str
§module: Module
Implementations§
source§impl HIR
impl HIR
sourcepub const fn new(name: Str, module: Module) -> Self
pub const fn new(name: Str, module: Module) -> Self
Examples found in repository?
declare.rs (line 299)
287 288 289 290 291 292 293 294 295 296 297 298 299 300
pub(crate) fn declare_module(&mut self, ast: AST) -> HIR {
let mut module = hir::Module::with_capacity(ast.module.len());
for chunk in ast.module.into_iter() {
match self.declare_chunk(chunk) {
Ok(chunk) => {
module.push(chunk);
}
Err(errs) => {
self.errs.extend(errs);
}
}
}
HIR::new(ast.name, module)
}
More examples
lower.rs (line 1936)
1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
pub fn lower(&mut self, ast: AST, mode: &str) -> Result<CompleteArtifact, IncompleteArtifact> {
log!(info "the AST lowering process has started.");
log!(info "the type-checking process has started.");
let ast = Reorderer::new(self.cfg.clone())
.reorder(ast)
.map_err(|errs| {
IncompleteArtifact::new(None, errs, LowerWarnings::from(self.warns.take_all()))
})?;
if mode == "declare" {
let hir = self.declare_module(ast);
if self.errs.is_empty() {
log!(info "HIR:\n{hir}");
log!(info "the declaring process has completed.");
return Ok(CompleteArtifact::new(
hir,
LowerWarnings::from(self.warns.take_all()),
));
} else {
log!(err "the declaring process has failed.");
return Err(self.return_incomplete_artifact(hir));
}
}
let mut module = hir::Module::with_capacity(ast.module.len());
if let Err(errs) = self.ctx.preregister(ast.module.block()) {
self.errs.extend(errs);
}
for chunk in ast.module.into_iter() {
match self.lower_expr(chunk) {
Ok(chunk) => {
module.push(chunk);
}
Err(errs) => {
self.errs.extend(errs);
}
}
}
self.ctx.clear_invalid_vars();
self.ctx.check_decls().unwrap_or_else(|mut errs| {
self.errs.append(&mut errs);
});
let hir = HIR::new(ast.name, module);
log!(info "HIR (not resolved, current errs: {}):\n{hir}", self.errs.len());
let hir = match self.ctx.resolve(hir) {
Ok(hir) => {
log!(info "HIR (resolved):\n{hir}");
hir
}
Err((hir, errs)) => {
self.errs.extend(errs);
log!(err "the resolving process has failed. errs: {}", self.errs.len());
return Err(self.return_incomplete_artifact(hir));
}
};
// TODO: recursive check
for chunk in hir.module.iter() {
if let Err(warns) = self.use_check(chunk, mode) {
self.warns.extend(warns);
}
}
if self.errs.is_empty() {
log!(info "the AST lowering process has completed.");
Ok(CompleteArtifact::new(
hir,
LowerWarnings::from(self.warns.take_all()),
))
} else {
log!(err "the AST lowering process has failed. errs: {}", self.errs.len());
Err(self.return_incomplete_artifact(hir))
}
}