Skip to content

Commit

Permalink
Run monomorph with a flag, suppress warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Sep 18, 2024
1 parent cf36900 commit 3a06c84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ mod native {
let mut no_prelude = false;
let mut no_backtrace = false;
let mut print_checked_ast = false;
let mut monomorphise = false;
let args: Vec<String> = std::env::args()
.filter(|arg| match arg.as_str() {
"--typecheck" => {
Expand All @@ -110,6 +111,10 @@ mod native {
print_checked_ast = true;
false
}
"--monomorphise" => {
monomorphise = true;
false
}
_ => true,
})
.collect();
Expand Down Expand Up @@ -151,7 +156,9 @@ mod native {

if !typecheck {
// For testing purposes.
let module = monomorph::monomorphise(&module, &tys);
if monomorphise {
module = monomorph::monomorphise(&module, &tys);
}

let input = args.get(2).map(|s| s.as_str()).unwrap_or("");
let mut w = std::io::stdout();
Expand Down
33 changes: 6 additions & 27 deletions src/monomorph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ use crate::type_checker::{Id, PgmTypes, Ty, TyArgs};

use smol_str::SmolStr;

/// A monomorphisation of a generic type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum MonoTy {
I8,
I32,
I64,
Ptr,
}

/*
Implementation plan:
Expand Down Expand Up @@ -96,18 +87,6 @@ struct PgmGraph {
ty: Map<Id, ast::TypeDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum ItemRef {
/// Item is a top-level function.
Top(Id),

/// Item is an associated function.
Associated(Id, Id),

/// Item is a type.
Ty(Id),
}

// TODO: This drops traits, we should copy missing methods with default implementations before
// converting to the graph.
fn pgm_to_graph(pgm: Vec<ast::TopDecl>, tys: &PgmTypes) -> PgmGraph {
Expand Down Expand Up @@ -960,7 +939,7 @@ fn ty_to_ast(ty: &Ty, ty_map: &Map<Id, ast::Type>) -> ast::Type {
})
}),

Ty::Var(var) => {
Ty::Var(_var) => {
// Ambiguous type, monomorphise as unit.
ast::Type::Record(vec![])
}
Expand Down Expand Up @@ -1000,14 +979,14 @@ fn ty_to_ast(ty: &Ty, ty_map: &Map<Id, ast::Type>) -> ast::Type {
})
}

Ty::Record(hash_map) => todo!(),
Ty::Record(_fields) => todo!(),

Ty::QVar(smol_str) => panic!(),
Ty::QVar(_var) => panic!(),

Ty::Fun(vec, ty) => todo!(),
Ty::Fun(_args, _ret) => todo!(),

Ty::FunNamedArgs(hash_map, ty) => todo!(),
Ty::FunNamedArgs(_args, _ret) => todo!(),

Ty::AssocTySelect { ty, assoc_ty } => todo!(),
Ty::AssocTySelect { ty: _, assoc_ty: _ } => todo!(),
}
}

0 comments on commit 3a06c84

Please sign in to comment.