WIP reorganization

This commit is contained in:
imaqtkatt 2023-10-12 11:59:57 -03:00
parent 0ac2f2bf2c
commit e153fa3e1c
25 changed files with 56 additions and 40 deletions

View File

@ -1,4 +1,5 @@
use super::{hvm_lang::DefNames, DefId};
use super::DefId;
use crate::term::DefNames;
use hvmc::{show_lnet, val_to_name, LNet};
use itertools::Itertools;
use std::collections::HashMap;

View File

@ -1,8 +1,6 @@
pub mod compat;
pub mod core;
pub mod hvm_lang;
pub use hvm_lang::{Definition, DefinitionBook, Rule, Term};
pub use crate::term::{Definition, DefinitionBook, Rule, Term};
use derive_more::{Display, From, Into};
use hvmc::Val;

View File

@ -1,15 +1,15 @@
use crate::ast::{
compat::{
use crate::{
ast::{var_id_to_name, DefId, Name, Term},
net::inter_net::{
addr, enter, kind, link, new_inet, new_node, port, slot, INet, INode, INodes, NodeId, NodeKind, Port,
SlotId, CON, DUP, ERA, ITE, LABEL_MASK, REF, ROOT, TAG_MASK,
},
hvm_lang::Op,
var_id_to_name, DefId, DefinitionBook, Name, Term,
term::{DefinitionBook, Op},
};
use hvmc::{LNet, LTree, Val};
use std::collections::{HashMap, HashSet};
use crate::ast::compat::{label_to_op, NUM, OP2};
use crate::net::inter_net::{label_to_op, NUM, OP2};
pub fn readback_net(net: &LNet, book: &DefinitionBook) -> anyhow::Result<(Term, bool)> {
/* check_lnet_valid(net)?; */

View File

@ -3,19 +3,20 @@
pub mod ast;
pub mod from_core;
pub mod loader;
pub mod parser;
pub mod net;
pub mod semantic;
pub mod term;
pub mod to_core;
use ast::{core::Book, hvm_lang::DefNames, DefinitionBook, Term};
use ast::{core::Book, DefinitionBook, Term};
use from_core::readback_net;
use hvmc::{readback_lnet, LNet};
use semantic::check_main;
use std::time::Instant;
use term::DefNames;
use to_core::{book_to_hvm_core, book_to_hvm_internal};
pub use loader::load_file_to_book;
pub use crate::term::load_book::load_file_to_book;
pub fn check_book(mut book: DefinitionBook) -> anyhow::Result<()> {
// TODO: Do the checks without having to do full compilation

View File

@ -1,6 +1,6 @@
// TODO: Refactor to not use this intermediate form
use super::hvm_lang::Op;
use crate::term::Op;
use hvmc::Val;
#[derive(Clone, Debug)]

1
src/net/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod inter_net;

View File

@ -1,11 +1,9 @@
/// Semantic checking
use crate::ast::{DefinitionBook, Name};
pub mod combinators;
/// Semantic passes for pattern matching on defiinition rules.
/// Extract ADTs from patterns in a book, then convert them into lambda calculus.
pub mod pattern;
pub mod supercombinators;
pub mod vars;
pub fn check_main(book: &DefinitionBook) -> anyhow::Result<()> {

View File

@ -1,6 +1,6 @@
use crate::ast::{
hvm_lang::{DefNames, Pattern},
DefId, Definition, DefinitionBook, Name, Rule, Term,
use crate::{
ast::{DefId, Definition, DefinitionBook, Name, Rule, Term},
term::{DefNames, Pattern},
};
use hvmc::Val;
use std::collections::HashSet;

View File

@ -1,5 +1,8 @@
use super::{Adt, AdtId, Type};
use crate::ast::{hvm_lang::Pattern, DefId, Definition, DefinitionBook, Name};
use crate::{
ast::{DefId, Definition, DefinitionBook, Name},
term::Pattern,
};
use anyhow::anyhow;
use itertools::Itertools;
use std::collections::HashMap;

View File

@ -1,4 +1,7 @@
use crate::ast::{hvm_lang::DefNames, var_id_to_name, DefinitionBook, Name, Term};
use crate::{
ast::{var_id_to_name, DefinitionBook, Name, Term},
term::DefNames,
};
use hvmc::Val;
use std::collections::HashMap;

View File

@ -1,4 +1,5 @@
use crate::{ast::DefinitionBook, parser::parse_definition_book};
use super::parser::parse_definition_book;
use crate::ast::DefinitionBook;
use ariadne::{Color, Label, Report, ReportKind, Source};
use chumsky::prelude::Rich;
use itertools::Itertools;

View File

@ -1,4 +1,8 @@
use super::{DefId, Name};
pub mod load_book;
pub mod parser;
pub mod transform;
use crate::ast::{DefId, Name};
use bimap::{BiHashMap, Overwritten};
use itertools::Itertools;
use std::fmt;

View File

View File

@ -1,4 +1,4 @@
mod lexer;
mod parser;
pub mod lexer;
pub mod parser;
pub use parser::{parse_definition_book, parse_term};

View File

@ -1,7 +1,7 @@
use super::lexer::LexingError;
use super::lexer::{LexingError, Token};
use crate::{
ast::{hvm_lang::Pattern, DefId, Definition, DefinitionBook, Name, Rule, Term},
parser::lexer::Token,
ast::{DefId, Definition, DefinitionBook, Name, Rule, Term},
term::{Op, Pattern},
};
use chumsky::{
extra,
@ -17,7 +17,7 @@ use itertools::Itertools;
use logos::{Logos, SpannedIter};
use std::{iter::Map, ops::Range};
use crate::ast::hvm_lang::Op;
// use crate::ast::hvm_lang::Op;
// TODO: Pattern matching on rules
// TODO: Other types of numbers

View File

View File

View File

@ -1,6 +1,6 @@
use crate::ast::{
hvm_lang::{DefNames, Op},
Definition, DefinitionBook, Name, Rule, Term,
use crate::{
ast::{Definition, DefinitionBook, Name, Rule, Term},
term::{DefNames, Op},
};
impl DefinitionBook {

View File

@ -1,4 +1,7 @@
use crate::ast::{hvm_lang::DefNames, DefId, Definition, DefinitionBook, Name, Rule, Term};
use crate::{
ast::{DefId, Definition, DefinitionBook, Name, Rule, Term},
term::DefNames,
};
use std::collections::HashSet;
/// Replaces closed Terms (i.e. without free variables) with a Ref to the extracted term

View File

@ -0,0 +1,2 @@
pub mod detach_combinators;
pub mod detach_supercombinators;

View File

View File

@ -1,14 +1,14 @@
use crate::ast::{
compat::{
use crate::{
ast::{var_id_to_name, DefId, Name, Term},
net::inter_net::{
addr, enter, kind, link, new_inet, new_node, port, slot, INet, NodeId, Port, CON, DUP, ERA, ITE,
LABEL_MASK, REF, ROOT, TAG_MASK,
},
var_id_to_name, DefId, Name, Term,
};
use hvmc::{LNet, LTree, Tag};
use std::collections::{HashMap, HashSet};
use crate::ast::compat::{op_to_label, NodeKind, NUM, OP2};
use crate::net::inter_net::{op_to_label, NodeKind, NUM, OP2};
/// Converts an IC term into an IC net.
pub fn term_to_compat_net(term: &Term) -> anyhow::Result<INet> {

View File

@ -27,7 +27,6 @@ pub fn term_to_hvm_core(term: &Term) -> anyhow::Result<LNet> {
}
pub fn book_to_hvm_internal(book: &Book, mem_size: usize) -> anyhow::Result<(hvmc::Net, hvmc::Book)> {
// TODO: Don't try to preallocate a huge buffer
let mut root = hvmc::Net::new(mem_size);
root.boot(book.main.to_internal()); // TODO: Don't use this workaround

View File

@ -2,9 +2,11 @@ use hvm_lang::{
ast::{DefId, DefinitionBook},
compile_book,
from_core::readback_net,
loader::{display_err_for_text, display_miette_err},
parser::{parse_definition_book, parse_term},
run_book,
term::{
load_book::{display_err_for_text, display_miette_err},
parser::{parse_definition_book, parse_term},
},
to_core::term_to_hvm_core,
};
use hvmc::{parse_lnet, show_lnet, Val};